Way to support attributes for TypedDict
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Currently i am working with a typeddict that is transforming to AttributeDict and i dont have a way to preserve typings. I am implementing a custom plugin for this but the type is only available for get_type_analyze_hook.
To Reproduce
from typing import TypedDict
Test = TypedDict(
"Test",
{
"from": str,
"test": str
}
)
my_test: Test = {
"from": "lorem",
"test": "11"
}
my_test.test = "22"
Expected Behavior
There wont be any errors.
Actual Behavior
test.py:17: error: "Test" has no attribute "test" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.0.1
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.10.9
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 running the provided TypedDict example with mypy 1.0.1 and reading the get_type_analyze_hook path used by a custom plugin. Done means defining how TypedDict keys transformed into attributes should preserve their types and making the example pass without the attr-defined error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100