Open hauntsaninja opened 4 years ago
Would it make sense to add an option to disable these checks, so we could disable them in CI for now?
Here's the results I get from running @hauntsaninja's branch on the stdlib in 2022. Several have been fixed, but there's also a few new ones:
This is getting very close to done now. With the original version of the check run on 3.12 on my macbook, here's what's still left, most of which is unfixable:
error: ctypes.LittleEndianStructure is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/ctypes/__init__.pyi:7
<TypeInfo ctypes._endian.LittleEndianStructure> inherits from _ctypes.Structure
MRO: ctypes._endian.LittleEndianStructure, _ctypes.Structure, _ctypes._StructUnionBase, _ctypes._CData, builtins.object
Runtime:
<class '_ctypes.Structure'> inherits from _ctypes._CData
MRO: _ctypes.Structure, _ctypes._CData, builtins.object
error: ctypes.LittleEndianUnion is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/ctypes/__init__.pyi:12
<TypeInfo ctypes._endian.LittleEndianUnion> inherits from _ctypes.Union
MRO: ctypes._endian.LittleEndianUnion, _ctypes.Union, _ctypes._StructUnionBase, _ctypes._CData, builtins.object
Runtime:
<class '_ctypes.Union'> inherits from _ctypes._CData
MRO: _ctypes.Union, _ctypes._CData, builtins.object
error: ctypes._endian.LittleEndianStructure is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/ctypes/_endian.pyi:7
<TypeInfo ctypes._endian.LittleEndianStructure> inherits from _ctypes.Structure
MRO: ctypes._endian.LittleEndianStructure, _ctypes.Structure, _ctypes._StructUnionBase, _ctypes._CData, builtins.object
Runtime:
<class '_ctypes.Structure'> inherits from _ctypes._CData
MRO: _ctypes.Structure, _ctypes._CData, builtins.object
error: ctypes._endian.LittleEndianUnion is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/ctypes/_endian.pyi:12
<TypeInfo ctypes._endian.LittleEndianUnion> inherits from _ctypes.Union
MRO: ctypes._endian.LittleEndianUnion, _ctypes.Union, _ctypes._StructUnionBase, _ctypes._CData, builtins.object
Runtime:
<class '_ctypes.Union'> inherits from _ctypes._CData
MRO: _ctypes.Union, _ctypes._CData, builtins.object
These are dynamic at runtime, depending on endianness. No way to accurately represent that in typeshed.
LittleEndianUnion
is 3.11 and higher only, as it doesn't exist before then.
error: enum.property is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/enum.pyi:181
<TypeInfo enum.property> inherits from builtins.property
MRO: enum.property, builtins.property, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/enum.py:184
<class 'enum.property'> inherits from types.DynamicClassAttribute
MRO: enum.property, types.DynamicClassAttribute, builtins.object
This one is piggy-backing on special casing of builtins.property, and I believe requires additional special casing added to mypy if it were to be fixed. I gave it a shot in https://github.com/python/typeshed/pull/12762 just to see what it looked like. This only shows up on 3.11 and higher.
error: pathlib.PurePath is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/pathlib.pyi:29
<TypeInfo pathlib.PurePath> inherits from os.PathLike
MRO: pathlib.PurePath, os.PathLike, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pathlib.py:292
<class 'pathlib.PurePath'> inherits from builtins.object
MRO: pathlib.PurePath, builtins.object
This one shows up in the check, but it's just invalid. pathlib.PurePath
gets registered to the
os.PathLike
ABC at runtime.
error: tkinter.Widget is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/tkinter/__init__.pyi:923
<TypeInfo tkinter.Widget> inherits from tkinter.BaseWidget, tkinter.Pack, tkinter.Place, tkinter.Grid
MRO: tkinter.Widget, tkinter.BaseWidget, tkinter.Misc, tkinter.Pack, tkinter.Place, tkinter.Grid, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py:2661
<class 'tkinter.Widget'> inherits from tkinter.BaseWidget, tkinter.Pack, tkinter.Place, tkinter.Grid, tkinter.tix.Form
MRO: tkinter.Widget, tkinter.BaseWidget, tkinter.Misc, tkinter.Pack, tkinter.Place, tkinter.Grid, tkinter.tix.Form, builtins.object
On this one, tkinter.tix.Form
is added directly to tkinter.Widget.__bases__
at runtime. There's
nothing typeshed can do about it, although I gave it a shot in https://github.com/python/typeshed/pull/12751 .
The good news is that tkinter.tix
was removed in 3.13, so this is only a 3.12 and lower issue and will eventually
disappear.
error: dataclasses._MISSING_TYPE is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/dataclasses.pyi:41
<TypeInfo dataclasses._MISSING_TYPE> inherits from enum.Enum
MRO: dataclasses._MISSING_TYPE, enum.Enum, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/dataclasses.py:184
<class 'dataclasses._MISSING_TYPE'> inherits from builtins.object
MRO: dataclasses._MISSING_TYPE, builtins.object
This one is waiting for PEP 661. We'll see what's possible if/when that becomes available.
error: turtle.ScrolledCanvas is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/turtle.pyi:164
<TypeInfo turtle.ScrolledCanvas> inherits from tkinter.Canvas, tkinter.Frame
MRO: turtle.ScrolledCanvas, tkinter.Canvas, tkinter.Frame, tkinter.Widget, tkinter.BaseWidget, tkinter.Misc, tkinter.Pack, tkinter.Place, tkinter.Grid, tkinter.XView, tkinter.YView, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/turtle.py:325
<class 'turtle.ScrolledCanvas'> inherits from tkinter.Frame
MRO: turtle.ScrolledCanvas, tkinter.Frame, tkinter.Widget, tkinter.BaseWidget, tkinter.Misc, tkinter.Pack, tkinter.Place, tkinter.Grid, tkinter.tix.Form, builtins.object
At runtime, turtle.ScrolledCanvas
is not a subclass of tkinter.Canvas
. A helper function runs which
copies all methods from tkinter.Canvas
to turtle.ScrolledCanvas
dynamically.
This one could be fixed, but the number of methods on tkinter.Canvas
is very large and I'm not
sure that even I think that it's worth fixing.
error: importlib.machinery.ExtensionFileLoader is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/importlib/machinery.pyi:151
<TypeInfo importlib.machinery.ExtensionFileLoader> inherits from importlib.abc.ExecutionLoader
MRO: importlib.machinery.ExtensionFileLoader, importlib.abc.ExecutionLoader, importlib.abc.InspectLoader, importlib._abc.Loader, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/_bootstrap_external.py:1267
<class '_frozen_importlib_external.ExtensionFileLoader'> inherits from _frozen_importlib_external.FileLoader, _frozen_importlib_external._LoaderBasics
MRO: _frozen_importlib_external.ExtensionFileLoader, _frozen_importlib_external.FileLoader, _frozen_importlib_external._LoaderBasics, builtins.object
error: importlib.machinery.SourceFileLoader is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/importlib/machinery.pyi:146
<TypeInfo importlib.machinery.SourceFileLoader> inherits from importlib.abc.FileLoader, importlib.abc.SourceLoader
MRO: importlib.machinery.SourceFileLoader, importlib.abc.FileLoader, importlib.abc.SourceLoader, importlib.abc.ResourceLoader, importlib.abc.ExecutionLoader, importlib.abc.InspectLoader, importlib._abc.Loader, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/_bootstrap_external.py:1197
<class '_frozen_importlib_external.SourceFileLoader'> inherits from _frozen_importlib_external.FileLoader, _frozen_importlib_external.SourceLoader
MRO: _frozen_importlib_external.SourceFileLoader, _frozen_importlib_external.FileLoader, _frozen_importlib_external.SourceLoader, _frozen_importlib_external._LoaderBasics, builtins.object
error: importlib.machinery.SourcelessFileLoader is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/importlib/machinery.pyi:149
<TypeInfo importlib.machinery.SourcelessFileLoader> inherits from importlib.abc.FileLoader, importlib.abc.SourceLoader
MRO: importlib.machinery.SourcelessFileLoader, importlib.abc.FileLoader, importlib.abc.SourceLoader, importlib.abc.ResourceLoader, importlib.abc.ExecutionLoader, importlib.abc.InspectLoader, importlib._abc.Loader, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/_bootstrap_external.py:1242
<class '_frozen_importlib_external.SourcelessFileLoader'> inherits from _frozen_importlib_external.FileLoader, _frozen_importlib_external._LoaderBasics
MRO: _frozen_importlib_external.SourcelessFileLoader, _frozen_importlib_external.FileLoader, _frozen_importlib_external._LoaderBasics, builtins.object
These three are fixable, and https://github.com/python/typeshed/pull/12775 fixes them.
On 3.9 and lower, there's a few more:
error: typing_extensions.ParamSpec is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:483
<TypeInfo typing_extensions.ParamSpec> inherits from builtins.object
MRO: typing_extensions.ParamSpec, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:1611
<class 'typing_extensions.ParamSpec'> inherits from builtins.list, typing_extensions._DefaultMixin
MRO: typing_extensions.ParamSpec, builtins.list, typing_extensions._DefaultMixin, builtins.object
I suspect this could be fixed, but I haven't paid it very much attention since it's both 3.9- only and in typing_extensions.
error: typing_extensions.SupportsAbs is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:407
<TypeInfo typing.SupportsAbs> inherits from builtins.object
MRO: typing.SupportsAbs, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:832
<class 'typing_extensions.SupportsAbs'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsAbs, typing_extensions.Protocol, typing.Generic, builtins.object
error: typing_extensions.SupportsBytes is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:397
<TypeInfo typing.SupportsBytes> inherits from builtins.object
MRO: typing.SupportsBytes, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:815
<class 'typing_extensions.SupportsBytes'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsBytes, typing_extensions.Protocol, typing.Generic, builtins.object
error: typing_extensions.SupportsComplex is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:392
<TypeInfo typing.SupportsComplex> inherits from builtins.object
MRO: typing.SupportsComplex, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:806
<class 'typing_extensions.SupportsComplex'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsComplex, typing_extensions.Protocol, typing.Generic, builtins.object
error: typing_extensions.SupportsFloat is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:387
<TypeInfo typing.SupportsFloat> inherits from builtins.object
MRO: typing.SupportsFloat, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:797
<class 'typing_extensions.SupportsFloat'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsFloat, typing_extensions.Protocol, typing.Generic, builtins.object
error: typing_extensions.SupportsIndex is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:286
<TypeInfo typing_extensions.SupportsIndex> inherits from builtins.object
MRO: typing_extensions.SupportsIndex, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:824
<class 'typing_extensions.SupportsIndex'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsIndex, typing_extensions.Protocol, typing.Generic, builtins.object
error: typing_extensions.SupportsInt is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:382
<TypeInfo typing.SupportsInt> inherits from builtins.object
MRO: typing.SupportsInt, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:788
<class 'typing_extensions.SupportsInt'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsInt, typing_extensions.Protocol, typing.Generic, builtins.object
error: typing_extensions.SupportsRound is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing_extensions.pyi:412
<TypeInfo typing.SupportsRound> inherits from builtins.object
MRO: typing.SupportsRound, builtins.object
Runtime: in file /Users/stephen/Developer/clones/mypy/.venv39/lib/python3.9/site-packages/typing_extensions.py:843
<class 'typing_extensions.SupportsRound'> inherits from typing_extensions.Protocol
MRO: typing_extensions.SupportsRound, typing_extensions.Protocol, typing.Generic, builtins.object
These showed up when I ran the check on 3.9 just now, but I don't remember them being there before. Looks like they're 3.11 and lower. These are more an artifact of stubcheck then anything real.
error: weakref.KeyedRef is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/weakref.pyi:127
<TypeInfo weakref.KeyedRef> inherits from weakref.ReferenceType
MRO: weakref.KeyedRef, weakref.ReferenceType, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/weakref.py:336
<class 'weakref.KeyedRef'> inherits from builtins.weakref
MRO: weakref.KeyedRef, builtins.weakref, builtins.object
error: weakref.WeakMethod is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/weakref.pyi:69
<TypeInfo weakref.WeakMethod> inherits from weakref.ReferenceType
MRO: weakref.WeakMethod, weakref.ReferenceType, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/weakref.py:39
<class 'weakref.WeakMethod'> inherits from builtins.weakref
MRO: weakref.WeakMethod, builtins.weakref, builtins.object
Not fixable; These are artifacts of the fact that classes in _weakref
/weakref
gave themselves
names within C that didn't match their names within python before 3.10 fixed it.
error: nntplib.NNTP_SSL is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/nntplib.pyi:112
<TypeInfo nntplib.NNTP_SSL> inherits from nntplib.NNTP
MRO: nntplib.NNTP_SSL, nntplib.NNTP, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/nntplib.py:1068
<class 'nntplib.NNTP_SSL'> inherits from nntplib._NNTPBase
MRO: nntplib.NNTP_SSL, nntplib._NNTPBase, builtins.object
error: typing.NamedTuple is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/typing.pyi:915
<TypeInfo typing.NamedTuple> inherits from builtins.tuple
MRO: typing.NamedTuple, builtins.tuple, typing.Sequence, typing.Reversible, typing.Collection, typing.Iterable, typing.Container, builtins.object
Runtime: in file /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/typing.py:1644
<class 'typing.NamedTuple'> inherits from builtins.object
MRO: typing.NamedTuple, builtins.object
Finally this pair are 3.8 and lower only, which means they're going away soon I believe?
nntplib.NNTP_SSL
could be fixed at the cost of duplication (nntplib._NNTPBase
was renamed).
NamedTuple is always messy. Neither is worth dealing with.
I actually haven't run it on 3.13 yet, so let's do that now. 3.13 adds:
error: _interpreters.NotShareableError is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/_interpreters.pyi:10
<TypeInfo _interpreters.NotShareableError> inherits from builtins.Exception
MRO: _interpreters.NotShareableError, builtins.Exception, builtins.BaseException, builtins.object
Runtime:
<class 'interpreters.NotShareableError'> inherits from builtins.ValueError
MRO: interpreters.NotShareableError, builtins.ValueError, builtins.Exception, builtins.BaseException, builtins.object
error: multiprocessing.managers.DictProxy is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/multiprocessing/managers.pyi:63
<TypeInfo multiprocessing.managers.DictProxy> inherits from multiprocessing.managers.BaseProxy, typing.MutableMapping
MRO: multiprocessing.managers.DictProxy, multiprocessing.managers.BaseProxy, typing.MutableMapping, typing.Mapping, typing.Collection, typing.Iterable, typing.Container, builtins.object
Runtime: in file /opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/managers.py:1179
<class 'multiprocessing.managers.DictProxy'> inherits from multiprocessing.managers.DictProxy
MRO: multiprocessing.managers.DictProxy, multiprocessing.managers.DictProxy, multiprocessing.managers.BaseProxy, builtins.object
error: pathlib.Path is inconsistent, base classes and MRO differ. INHERITANCE
Stub: in file ../typeshed/stdlib/pathlib.pyi:103
<TypeInfo pathlib.Path> inherits from pathlib.PurePath
MRO: pathlib.Path, pathlib.PurePath, os.PathLike, builtins.object
Runtime: in file /opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/pathlib/_local.py:482
<class 'pathlib._local.Path'> inherits from pathlib._abc.PathBase, pathlib._local.PurePath
MRO: pathlib._local.Path, pathlib._abc.PathBase, pathlib._local.PurePath, pathlib._abc.PurePathBase, builtins.object
_interpreters.NotShareableError
looks extremely straightforward.
multiprocessing.managers.DictProxy
was already on my list of things to look into, and is probably
fixable but I don't know yet.
pathlib.Path
looks basically fixable, but needs investigation to determine how much duplicated code
would be needed to fix it.
And that's everything! I've been working with various stricter versions of the inheritance check for a while now. I'll probably propose my own version of it for inclusion in stubcheck once I get things a little more cleaned up, and that can probably mark the end of this issue. Almost there!
I had a patch to stubtest that added checking of base classes. Unfortunately, it was too noisy to consider merging, although some fixes did come out of it. I complicated the patch today, and most of the following look actionable. Figured I'd jot the output down here, so it doesn't get forgotten about, since I'm not sure I want to merge this newly complicated patch (branch at https://github.com/hauntsaninja/mypy/tree/stubtestbaseclass). I'll chip away at these, but if someone reading this is looking to contribute to typeshed, this is a good place to start!