Open
Description
Currently collections.abc.Generator/Coroutine/AsyncGenerator etc. have attributes that don't have to exist at runtime. I think it'd be wise to switch recommending to using the types concrete classes where possible over the abstract versions which have a smaller interface because having this weird sort of duplication where the 2 are basically the same is a wrinkle that's bitten me recently. To do this I think a few things need to happen:
- make the classes in
collections.abc.pyi
Protocol
s that should be based on their runtime implementation (they implement custom__subclasshook__
) and not the concrete types. (Make collections.abcs more consistent with runtime implementation typeshed#10816) - make the
types
classes subscriptable at runtime. (gh-110209: Add __class_getitem__ for generator and coroutine cpython#110212) - make type checkers infer things like
def foo(): yield
astypes.GeneratorType
and not justcollections.abc.Generator
.
(as a small aside it might be nice to move the type implementations from typing to collections.abc soon)
refs: microsoft/pyright#6053