Skip to content

Mypy inappropriately infers class type as _typeshed.DataclassInstance #14941

Description

@binishkaspar

Bug Report
In the following code snippet, mypy incorrectly infers the type of typ as _typeshed.DataclassInstance. This issue was not present in previous versions of mypy

To Reproduce

fromdataclassesimportdataclass, is_dataclassfromtypingimportTypeVar, Any, Type, cast@dataclassclassA:
a: intT=TypeVar('T')
defparse(typ: Type[T], raw: dict[str, Any]) ->T:
ifnotis_dataclass(typ):
raiseException('Unsupported type')
parsed=typ(**raw) # type: ignore[call-arg]returnparsedparse(A, {'a': 2})

Expected Behavior

There should be no type error

Actual Behavior

Incompatible return value type (got "DataclassInstance", expected "T") \[return-value\]

Your Environment

  • Mypy version used: 1.1.1
  • Python version used: 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions