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

array.array should support __class_getitem__ #98658

Closed
JelleZijlstra opened this issue Oct 25, 2022 · 3 comments
Closed

array.array should support __class_getitem__ #98658

JelleZijlstra opened this issue Oct 25, 2022 · 3 comments
Labels
topic-typing type-feature A feature request or enhancement

Comments

@JelleZijlstra
Copy link
Member

The array.array class has been marked as generic in typeshed since 2017 (python/typeshed#1649). We just got a report on mypy (python/mypy#13942) pointing out that the class is not subscriptable at runtime. Just like other generic standard library classes, we should make array.array subscriptable at runtime (PEP-585).

I'll make a PR.

@serhiy-storchaka
Copy link
Member

Isn't it a bug in typeshed? This class does not look generic.

@JelleZijlstra
Copy link
Member Author

It's marked as generic because the "element" type depends on the type code:

In [50]: a1=array.array('b', [1])

In [51]: a1[0]
Out[51]: 1

In [52]: a2 = array.array('f', [1])

In [53]: a2[0]
Out[53]: 1.0

So we'd want a1 to be typed as an array[int] and a2 as an array[float].

@serhiy-storchaka
Copy link
Member

It makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants