From 5cb59ec3d40a7f73157296bec79d8bf6876e48d7 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 21 Dec 2023 22:07:05 +0000 Subject: [PATCH 1/5] Bump various test dependencies --- .github/workflows/tests.yml | 2 +- .pre-commit-config.yaml | 4 ++-- requirements-tests.txt | 6 +++--- tests/stubtest_allowlists/py3_common.txt | 5 +---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5b33a3d4dc35..fb7b893d4d7f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,7 +52,7 @@ jobs: - uses: actions/checkout@v4 - uses: chartboost/ruff-action@v1 with: - version: "0.1.7" # must match .pre-commit-config.yaml and requirements-test.txt + version: "0.1.9" # must match .pre-commit-config.yaml and requirements-test.txt flake8: name: Lint with Flake8 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1a35c2dc2fcf..8444c043d09c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,12 +10,12 @@ repos: - id: mixed-line-ending - id: check-case-conflict - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.11.0 # must match requirements-tests.txt + rev: 23.12.0 # must match requirements-tests.txt hooks: - id: black language_version: python3.10 - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 # must match requirements-tests.txt and tests.yml + rev: v0.1.9 # must match requirements-tests.txt and tests.yml hooks: - id: ruff args: [--exit-non-zero-on-fix, --fix-only] diff --git a/requirements-tests.txt b/requirements-tests.txt index 894cfcfa2cd6..2e62c3d6825a 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,15 +1,15 @@ # Type checkers and other linters that we test our stubs against. These should always # be pinned to a specific version to make failure reproducible. See also the # "tool.typeshed" section in pyproject.toml for additional type checkers. -black==23.11.0 # must match .pre-commit-config.yaml +black==23.12.0 # must match .pre-commit-config.yaml flake8==6.1.0 # must match .pre-commit-config.yaml flake8-bugbear==23.12.2 # must match .pre-commit-config.yaml flake8-noqa==1.3.2 # must match .pre-commit-config.yaml flake8-pyi==23.11.0 # must match .pre-commit-config.yaml -mypy==1.7.1 +mypy==1.8.0 pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml pytype==2023.12.8; platform_system != "Windows" and python_version < "3.12" -ruff==0.1.7 # must match .pre-commit-config.yaml and tests.yml +ruff==0.1.9 # must match .pre-commit-config.yaml and tests.yml # Libraries used by our various scripts. aiohttp==3.9.1 diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index c79bcacd6565..a2c35ace84a9 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -25,7 +25,6 @@ asyncio.Future.__init__ # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object builtins.dict.get builtins.ellipsis # type is not exposed anywhere -builtins.function collections.ChainMap.fromkeys # Runtime has *args which can really only be one argument 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 @@ -479,8 +478,7 @@ typing_extensions\.TypeVar.* typing_extensions\.ParamSpec.* typing(_extensions)?\.Generic typing\.Protocol -(typing\._TypedDict\..+)? -typing_extensions\._TypedDict\..* +typing(_extensions)?\._TypedDict # Special primitives typing_extensions\.Annotated @@ -513,7 +511,6 @@ typing(_extensions)?\.Coroutine typing(_extensions)?\.Collection typing(_extensions)?\.Container typing\.ByteString -typing(_extensions)?\.AwaitableGenerator typing(_extensions)?\.Awaitable typing(_extensions)?\.AbstractSet From 087b34a54f9c5094664d1331638c1eb3f68e5280 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 21 Dec 2023 22:11:01 +0000 Subject: [PATCH 2/5] . --- stdlib/asyncore.pyi | 1 + tests/stubtest_allowlists/py310.txt | 1 + tests/stubtest_allowlists/py311.txt | 1 + tests/stubtest_allowlists/py312.txt | 1 + tests/stubtest_allowlists/py3_common.txt | 1 - 5 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/asyncore.pyi b/stdlib/asyncore.pyi index 47c8e2207022..36d1862fdda7 100644 --- a/stdlib/asyncore.pyi +++ b/stdlib/asyncore.pyi @@ -83,6 +83,7 @@ if sys.platform != "win32": def write(self, data: bytes, flags: int = ...) -> int: ... def close(self) -> None: ... def fileno(self) -> int: ... + def __del__(self) -> None: ... class file_dispatcher(dispatcher): def __init__(self, fd: FileDescriptorLike, map: _MapType | None = None) -> None: ... diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index df8d27d8b74c..ec360ac265bf 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -24,6 +24,7 @@ types.GenericAlias.__mro_entries__ types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392 typing._SpecialForm.__mro_entries__ weakref.ProxyType.__reversed__ # Doesn't really exist +builtins.ellipsis # type is not exposed anywhere # Modules that exist at runtime, but shouldn't be added to typeshed ctypes.test diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 509e68adf967..20fc8de56fae 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -16,6 +16,7 @@ importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined importlib.abc.Finder.find_module tkinter._VersionInfoType.__doc__ typing.NewType.__mro_entries__ +builtins.ellipsis # type is not exposed anywhere # Modules that exist at runtime, but shouldn't be added to typeshed ctypes.test diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index 8847ee424b51..bd2dcbf198cf 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -14,6 +14,7 @@ enum.Enum.__init__ importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility tkinter._VersionInfoType.__doc__ typing.NewType.__mro_entries__ +builtins.ellipsis # type is not exposed anywhere # ========== # Related to positional-only arguments diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index a2c35ace84a9..495e42c6fbbe 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -24,7 +24,6 @@ asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several p asyncio.Future.__init__ # Usually initialized from c object asyncio.futures.Future.__init__ # Usually initialized from c object builtins.dict.get -builtins.ellipsis # type is not exposed anywhere collections.ChainMap.fromkeys # Runtime has *args which can really only be one argument 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 From 490b59fd42621acd3e75e4903691b0fef0098e3e Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 21 Dec 2023 22:34:27 +0000 Subject: [PATCH 3/5] Try to fix the third-party errors --- stubs/pyasn1/@tests/stubtest_allowlist.txt | 3 --- stubs/pynput/pynput/keyboard/_base.pyi | 3 +++ stubs/pynput/pynput/mouse/_base.pyi | 2 ++ stubs/python-xlib/@tests/stubtest_allowlist.txt | 3 --- stubs/python-xlib/Xlib/protocol/rq.pyi | 1 - 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/stubs/pyasn1/@tests/stubtest_allowlist.txt b/stubs/pyasn1/@tests/stubtest_allowlist.txt index a4f02448ed6d..5028c70108e2 100644 --- a/stubs/pyasn1/@tests/stubtest_allowlist.txt +++ b/stubs/pyasn1/@tests/stubtest_allowlist.txt @@ -1,6 +1,3 @@ -# type_check_only -pyasn1.type.base.NoValue.plug - # typeshed typing differences with runtime collections.OrderedDict and builtins.dict pyasn1.codec.native.encoder.SequenceEncoder.protoDict pyasn1.codec.native.encoder.SetEncoder.protoDict diff --git a/stubs/pynput/pynput/keyboard/_base.pyi b/stubs/pynput/pynput/keyboard/_base.pyi index 692af81ef482..42bd81212223 100644 --- a/stubs/pynput/pynput/keyboard/_base.pyi +++ b/stubs/pynput/pynput/keyboard/_base.pyi @@ -121,6 +121,9 @@ class Controller: @property def shift_pressed(self) -> bool: ... + if sys.platform == "linux": + def __del__(self) -> None: ... + class Listener(AbstractListener): def __init__( self, diff --git a/stubs/pynput/pynput/mouse/_base.pyi b/stubs/pynput/pynput/mouse/_base.pyi index 10141121b1d7..39294216a610 100644 --- a/stubs/pynput/pynput/mouse/_base.pyi +++ b/stubs/pynput/pynput/mouse/_base.pyi @@ -59,6 +59,8 @@ class Controller: def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... + if sys.platform == "linux": + def __del__(self) -> None: ... class Listener(AbstractListener): if sys.platform == "win32": diff --git a/stubs/python-xlib/@tests/stubtest_allowlist.txt b/stubs/python-xlib/@tests/stubtest_allowlist.txt index 1809e171e038..2fec5b0c782c 100644 --- a/stubs/python-xlib/@tests/stubtest_allowlist.txt +++ b/stubs/python-xlib/@tests/stubtest_allowlist.txt @@ -17,9 +17,6 @@ Xlib.protocol.rq.*.structcode # Should only ever be str once instantiated Xlib.protocol.rq.*.name -# Structs generate their attributes (@type_check_only) -Xlib.protocol.rq.Struct.__getattr__ - # Iteration variable that bleeds into the global scope Xlib.protocol.rq.c Xlib.protocol.rq.size diff --git a/stubs/python-xlib/Xlib/protocol/rq.pyi b/stubs/python-xlib/Xlib/protocol/rq.pyi index f9ec0f45650c..871afc9d4529 100644 --- a/stubs/python-xlib/Xlib/protocol/rq.pyi +++ b/stubs/python-xlib/Xlib/protocol/rq.pyi @@ -365,7 +365,6 @@ class GetAttrData: # GetAttrData classes get their attributes dynamically # TODO: Complete all classes inheriting from GetAttrData def __getattr__(self, attr: str) -> Any: ... - @type_check_only def __setattr__(self, __name: str, __value: Any) -> None: ... class DictWrapper(GetAttrData): From a16c38b84dbf94a4679fc2ce7ef70252733464d1 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 21 Dec 2023 22:41:07 +0000 Subject: [PATCH 4/5] ok --- stubs/pynput/@tests/stubtest_allowlist.txt | 6 ++++++ stubs/pynput/pynput/keyboard/_base.pyi | 3 --- stubs/pynput/pynput/mouse/_base.pyi | 2 -- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/stubs/pynput/@tests/stubtest_allowlist.txt b/stubs/pynput/@tests/stubtest_allowlist.txt index 0fa0e5d5a8c8..dcfb0d75b69a 100644 --- a/stubs/pynput/@tests/stubtest_allowlist.txt +++ b/stubs/pynput/@tests/stubtest_allowlist.txt @@ -1,6 +1,12 @@ # These __init__ methods have *args, **kwargs arguments on some platforms, but not others pynput.mouse.Controller.__init__ +# To reduce duplication, our stubs simplify things: +# the runtime has several Controller classes, +# some of which have __del__ methods and some of which don't. +pynput.mouse.Controller.__del__ +pynput.keyboard.Controller.__del__ + # stubtest issues with non-`type` metaclasses, see https://github.com/python/mypy/issues/13316 pynput.keyboard.Controller._Key pynput.keyboard._base.Controller._Key diff --git a/stubs/pynput/pynput/keyboard/_base.pyi b/stubs/pynput/pynput/keyboard/_base.pyi index 42bd81212223..692af81ef482 100644 --- a/stubs/pynput/pynput/keyboard/_base.pyi +++ b/stubs/pynput/pynput/keyboard/_base.pyi @@ -121,9 +121,6 @@ class Controller: @property def shift_pressed(self) -> bool: ... - if sys.platform == "linux": - def __del__(self) -> None: ... - class Listener(AbstractListener): def __init__( self, diff --git a/stubs/pynput/pynput/mouse/_base.pyi b/stubs/pynput/pynput/mouse/_base.pyi index 39294216a610..10141121b1d7 100644 --- a/stubs/pynput/pynput/mouse/_base.pyi +++ b/stubs/pynput/pynput/mouse/_base.pyi @@ -59,8 +59,6 @@ class Controller: def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... - if sys.platform == "linux": - def __del__(self) -> None: ... class Listener(AbstractListener): if sys.platform == "win32": From f96c7b93250c127aa626e7e1474113b99b459150 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 21 Dec 2023 22:45:30 +0000 Subject: [PATCH 5/5] gimme a break --- stubs/pynput/@tests/stubtest_allowlist.txt | 6 ------ stubs/pynput/@tests/stubtest_allowlist_linux.txt | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stubs/pynput/@tests/stubtest_allowlist.txt b/stubs/pynput/@tests/stubtest_allowlist.txt index dcfb0d75b69a..0fa0e5d5a8c8 100644 --- a/stubs/pynput/@tests/stubtest_allowlist.txt +++ b/stubs/pynput/@tests/stubtest_allowlist.txt @@ -1,12 +1,6 @@ # These __init__ methods have *args, **kwargs arguments on some platforms, but not others pynput.mouse.Controller.__init__ -# To reduce duplication, our stubs simplify things: -# the runtime has several Controller classes, -# some of which have __del__ methods and some of which don't. -pynput.mouse.Controller.__del__ -pynput.keyboard.Controller.__del__ - # stubtest issues with non-`type` metaclasses, see https://github.com/python/mypy/issues/13316 pynput.keyboard.Controller._Key pynput.keyboard._base.Controller._Key diff --git a/stubs/pynput/@tests/stubtest_allowlist_linux.txt b/stubs/pynput/@tests/stubtest_allowlist_linux.txt index 6a32bbd42136..ff54e4166252 100644 --- a/stubs/pynput/@tests/stubtest_allowlist_linux.txt +++ b/stubs/pynput/@tests/stubtest_allowlist_linux.txt @@ -1,5 +1,11 @@ # These __init__ methods have *args, **kwargs arguments on some platforms, but not others pynput.keyboard.Controller.__init__ +# To reduce duplication, our stubs simplify things: +# the runtime has several Controller classes, +# some of which have __del__ methods on linux, and some of which don't. +pynput.mouse.Controller.__del__ +pynput.keyboard.Controller.__del__ + # Platform specific implementation detail: pynput.keyboard.Controller.keyboard_mapping