Skip to content

Incorrect precision calculation for TypedDict classes. #12512

Open
@baubie

Description

@baubie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions