Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect precision calculation for TypedDict classes. #12512

Open
baubie opened this issue Apr 2, 2022 · 0 comments
Open

Incorrect precision calculation for TypedDict classes. #12512

baubie opened this issue Apr 2, 2022 · 0 comments
Labels
bug mypy got something wrong topic-typed-dict

Comments

@baubie
Copy link

baubie commented Apr 2, 2022

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
@baubie baubie added the bug mypy got something wrong label Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-typed-dict
Projects
None yet
Development

No branches or pull requests

2 participants