Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints / annotations to array_namespace(): array_api_strict as return type? #194

Open
34j opened this issue Nov 2, 2024 · 1 comment

Comments

@34j
Copy link

34j commented Nov 2, 2024

Without type hints, it is very inconvenient because of spelling errors of array_api functions. As array_api_compat seems to be a superset of array_api_strict, I would like to propose to simply set the return type of array_namespace() to array_api_strict, although it might be confusing.

def array_namespace(*xs, api_version=None, use_compat=None):

from typing import overload
import array_api_strict

array_api_compat_type = array_api_strict

@overload
def array_namespace(*xs, api_version=None, use_compat: None=None) -> array_api_compat_type:
	...
@asmeurer
Copy link
Member

asmeurer commented Nov 6, 2024

I think upstream work to make a protocol out of the array API namespace would be what we'd want here.

data-apis/array-api#685
data-apis/array-api#267

Setting the return type as array_api_strict seems wrong. array_api_strict isn't a type, it's a module, and it isn't even the module that's returned in most cases. The correct return type would be typing.ModuleType, which we can definitely add, although I don't think that alone would make it infer much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants