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

Literal types support in numpy.typing #16676

Open
zhihaoy opened this issue Jun 24, 2020 · 3 comments
Open

Literal types support in numpy.typing #16676

zhihaoy opened this issue Jun 24, 2020 · 3 comments

Comments

@zhihaoy
Copy link

zhihaoy commented Jun 24, 2020

Many NumPy APIs currently have return type Any. view, item, finfo... But almost always, their type arguments are literals ('d', np.float64, for example). We should implement basic dependent types with Python 3.8 literal types in the typing module.

See also: https://www.python.org/dev/peps/pep-0586/

@person142
Copy link
Member

Not sure what you mean here-ndarray.view does not have an Any return type in the types currently. For ndarray.item, it can return anything, i.e.

>>> class A: pass
...
>>> np.array([A()]).item()
<__main__.A object at 0x105ee6ed0>

The fix there is to make ndarray generic over the dtype, which is currently in progress. For finfo, nobody has added types yet; we have #16546 to track that.

@zhihaoy
Copy link
Author

zhihaoy commented Jun 25, 2020

Not sure what you mean here-ndarray.view does not have an Any return type in the types currently.

I mean a.view('i8').

Yes, item() is different. I mean all APIs that can accept type or dtype as function parameters.

@BvB93
Copy link
Member

BvB93 commented Jun 25, 2020

I mean a.view('i8').

Right, so what you're talking about here boils down to DTypeLike being (in practice) unable to accept arbitrary strings.

While aforementioned annotation should eventually be refined with Literals,
there is already substantially sized todo-list (see the previously linked issue) with, as of yet, untyped functions.

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

3 participants