diff --git a/.github/workflows/stubtest.yml b/.github/workflows/stubtest.yml index 708692c62a75..d092a96329cd 100644 --- a/.github/workflows/stubtest.yml +++ b/.github/workflows/stubtest.yml @@ -39,7 +39,7 @@ jobs: # - get_mypy_req in tests/stubtest_third_party.py # - stubtest-stdlib in .github/workflows/stubtest.yml # - stubtest-stdlib in .github/workflows/tests.yml - run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@080bb0e04e9d5c4d2513621d1fb62f1d61a573e9 + run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@a562f0aac287b1069a8267b3812fb6813eaefec3 - name: Run stubtest run: python tests/stubtest_stdlib.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a6c72dc9f93f..08ee9405ee62 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -114,7 +114,7 @@ jobs: # - get_mypy_req in tests/stubtest_third_party.py # - stubtest-stdlib in .github/workflows/stubtest.yml # - stubtest-stdlib in .github/workflows/tests.yml - run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@080bb0e04e9d5c4d2513621d1fb62f1d61a573e9 + run: pip install $(grep tomli== requirements-tests.txt) git+git://github.com/python/mypy@a562f0aac287b1069a8267b3812fb6813eaefec3 - name: Run stubtest run: python tests/stubtest_stdlib.py diff --git a/stdlib/multiprocessing/context.pyi b/stdlib/multiprocessing/context.pyi index 28ec0b140566..db8e6216b6ad 100644 --- a/stdlib/multiprocessing/context.pyi +++ b/stdlib/multiprocessing/context.pyi @@ -8,7 +8,7 @@ from multiprocessing import queues, synchronize from multiprocessing.pool import Pool as _Pool from multiprocessing.process import BaseProcess from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase -from typing import Any, TypeVar, Union, overload +from typing import Any, ClassVar, TypeVar, Union, overload from typing_extensions import Literal if sys.version_info >= (3, 8): @@ -139,6 +139,8 @@ class DefaultContext(BaseContext): def set_start_method(self, method: str | None, force: bool = ...) -> None: ... def get_start_method(self, allow_none: bool = ...) -> str: ... def get_all_start_methods(self) -> list[str]: ... + if sys.version_info < (3, 8): + __all__: ClassVar[list[str]] _default_context: DefaultContext diff --git a/tests/stubtest_allowlists/darwin-py310.txt b/tests/stubtest_allowlists/darwin-py310.txt index 8a3185cd8c13..3f08864b49bc 100644 --- a/tests/stubtest_allowlists/darwin-py310.txt +++ b/tests/stubtest_allowlists/darwin-py310.txt @@ -4,3 +4,4 @@ curses.color_pair # Exists at runtime, but missing from stubs mmap.MADV_FREE +distutils.util.__warningregistry__ diff --git a/tests/stubtest_allowlists/linux-py310.txt b/tests/stubtest_allowlists/linux-py310.txt index d435cdd0a567..fd9123733be0 100644 --- a/tests/stubtest_allowlists/linux-py310.txt +++ b/tests/stubtest_allowlists/linux-py310.txt @@ -18,6 +18,7 @@ signal.sigwaitinfo select.epoll.register # Exists at runtime, but missing from stubs +distutils.command.build_ext.__warningregistry__ os.EFD_CLOEXEC os.EFD_NONBLOCK os.EFD_SEMAPHORE diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 4c77a02746dc..911510b3846f 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -16,6 +16,25 @@ _collections_abc.MutableMapping.__setitem__ _collections_abc.MutableMapping.pop _collections_abc.MutableMapping.setdefault +# Many positional-only differences with KeysView/ItemsView +_collections_abc.dict_keys.__.*__ +_collections_abc.dict_items.__.*__ + +# Pos-only differences with object.__setattr__/object.__delattr__ +# Adding these to the stub has bad consequences (see #7385, #7347) +enum.EnumMeta.__setattr__ +enum.EnumMeta.__delattr__ +uuid.UUID.__setattr__ + +# Pos-only differences with the normal NamedTuple __getitem__ +platform.uname_result.__getitem__ + +# mypy does not autogenerate __eq__ methods for dataclasses, +# so wrongly infers that these have positional-only parameters. +# https://github.com/python/mypy/issues/12186 +pstats.FunctionProfile.__eq__ +pstats.StatsProfile.__eq__ + # typing.IO uses positional-or-keyword arguments, but in the stubs we prefer # to mark these as positional-only for compatibility with existing sub-classes. typing.BinaryIO.write @@ -28,6 +47,7 @@ typing.IO.truncate typing.IO.write typing.IO.writelines +_weakref.ProxyType.__reversed__ # Doesn't really exist ast.Bytes.__new__ ast.Ellipsis.__new__ ast.ExtSlice.__new__ @@ -41,6 +61,8 @@ asyncio.Future._callbacks # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures.Future._callbacks # Usually initialized from c object builtins.dict.get +builtins.float.__set_format__ # Internal method for CPython test suite +builtins.property.__set_name__ # Doesn't actually exist contextvars.Context.__init__ # Default C __init__ signature is wrong contextlib.AbstractAsyncContextManager.__class_getitem__ contextlib.AbstractContextManager.__class_getitem__ @@ -78,9 +100,11 @@ sys.UnraisableHookArgs # Not exported from sys types.ClassMethodDescriptorType.__get__ types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime types.GenericAlias.__getattr__ +types.GenericAlias.__mro_entries__ types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392 types.MethodDescriptorType.__get__ types.WrapperDescriptorType.__get__ +typing._SpecialForm.__mro_entries__ typing.ForwardRef._evaluate typing.SupportsAbs.__init__ typing.SupportsBytes.__init__ @@ -100,6 +124,7 @@ typing._TypedDict.pop typing._TypedDict.setdefault typing._TypedDict.update typing._TypedDict.values +weakref.ProxyType.__reversed__ # Doesn't really exist weakref.WeakValueDictionary.update xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature @@ -112,6 +137,8 @@ _collections_abc.Coroutine.send _collections_abc.Coroutine.throw _collections_abc.Generator.send _collections_abc.Generator.throw +_collections_abc.Mapping.__eq__ +_collections_abc.Set.__eq__ contextlib.AbstractAsyncContextManager.__aexit__ contextlib.AbstractContextManager.__exit__ @@ -146,13 +173,16 @@ _csv.Writer _imp.source_hash ast.Tuple.dims ast.main +asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this asyncio.AbstractEventLoop.connect_accepted_socket asyncio.events.AbstractEventLoop.connect_accepted_socket bdb.Breakpoint.clearBreakpoints +dbm.dumb._Database.__contains__ distutils.dist.DistributionMetadata.set_classifiers distutils.dist.DistributionMetadata.set_keywords distutils.dist.DistributionMetadata.set_platforms distutils.util.get_host_platform +functools.partial.__vectorcalloffset__ # undocumented implementation detail multiprocessing.managers.SharedMemoryServer.create multiprocessing.managers.SharedMemoryServer.list_segments multiprocessing.managers.SharedMemoryServer.public diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index 94025b954f6c..b3ce9269429e 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -6,6 +6,9 @@ _dummy_threading asyncio.Future.__init__ # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures._TracebackLogger.__init__ +asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub +asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub +builtins.float.__setformat__ # Internal method for CPython test suite builtins.str.maketrans cmath.log collections.AsyncGenerator.ag_await @@ -13,6 +16,12 @@ collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame collections.AsyncGenerator.ag_running collections.Callable +collections.Mapping.__reversed__ # Set to None at runtime for a better error message +# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. +collections.Set.__rand__ +collections.Set.__ror__ +collections.Set.__rsub__ +collections.Set.__rxor__ collections.UserString.maketrans datetime.datetime_CAPI distutils.command.bdist_wininst # see #6523 @@ -129,4 +138,5 @@ tempfile.SpooledTemporaryFile.softspace tkinter.dnd.Icon tkinter.dnd.Tester tkinter.dnd.test +typing.[A-Z]\w*.__.*__ # many missing typing dunders in py36 xml.dom.xmlbuilder.DocumentLS.async diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index 987623d79667..e0d94bde87cc 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -3,11 +3,16 @@ _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame _collections_abc.AsyncGenerator.ag_running _dummy_threading +asyncio.AbstractEventLoop.run_in_executor # allowed to return a Future, changed in 3.8 +asyncio.events.AbstractEventLoop.run_in_executor # allowed to return a Future, changed in 3.8 asyncio.Future.__init__ # Usually initialized from c object asyncio.Future._callbacks # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures.Future._callbacks # Usually initialized from c object +asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub +asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub builtins.dict.get +builtins.float.__set_format__ # Internal method for CPython test suite builtins.str.maketrans cmath.log collections.AsyncGenerator.ag_await @@ -15,6 +20,12 @@ collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame collections.AsyncGenerator.ag_running collections.Callable +collections.Mapping.__reversed__ # Set to None at runtime for a better error message +# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. +collections.Set.__rand__ +collections.Set.__ror__ +collections.Set.__rsub__ +collections.Set.__rxor__ collections.UserString.maketrans contextvars.Context.__init__ # Default C __init__ signature is wrong contextvars.ContextVar.get diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index 13a72397cef4..d51f85d6ec1e 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -15,7 +15,10 @@ asyncio.Future.__init__ # Usually initialized from c object asyncio.Future._callbacks # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures.Future._callbacks # Usually initialized from c object +asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub +asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub builtins.dict.get +builtins.float.__set_format__ # Internal method for CPython test suite collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame @@ -24,6 +27,12 @@ collections.Callable collections.ItemsView.__reversed__ collections.KeysView.__reversed__ collections.ValuesView.__reversed__ +collections.Mapping.__reversed__ # Set to None at runtime for a better error message +# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. +collections.Set.__rand__ +collections.Set.__ror__ +collections.Set.__rsub__ +collections.Set.__rxor__ contextvars.Context.__init__ # Default C __init__ signature is wrong dataclasses.field distutils.command.bdist_wininst # see #6523 diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 3b16ecb95eae..666290a70570 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -6,6 +6,7 @@ _collections_abc.AsyncGenerator.ag_running _collections_abc.ItemsView.__reversed__ _collections_abc.KeysView.__reversed__ _collections_abc.ValuesView.__reversed__ +_weakref.ProxyType.__reversed__ # Doesn't really exist ast.Bytes.__new__ ast.Ellipsis.__new__ ast.ExtSlice.__new__ @@ -19,14 +20,21 @@ asyncio.Future._callbacks # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures.Future._callbacks # Usually initialized from c object builtins.dict.get +builtins.float.__set_format__ # Internal method for CPython test suite collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame collections.AsyncGenerator.ag_running collections.Callable +collections.Mapping.__reversed__ # Set to None at runtime for a better error message collections.ItemsView.__reversed__ collections.KeysView.__reversed__ collections.ValuesView.__reversed__ +# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. +collections.Set.__rand__ +collections.Set.__ror__ +collections.Set.__rsub__ +collections.Set.__rxor__ contextvars.Context.__init__ # Default C __init__ signature is wrong contextlib.AbstractAsyncContextManager.__class_getitem__ contextlib.AbstractContextManager.__class_getitem__ @@ -83,6 +91,7 @@ typing._TypedDict.pop typing._TypedDict.setdefault typing._TypedDict.update typing._TypedDict.values +weakref.ProxyType.__reversed__ # Doesn't really exist weakref.WeakValueDictionary.update xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature @@ -146,7 +155,9 @@ pyexpat.XMLParserType.SkippedEntityHandler pyexpat.XMLParserType.intern stringprep.unicodedata # re-exported from unicodedata types.CoroutineType.cr_origin +types.GenericAlias.__mro_entries__ typing._SpecialForm.__call__ +typing._SpecialForm.__mro_entries__ unicodedata.UCD.is_normalized xml.parsers.expat.XMLParserType.SkippedEntityHandler xml.parsers.expat.XMLParserType.intern diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index e4fe05c80536..cc2accf895e1 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -13,8 +13,14 @@ _collections_abc.Generator.gi_code _collections_abc.Generator.gi_frame _collections_abc.Generator.gi_running _collections_abc.Generator.gi_yieldfrom +_collections_abc.Mapping.__reversed__ # set to None at runtime for a better error message _collections_abc.Mapping.get # Adding None to the Union messed up mypy _collections_abc.Sequence.index # Supporting None in end is not mandatory +# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. +_collections_abc.Set.__rand__ +_collections_abc.Set.__ror__ +_collections_abc.Set.__rsub__ +_collections_abc.Set.__rxor__ _csv.Dialect.__init__ # C __init__ signature is inaccurate _socket.* _threading_local.local.__new__ @@ -240,14 +246,21 @@ xml.parsers.expat.expat_CAPI # Allowlist entries that cannot or should not be fixed # ========== _pydecimal.* # See comments in file +_weakref.ProxyType.__bytes__ # Doesn't really exist ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796 # Weird special builtins that are typed as functions, but aren't functions builtins.copyright builtins.credits builtins.exit +builtins.float.__getformat__ # Internal method for CPython test suite builtins.help builtins.license builtins.quit +# These super() dunders don't seem to be particularly useful, +# and having them pop up on autocomplete suggestions would be annoying +builtins.super.__self__ +builtins.super.__self_class__ +builtins.super.__thisclass__ # GetSetDescriptor that always raises AttributeError builtins.OSError.characters_written # Aliases for OSError @@ -290,6 +303,7 @@ sys.tracebacklimit codecs.StreamReaderWriter.\w+ codecs.StreamRecoder.\w+ urllib.response.addbase.\w+ +weakref.ProxyType.__bytes__ # Doesn't actually exist # Dynamically created, has unnecessary *args turtle.ScrolledCanvas.find_all @@ -668,7 +682,6 @@ pkgutil.ImpLoader.source # ========== # Exists at runtime, but missing from stubs # ========== -__main__.\w+ _json.encode_basestring _thread.LockType.acquire_lock _thread.LockType.locked_lock diff --git a/tests/stubtest_allowlists/win32-py310.txt b/tests/stubtest_allowlists/win32-py310.txt index 2fcacc00a5b2..364d1144d00e 100644 --- a/tests/stubtest_allowlists/win32-py310.txt +++ b/tests/stubtest_allowlists/win32-py310.txt @@ -20,6 +20,7 @@ asyncio.IocpProactor.recvfrom asyncio.IocpProactor.sendto asyncio.windows_events.IocpProactor.recvfrom asyncio.windows_events.IocpProactor.sendto +distutils.command.build_ext.__warningregistry__ msvcrt.GetErrorMode socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 3c858a056ae3..7fce6d856a42 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -22,7 +22,7 @@ def get_mypy_req(): # - get_mypy_req in tests/stubtest_third_party.py # - stubtest-stdlib in .github/workflows/stubtest.yml # - stubtest-stdlib in .github/workflows/tests.yml - return "git+git://github.com/python/mypy@080bb0e04e9d5c4d2513621d1fb62f1d61a573e9" + return "git+git://github.com/python/mypy@a562f0aac287b1069a8267b3812fb6813eaefec3" with open("requirements-tests.txt") as f: return next(line.strip() for line in f if "mypy" in line)