Using `types` classes over `collections.abc`'s bases
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 302
- Avg merge
- 23h
- Merged PRs (30d)
- 8
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.pyiProtocols that should be based on their runtime implementation (they implement custom__subclasshook__) and not the concrete types. (https://github.com/python/typeshed/pull/10816) - make the
typesclasses subscriptable at runtime. (https://github.com/python/cpython/pull/110212) - make type checkers infer things like
def foo(): yieldastypes.GeneratorTypeand not justcollections.abc.Generator.
(as a small aside it might be nice to move the type implementations from typing to collections.abc soon)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the collections.abc.pyi classes and the linked typeshed and CPython pull requests. Then examine how type checkers infer generator, coroutine, and async-generator functions. Done means the abstract and concrete types have the proposed runtime and inference behavior across the identified changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100