"class property" should be Generic[T]
Open
Nobody has claimed this yet.
stubs: improvement
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
Currently property.__get__ returns Any, which loose information:
This would be more correct for property.__get__ to be generic and return T. Similar to cached_property:
class A:
@cached_property
def f(self) -> int: # f is `cached_property[int]`, f.__get__() -> int
...
@property
def g(self) -> int: # f is `property[Any]`, g.__get__() -> Any
...
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 with stdlib/3/builtins.pyi at the property definition referenced in the issue, then compare its get typing with stdlib/3/functools.pyi and cached_property. Confirm how the generic type is inferred from a property's getter annotation. Done means property.get preserves and returns that type instead of Any, with the existing stub behavior otherwise unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100