Cache types.GenericAlias in getitems
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
The "old-style" generic classes from the typing module (List, Dict, etc) cached typing._GenericAlias instances retuned from __getitem__:
>>> from typing import List
>>> List[int] is List[int]
True
But when this functionality was ported to built-in types, caching was not implemented:
>>> list[int] is list[int]
False
Since it is very common to subscript the same types with the same arguments, caching will be very beneficial here and will reduce memory footprint of heavily type-annotated modules.
Linked PRs
- gh-103541
Contributor guide
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 typing module's existing caching behavior for getitem and the linked PR gh-103541. Confirm the desired result with the list[int] is list[int] example; done means equivalent built-in generic aliases are cached without changing the stated typing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100