Consider adding a plugin for `.__dict__`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Feature
In runtime we know that __dict__ on any object contains the same fields as instance itself.
So, we can predict what is going to be inside this __dict__:
>>> class A:
... def __init__(self, x: int, y: str) -> None:
... self.x = x
... self.y = y
...
>>> A(1, 'a').__dict__
{'x': 1, 'y': 'a'}
Pitch
I think it might be very useful to infer A(1, 'a').__dict__ as TypedDict({'x': int, 'y': str}).
However:
- Performance might be an issue
- There are cases where this is not possible due to typing and runtime resons (
__getattr__,fallback_to_any, etc)
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 examining how mypy plugins and TypedDict inference are currently handled, then assess whether an object's dict can be inferred from its instance fields. Account for the stated performance concerns and exceptions such as getattr and fallback_to_any; done would require a defined design and supporting behavior for the feasible cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100