Skip to content

Commit

Permalink
move various cases of 'stub does not have *args argument' to "don't f…
Browse files Browse the repository at this point in the history
…ix" (#12956)
  • Loading branch information
tungol authored Nov 5, 2024
1 parent f314631 commit 7b68c81
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
75 changes: 43 additions & 32 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -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

# ==========
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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__
Expand All @@ -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`
Expand Down Expand Up @@ -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__
Expand All @@ -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)?
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion stdlib/@tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion stdlib/_threading_local.pyi
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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: ...

0 comments on commit 7b68c81

Please sign in to comment.