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
The way some collection builtins (e.g. list, dict, ...) are defined in typeshed causes false positive with type checking, due to the incorrect MRO exposed by typeshed.
So my guess is that typeshed should not tell mypy that "list and co" are subclasses of "MutableSequence and co".
Note:
while this particular choice of inheritance is debatable, it is fundamental for the way some libraries work, e.g. tomlkit work. It uses MutableSequence as a mixin, so that I gets MutableSequence methods for free, but it also want the custom objects to be considered lists themselves, so the users can use the API transparently as if they were dealing with built-in objects (this is an important aspect of the design).
The way some collection builtins (e.g.
list
,dict
, ...) are defined in typeshed causes false positive with type checking, due to the incorrect MRO exposed by typeshed.For example,
typeshed/stdlib/builtins.pyi
Line 971 in af84d2f
MutableSequence
", however that is not true and causes the following false negative error:https://mypy-play.net/?mypy=latest&python=3.12&gist=dc0042ce469e49dc22de0c91384d4588
Note that this does not correspond to the real implementation. When I run the script above, no runtime error is found. Instead, this is the output:
So my guess is that
typeshed
should not tellmypy
that "list
and co" are subclasses of "MutableSequence
and co".Note:
while this particular choice of inheritance is debatable, it is fundamental for the way some libraries work, e.g.
tomlkit
work. It usesMutableSequence
as a mixin, so that I getsMutableSequence
methods for free, but it also want the custom objects to be considered lists themselves, so the users can use the API transparently as if they were dealing with built-in objects (this is an important aspect of the design).Related: python/mypy#11427
The text was updated successfully, but these errors were encountered: