pyright
pyright copied to clipboard
Generic `dict` subclass constructed with keyword arguments has an `Unknown` key type
Constructing a generic dict subclass with keyword arguments leaves the key type Unknown, although the same call on dict infers str:
class D[K, V](dict[K, V]): ...
reveal_type(dict(key=1))
reveal_type(D(key=1))
:3:13 - information: Type of "dict(key=1)" is "dict[str, int]"
:4:13 - information: Type of "D(key=1)" is "D[Unknown, int]"
D inherits dict.__init__, so I'd expect D[str, int], which is what mypy, ty and pyrefly infer. The str comes from the overload's self: dict[str, _VT] annotation, and pyright applies a self annotation's type arguments only when the class being constructed is the one that declares __init__.
Command-line pyright 1.1.414.