Closed as not planned
Description
Bug report
Bug description:
This should be reproducible for all Python versions that support dataclass. A relevant bug is reported to typeshed: python/typeshed#11793
Static type checkers seems not smart enough to infer the type correctly in the below case:
from collections import OrderedDict
from typing import reveal_type
od: OrderedDict[int, int] = OrderedDict()
class object:
d: dict[int, int]
o = object()
o.d = od
reveal_type(o.d)
# `OrderedDict` for runtime
# `collections.OrderedDict[builtins.int, builtins.int]` for mypy
# `OrderedDict[int, int]` for pytype
from collections import OrderedDict
import dataclasses
from typing import reveal_type
@dataclasses.dataclass
class dataclassObject(object):
d: dict[int, int]
o = dataclassObject(d=od)
reveal_type(o.d)
# `OrderedDict` for runtime
# `builtins.dict[builtins.int, builtins.int]` for mypy
# `Dict[int, int]` for pytype
CPython versions tested on:
3.9, 3.11
Operating systems tested on:
macOS