Skip to content

TypedDict as default_factory in dataclasses is not inferred correctly #5723

Closed
@iddan

Description

@iddan
  • Are you reporting a bug, or opening a feature request? bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
from dataclasses import dataclass, field
from mypy_extensions import TypedDict

class Person(TypedDict, total=False):
    name: str

@dataclass
class Job:
    person: Person = field(default_factory=Person)
  • What is the actual behavior/output?
main.py:9: error: Incompatible types in assignment (expression has type "main.Person", variable has type "Person")
  • What is the behavior/output you expect? To pass
  • What are the versions of mypy and Python you are using? latest
    Do you see the same issue after installing mypy from Git master? yes
  • What are the mypy flags you are using? (For example --strict-optional) none

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions