-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Allow iter[T]
as builtin generic for typing.Iterator[T]
(PEP 585)
#102465
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
Comments
I think that As far as I know, we don't have any generic functions at the moment. |
Agree with Nikita. Someone previously suggested |
I'm also not a fan of this idea. |
Interesting discussion. I came across this from #86268 while relearning type hints post typing module deprecation,. One difference I could appreciate is that unlike dict/list, collection.abc.Iterator is not a concrete class, and thus should not be instantiated; hence iter() cannot be a construtor for the class (and thus currently it is not); it is something that always returns a subclass of Iterator. The confusion I can construct is when we try to annotate the iter function itself after this proposal:
becomes
This does look strange,(and the lack of facility for getElementType(T) makes it worse) but the two use of [] are different: the first Is this a severe enough confusion, or are there more severe confusions beyond this one? |
I have some discussion of this idea at https://jellezijlstra.github.io/why-cant-we#builtin-functions-as-type-expressions |
Feature or enhancement
PEP 585 allows us to use
set
,list
,dict
,tuple
, etc. instead of thetyping.Dict
, ... analogues.Pitch
Amend PEP 585 to allow
iter[T]
to act as a builtin substitute fortyping.Iterator[T]
.The text was updated successfully, but these errors were encountered: