diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index e2f5003b3..c170ef769 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -4,7 +4,6 @@ # Please keep sorted alphabetically -_asyncio.Future.__init__ # Usually initialized from c object _collections_abc.AsyncGenerator.ag_await _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame @@ -13,19 +12,10 @@ _collections_abc.ItemsView.__reversed__ _collections_abc.KeysView.__reversed__ _collections_abc.ValuesView.__reversed__ _ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed -_threading_local.local.__new__ -ast.Bytes.__new__ -ast.Ellipsis.__new__ -ast.NameConstant.__new__ -ast.Num.__new__ -ast.Str.__new__ asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them -asyncio.Future.__init__ # Usually initialized from c object -asyncio.futures.Future.__init__ # Usually initialized from c object builtins.dict.get collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023 -collections\.UserList\.sort # Runtime has *args but will error if any are supplied configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used # SectionProxy get functions are set in __init__ configparser.SectionProxy.getboolean @@ -61,10 +51,6 @@ ipaddress._BaseNetwork.max_prefixlen multiprocessing.JoinableQueue multiprocessing.Queue multiprocessing.SimpleQueue -multiprocessing.managers.SyncManager.Event -multiprocessing.managers.SyncManager.Lock -multiprocessing.managers.SyncManager.Namespace -multiprocessing.managers.SyncManager.RLock multiprocessing.queues.JoinableQueue.__init__ multiprocessing.queues.Queue.__init__ multiprocessing.queues.SimpleQueue.__init__ @@ -92,15 +78,11 @@ tkinter.simpledialog.TclVersion tkinter.simpledialog.TkVersion tkinter.Misc.after # we intentionally don't allow everything that "works" at runtime tkinter.Text.count # stubtest somehow thinks that index1 parameter has a default value, but it doesn't in any of the overloads -traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__ typing(_extensions)?\.IO\.__next__ # Added because IO streams are iterable. See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 typing.type_check_only # typing decorator that is not available at runtime unittest.mock.patch # It's a complicated overload and I haven't been able to figure out why stubtest doesn't like it -urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified weakref.WeakKeyDictionary.update 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 xml.parsers.expat.expat_CAPI # ========== @@ -330,13 +312,33 @@ collections.abc.* # Types are re-exported from _collections_abc, so errors shou _?ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char _?ctypes.Array._type_ # _type_ is abstract, https://github.com/python/typeshed/pull/6361 _?ctypes.Array._length_ # _length_ is abstract, https://github.com/python/typeshed/pull/6361 + +# runtime is *args, **kwargs due to a wrapper +# we have more accurate signatures in the stubs +_frozen_importlib_external.ExtensionFileLoader.get_filename +_frozen_importlib_external.FileLoader.get_filename +_frozen_importlib_external.FileLoader.get_resource_reader +_frozen_importlib_external.FileLoader.load_module + _pydecimal.* # See comments in file argparse.ArgumentParser.__init__ # stubtest doesn't recognise the runtime default (a class) as being compatible with a callback protocol (the stub annotation) argparse.Namespace.__getattr__ # The whole point of this class is its attributes are dynamic + +# runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs +ast.Bytes.__new__ +ast.Ellipsis.__new__ +ast.NameConstant.__new__ +ast.Num.__new__ +ast.Str.__new__ + ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796 asyncio.proactor_events.BaseProactorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation asyncio.selector_events.BaseSelectorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation +_asyncio.Future.__init__ # Usually initialized from c object +asyncio.Future.__init__ # Usually initialized from c object +asyncio.futures.Future.__init__ # Usually initialized from c object + # Condition functions are exported in __init__ asyncio.Condition.acquire asyncio.Condition.locked @@ -379,6 +381,7 @@ codecs.CodecInfo.incrementalencoder codecs.CodecInfo.streamreader codecs.CodecInfo.streamwriter +collections.UserList.sort # Runtime has *args but will error if any are supplied contextvars.Context.__init__ # C signature is broader than what is actually accepted # The Dialect properties are initialized as None in Dialect but their values are enforced in _Dialect @@ -396,6 +399,16 @@ email.policy.EmailPolicy.message_factory # "type" at runtime, but protocol in s hashlib.scrypt # Raises TypeError if salt, n, r or p are None hmac.HMAC.blocksize # use block_size instead +# runtime is *args, **kwargs due to a wrapper +# we have more accurate signatures in the stubs +importlib._bootstrap_external.ExtensionFileLoader.get_filename +importlib._bootstrap_external.FileLoader.get_filename +importlib._bootstrap_external.FileLoader.get_resource_reader +importlib._bootstrap_external.FileLoader.load_module +importlib.abc.FileLoader.get_filename +importlib.abc.FileLoader.load_module +importlib.machinery.ExtensionFileLoader.get_filename + # We can't distinguish not having a default value from having a default value of inspect.Parameter.empty inspect.Parameter.__init__ inspect.Signature.__init__ @@ -417,6 +430,12 @@ multiprocessing.managers.DictProxy.items multiprocessing.managers.DictProxy.keys multiprocessing.managers.DictProxy.values +# runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs +multiprocessing.managers.SyncManager.Event +multiprocessing.managers.SyncManager.Lock +multiprocessing.managers.SyncManager.Namespace +multiprocessing.managers.SyncManager.RLock + multiprocessing.(dummy|managers).Namespace.__[gs]etattr__ # Any field can be set on Namespace # alias for a class defined elsewhere, # mypy infers the variable has type `(*args) -> ForkingPickler` @@ -644,6 +663,9 @@ tkinter.Misc.pack_propagate # The noarg placeholder is a set value list tkinter.Tk.report_callback_exception # A bit of a lie, since it's actually a method, but typing it as an attribute allows it to be assigned to tkinter.Wm.wm_iconphoto # Default value of argument can't be used without runtime error +traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__ +urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified + # Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__) # These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220 _ctypes.Array.__iter__ @@ -654,6 +676,9 @@ xml.etree.ElementTree.Element.__iter__ xml.etree.cElementTree.Element.__iter__ typing(_extensions)?\.IO\.__iter__ # See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 +xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature +xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature + # Added or modified in a patch release, backported to all security branches, # but have yet to find their way to all GitHub Actions images (tarfile.tar_filter)? @@ -681,17 +706,3 @@ typing(_extensions)?\.IO\.__iter__ # See https://github.com/python/typeshed/com enum.auto.__or__ enum.auto.__and__ enum.auto.__xor__ - -# wrapped with _check_name decorator which adds *args, **kwargs -# we have more accurate signatures in the stubs -_frozen_importlib_external.ExtensionFileLoader.get_filename -_frozen_importlib_external.FileLoader.get_filename -_frozen_importlib_external.FileLoader.get_resource_reader -_frozen_importlib_external.FileLoader.load_module -importlib._bootstrap_external.ExtensionFileLoader.get_filename -importlib._bootstrap_external.FileLoader.get_filename -importlib._bootstrap_external.FileLoader.get_resource_reader -importlib._bootstrap_external.FileLoader.load_module -importlib.abc.FileLoader.get_filename -importlib.abc.FileLoader.load_module -importlib.machinery.ExtensionFileLoader.get_filename diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 308855f8f..5df7f76eb 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -6,7 +6,6 @@ _collections_abc.MappingView.__class_getitem__ _csv.Reader _csv.Writer bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set -configparser.LegacyInterpolation.__init__ configparser.ParsingError.filename collections\.UserList\.index # ignoring pos-or-keyword parameter enum.Enum.__init__ @@ -106,6 +105,8 @@ os.path.join # Allowlist entries that cannot or should not be fixed # ========== +configparser.LegacyInterpolation.__init__ # runtime is *args, **kwargs, but it's just a passthrough + # Factory function at runtime # but that wouldn't let us use it in type hints threading.Lock diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 14500a678..bb9e5483f 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -9,7 +9,6 @@ _collections_abc.Iterable.__class_getitem__ _collections_abc.MappingView.__class_getitem__ _csv.Reader _csv.Writer -configparser.LegacyInterpolation.__init__ enum.Enum.__init__ importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility lib2to3.pygram.pattern_symbols @@ -89,6 +88,8 @@ zoneinfo.ZoneInfo.from_file # Allowlist entries that cannot or should not be fixed # ========== +configparser.LegacyInterpolation.__init__ # runtime is *args, **kwargs, but it's just a passthrough + # Factory function at runtime # but that wouldn't let us use it in type hints threading.Lock diff --git a/stdlib/_threading_local.pyi b/stdlib/_threading_local.pyi index 98683dabc..f9ac94227 100644 --- a/stdlib/_threading_local.pyi +++ b/stdlib/_threading_local.pyi @@ -1,5 +1,5 @@ from typing import Any -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias from weakref import ReferenceType __all__ = ["local"] @@ -12,6 +12,7 @@ class _localimpl: def create_dict(self) -> _LocalDict: ... class local: + def __new__(cls, /, *args: Any, **kw: Any) -> Self: ... def __getattribute__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... def __delattr__(self, name: str) -> None: ...