Incorrect precision calculation for TypedDict classes.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When defining a TypedDict class as in the example below, the lines defining the members of the dict are considered to be imprecise by the reports.
To Reproduce
# Code with imprecise lines
from typing import TypedDict
class UserDict(TypedDict):
user_id: int # Marked imprecise
email: str # Marked imprecise
user:UserDict = { 'user_id': 1, 'email': 'you@somewhere.com' }
The functionally equivalent alternative way shows all lines as precise:
# All lines are marked precise
from typing import TypedDict
UserDict = TypedDict('UserDict', {'user_id': int, 'email': str})
user:UserDict = { 'user_id': 1, 'email': 'you@somewhere.com' }
Expected Behavior
The member definitions in a TypedDict class should be marked precise.
Actual Behavior
Only 5 / 7 lines of code are considered precise with the user_id: int and email: str lines being marked imprecise. In the HTML report those lines have the title Any Types on this line: Error (x1).
Your Environment
- Python 3.10.3
- mypy 0.942
- Clean venv, run with `mypy --html-report report --txt-report . .``
- Ubuntu 20.04.4
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 reported mypy command on the TypedDict reproduction and compare the HTML and text reports for class syntax versus the functional form. Done means the user_id and email member lines are marked precise rather than reporting Any types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100