You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a pending PR for typeshed which fixes overparameterized dict.get and dict.pop methods: python/typeshed#10294. The PR causes a lot of failures in various GitHub projects due to how mypy treats empty collections. Specifically, if dict.get is annotated as
class dict(Generic[KT, VT]):
def get(self, key: KT, default: T) -> T | VT: ...
mypy infers the type of v in
def test(d: dict[str, Any]):
v = d.get("foo", {})
to be Any | dict[<unknown>, <unknown>], instead of Any | dict[Any, Any].
Feature
Specialize empty collections to Any if no other information is available to recover type arguments.
Pitch
Using <unknown> instead of Any requires users to cast or add type annotations where they otherwise will not be necessary. See comments in the PR for a few examples from real projects.
The text was updated successfully, but these errors were encountered:
Context
I have a pending PR for typeshed which fixes overparameterized
dict.get
anddict.pop
methods: python/typeshed#10294. The PR causes a lot of failures in various GitHub projects due to how mypy treats empty collections. Specifically, ifdict.get
is annotated asmypy infers the type of
v
into be
Any | dict[<unknown>, <unknown>]
, instead ofAny | dict[Any, Any]
.Feature
Specialize empty collections to
Any
if no other information is available to recover type arguments.Pitch
Using
<unknown>
instead ofAny
requires users to cast or add type annotations where they otherwise will not be necessary. See comments in the PR for a few examples from real projects.The text was updated successfully, but these errors were encountered: