Skip to content

Commit 7b68c81

Browse files
authored
move various cases of 'stub does not have *args argument' to "don't fix" (#12956)
1 parent f314631 commit 7b68c81

File tree

4 files changed

+49
-35
lines changed

4 files changed

+49
-35
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
# Please keep sorted alphabetically
66

7-
_asyncio.Future.__init__ # Usually initialized from c object
87
_collections_abc.AsyncGenerator.ag_await
98
_collections_abc.AsyncGenerator.ag_code
109
_collections_abc.AsyncGenerator.ag_frame
@@ -13,19 +12,10 @@ _collections_abc.ItemsView.__reversed__
1312
_collections_abc.KeysView.__reversed__
1413
_collections_abc.ValuesView.__reversed__
1514
_ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed
16-
_threading_local.local.__new__
17-
ast.Bytes.__new__
18-
ast.Ellipsis.__new__
19-
ast.NameConstant.__new__
20-
ast.Num.__new__
21-
ast.Str.__new__
2215
asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
2316
asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
24-
asyncio.Future.__init__ # Usually initialized from c object
25-
asyncio.futures.Future.__init__ # Usually initialized from c object
2617
builtins.dict.get
2718
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
28-
collections\.UserList\.sort # Runtime has *args but will error if any are supplied
2919
configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used
3020
# SectionProxy get functions are set in __init__
3121
configparser.SectionProxy.getboolean
@@ -61,10 +51,6 @@ ipaddress._BaseNetwork.max_prefixlen
6151
multiprocessing.JoinableQueue
6252
multiprocessing.Queue
6353
multiprocessing.SimpleQueue
64-
multiprocessing.managers.SyncManager.Event
65-
multiprocessing.managers.SyncManager.Lock
66-
multiprocessing.managers.SyncManager.Namespace
67-
multiprocessing.managers.SyncManager.RLock
6854
multiprocessing.queues.JoinableQueue.__init__
6955
multiprocessing.queues.Queue.__init__
7056
multiprocessing.queues.SimpleQueue.__init__
@@ -92,15 +78,11 @@ tkinter.simpledialog.TclVersion
9278
tkinter.simpledialog.TkVersion
9379
tkinter.Misc.after # we intentionally don't allow everything that "works" at runtime
9480
tkinter.Text.count # stubtest somehow thinks that index1 parameter has a default value, but it doesn't in any of the overloads
95-
traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__
9681
typing(_extensions)?\.IO\.__next__ # Added because IO streams are iterable. See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3
9782
typing.type_check_only # typing decorator that is not available at runtime
9883
unittest.mock.patch # It's a complicated overload and I haven't been able to figure out why stubtest doesn't like it
99-
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified
10084
weakref.WeakKeyDictionary.update
10185
weakref.WeakValueDictionary.update
102-
xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature
103-
xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature
10486
xml.parsers.expat.expat_CAPI
10587

10688
# ==========
@@ -330,13 +312,33 @@ collections.abc.* # Types are re-exported from _collections_abc, so errors shou
330312
_?ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char
331313
_?ctypes.Array._type_ # _type_ is abstract, https://github.com/python/typeshed/pull/6361
332314
_?ctypes.Array._length_ # _length_ is abstract, https://github.com/python/typeshed/pull/6361
315+
316+
# runtime is *args, **kwargs due to a wrapper
317+
# we have more accurate signatures in the stubs
318+
_frozen_importlib_external.ExtensionFileLoader.get_filename
319+
_frozen_importlib_external.FileLoader.get_filename
320+
_frozen_importlib_external.FileLoader.get_resource_reader
321+
_frozen_importlib_external.FileLoader.load_module
322+
333323
_pydecimal.* # See comments in file
334324
argparse.ArgumentParser.__init__ # stubtest doesn't recognise the runtime default (a class) as being compatible with a callback protocol (the stub annotation)
335325
argparse.Namespace.__getattr__ # The whole point of this class is its attributes are dynamic
326+
327+
# runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
328+
ast.Bytes.__new__
329+
ast.Ellipsis.__new__
330+
ast.NameConstant.__new__
331+
ast.Num.__new__
332+
ast.Str.__new__
333+
336334
ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796
337335
asyncio.proactor_events.BaseProactorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation
338336
asyncio.selector_events.BaseSelectorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation
339337

338+
_asyncio.Future.__init__ # Usually initialized from c object
339+
asyncio.Future.__init__ # Usually initialized from c object
340+
asyncio.futures.Future.__init__ # Usually initialized from c object
341+
340342
# Condition functions are exported in __init__
341343
asyncio.Condition.acquire
342344
asyncio.Condition.locked
@@ -379,6 +381,7 @@ codecs.CodecInfo.incrementalencoder
379381
codecs.CodecInfo.streamreader
380382
codecs.CodecInfo.streamwriter
381383

384+
collections.UserList.sort # Runtime has *args but will error if any are supplied
382385
contextvars.Context.__init__ # C signature is broader than what is actually accepted
383386

384387
# 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
396399
hashlib.scrypt # Raises TypeError if salt, n, r or p are None
397400
hmac.HMAC.blocksize # use block_size instead
398401

402+
# runtime is *args, **kwargs due to a wrapper
403+
# we have more accurate signatures in the stubs
404+
importlib._bootstrap_external.ExtensionFileLoader.get_filename
405+
importlib._bootstrap_external.FileLoader.get_filename
406+
importlib._bootstrap_external.FileLoader.get_resource_reader
407+
importlib._bootstrap_external.FileLoader.load_module
408+
importlib.abc.FileLoader.get_filename
409+
importlib.abc.FileLoader.load_module
410+
importlib.machinery.ExtensionFileLoader.get_filename
411+
399412
# We can't distinguish not having a default value from having a default value of inspect.Parameter.empty
400413
inspect.Parameter.__init__
401414
inspect.Signature.__init__
@@ -417,6 +430,12 @@ multiprocessing.managers.DictProxy.items
417430
multiprocessing.managers.DictProxy.keys
418431
multiprocessing.managers.DictProxy.values
419432

433+
# runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
434+
multiprocessing.managers.SyncManager.Event
435+
multiprocessing.managers.SyncManager.Lock
436+
multiprocessing.managers.SyncManager.Namespace
437+
multiprocessing.managers.SyncManager.RLock
438+
420439
multiprocessing.(dummy|managers).Namespace.__[gs]etattr__ # Any field can be set on Namespace
421440
# alias for a class defined elsewhere,
422441
# mypy infers the variable has type `(*args) -> ForkingPickler`
@@ -644,6 +663,9 @@ tkinter.Misc.pack_propagate # The noarg placeholder is a set value list
644663
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
645664
tkinter.Wm.wm_iconphoto # Default value of argument can't be used without runtime error
646665

666+
traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__
667+
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified
668+
647669
# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
648670
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
649671
_ctypes.Array.__iter__
@@ -654,6 +676,9 @@ xml.etree.ElementTree.Element.__iter__
654676
xml.etree.cElementTree.Element.__iter__
655677
typing(_extensions)?\.IO\.__iter__ # See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3
656678

679+
xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature
680+
xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature
681+
657682
# Added or modified in a patch release, backported to all security branches,
658683
# but have yet to find their way to all GitHub Actions images
659684
(tarfile.tar_filter)?
@@ -681,17 +706,3 @@ typing(_extensions)?\.IO\.__iter__ # See https://github.com/python/typeshed/com
681706
enum.auto.__or__
682707
enum.auto.__and__
683708
enum.auto.__xor__
684-
685-
# wrapped with _check_name decorator which adds *args, **kwargs
686-
# we have more accurate signatures in the stubs
687-
_frozen_importlib_external.ExtensionFileLoader.get_filename
688-
_frozen_importlib_external.FileLoader.get_filename
689-
_frozen_importlib_external.FileLoader.get_resource_reader
690-
_frozen_importlib_external.FileLoader.load_module
691-
importlib._bootstrap_external.ExtensionFileLoader.get_filename
692-
importlib._bootstrap_external.FileLoader.get_filename
693-
importlib._bootstrap_external.FileLoader.get_resource_reader
694-
importlib._bootstrap_external.FileLoader.load_module
695-
importlib.abc.FileLoader.get_filename
696-
importlib.abc.FileLoader.load_module
697-
importlib.machinery.ExtensionFileLoader.get_filename

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ _collections_abc.MappingView.__class_getitem__
66
_csv.Reader
77
_csv.Writer
88
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
9-
configparser.LegacyInterpolation.__init__
109
configparser.ParsingError.filename
1110
collections\.UserList\.index # ignoring pos-or-keyword parameter
1211
enum.Enum.__init__
@@ -106,6 +105,8 @@ os.path.join
106105
# Allowlist entries that cannot or should not be fixed
107106
# ==========
108107

108+
configparser.LegacyInterpolation.__init__ # runtime is *args, **kwargs, but it's just a passthrough
109+
109110
# Factory function at runtime
110111
# but that wouldn't let us use it in type hints
111112
threading.Lock

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ _collections_abc.Iterable.__class_getitem__
99
_collections_abc.MappingView.__class_getitem__
1010
_csv.Reader
1111
_csv.Writer
12-
configparser.LegacyInterpolation.__init__
1312
enum.Enum.__init__
1413
importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility
1514
lib2to3.pygram.pattern_symbols
@@ -89,6 +88,8 @@ zoneinfo.ZoneInfo.from_file
8988
# Allowlist entries that cannot or should not be fixed
9089
# ==========
9190

91+
configparser.LegacyInterpolation.__init__ # runtime is *args, **kwargs, but it's just a passthrough
92+
9293
# Factory function at runtime
9394
# but that wouldn't let us use it in type hints
9495
threading.Lock

stdlib/_threading_local.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Any
2-
from typing_extensions import TypeAlias
2+
from typing_extensions import Self, TypeAlias
33
from weakref import ReferenceType
44

55
__all__ = ["local"]
@@ -12,6 +12,7 @@ class _localimpl:
1212
def create_dict(self) -> _LocalDict: ...
1313

1414
class local:
15+
def __new__(cls, /, *args: Any, **kw: Any) -> Self: ...
1516
def __getattribute__(self, name: str) -> Any: ...
1617
def __setattr__(self, name: str, value: Any) -> None: ...
1718
def __delattr__(self, name: str) -> None: ...

0 commit comments

Comments
 (0)