From aa3b78350ba76baab994c1d5b54af5ac14b5380f Mon Sep 17 00:00:00 2001 From: KotlinIsland <65446343+kotlinisland@users.noreply.github.com> Date: Mon, 22 Sep 2025 18:31:33 +1000 Subject: [PATCH 1/2] fix `collections.abc.Callable` and `typing.Callable` --- .../@tests/test_cases/check_collections_abc.py | 17 +++++++++++++++++ stdlib/_collections_abc.pyi | 14 ++++++++++++-- stdlib/typing.pyi | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 stdlib/@tests/test_cases/check_collections_abc.py diff --git a/stdlib/@tests/test_cases/check_collections_abc.py b/stdlib/@tests/test_cases/check_collections_abc.py new file mode 100644 index 000000000000..9a1e43c219fb --- /dev/null +++ b/stdlib/@tests/test_cases/check_collections_abc.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +from collections.abc import Callable +from typing_extensions import assert_type + +assert_type(Callable[[], None], type[Callable[[], None]]) + + +def f(c: Callable[[], None]) -> None: + assert_type(c.__call__, Callable[[], None]) + + +class C(Callable[[], None]): + def __call__(self) -> None: ... + + +isinstance(C(), Callable) diff --git a/stdlib/_collections_abc.pyi b/stdlib/_collections_abc.pyi index 0fa81662dfbc..9ff0eebc6379 100644 --- a/stdlib/_collections_abc.pyi +++ b/stdlib/_collections_abc.pyi @@ -1,5 +1,5 @@ import sys -from abc import abstractmethod +from abc import ABCMeta, abstractmethod from types import MappingProxyType from typing import ( # noqa: Y022,Y038,UP035,Y057,RUF100 AbstractSet as Set, @@ -8,7 +8,6 @@ from typing import ( # noqa: Y022,Y038,UP035,Y057,RUF100 AsyncIterator as AsyncIterator, Awaitable as Awaitable, ByteString as ByteString, - Callable as Callable, ClassVar, Collection as Collection, Container as Container, @@ -25,6 +24,7 @@ from typing import ( # noqa: Y022,Y038,UP035,Y057,RUF100 MutableMapping as MutableMapping, MutableSequence as MutableSequence, MutableSet as MutableSet, + ParamSpec, Protocol, Reversible as Reversible, Sequence as Sequence, @@ -68,6 +68,16 @@ if sys.version_info >= (3, 12): _KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers. _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers. +_R_co = TypeVar("_R_co", covariant=True) # return type for Callable +_P = ParamSpec("_P") + +@runtime_checkable +class Callable(Protocol[_P, _R_co], metaclass=ABCMeta): + __slots__ = () + + @abstractmethod + def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ... + @final class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented def __eq__(self, value: object, /) -> bool: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index af1d1650da41..69285b39f2bf 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -233,7 +233,6 @@ class _SpecialForm(_Final): Union: _SpecialForm Protocol: _SpecialForm -Callable: _SpecialForm Type: _SpecialForm NoReturn: _SpecialForm ClassVar: _SpecialForm @@ -427,6 +426,7 @@ class _Alias: # Class for defining generic aliases for library types. def __getitem__(self, typeargs: Any) -> Any: ... +Callable = _Alias() List = _Alias() Dict = _Alias() DefaultDict = _Alias() From 84a101f96dcd6c1071b5bd66d07dda805dece4ad Mon Sep 17 00:00:00 2001 From: KotlinIsland <65446343+kotlinisland@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:19:40 +1000 Subject: [PATCH 2/2] DONT MERGE: only run tests in ci --- .github/workflows/tests.yml | 84 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f00b63ab0db0..edf123be132f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,33 +36,33 @@ jobs: - run: uv pip install -r requirements-tests.txt --system - run: python ./tests/check_typeshed_structure.py - mypy: - name: "mypy: Check stubs" - runs-on: ubuntu-latest - strategy: - matrix: - platform: ["linux", "win32", "darwin"] - python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] - fail-fast: false - steps: - - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - - uses: astral-sh/setup-uv@v7 - with: - version-file: "requirements-tests.txt" - - run: uv pip install -r requirements-tests.txt --system - - name: Install required APT packages - run: | - PACKAGES=$(python tests/get_stubtest_system_requirements.py) - if [ -n "$PACKAGES" ]; then - printf "Installing APT packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n" - sudo apt-get update -q && sudo apt-get install -qy $PACKAGES - fi - - name: Run mypy_test.py - run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} +# mypy: +# name: "mypy: Check stubs" +# runs-on: ubuntu-latest +# strategy: +# matrix: +# platform: ["linux", "win32", "darwin"] +# python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] +# fail-fast: false +# steps: +# - uses: actions/checkout@v6 +# - uses: actions/setup-python@v6 +# with: +# python-version: ${{ matrix.python-version }} +# allow-prereleases: true +# - uses: astral-sh/setup-uv@v7 +# with: +# version-file: "requirements-tests.txt" +# - run: uv pip install -r requirements-tests.txt --system +# - name: Install required APT packages +# run: | +# PACKAGES=$(python tests/get_stubtest_system_requirements.py) +# if [ -n "$PACKAGES" ]; then +# printf "Installing APT packages:\n $(echo $PACKAGES | sed 's/ /\n /g')\n" +# sudo apt-get update -q && sudo apt-get install -qy $PACKAGES +# fi +# - name: Run mypy_test.py +# run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} regression-tests: name: "mypy: Run test cases" @@ -117,21 +117,21 @@ jobs: run: echo "$PWD/.venv/bin" >> $GITHUB_PATH - name: List 3rd-party stub dependencies installed run: uv pip freeze - - name: Run pyright with basic settings on all the stubs - uses: jakebailey/pyright-action@v2 - with: - version: PATH - python-platform: ${{ matrix.python-platform }} - python-version: ${{ matrix.python-version }} - annotate: ${{ matrix.python-version == '3.13' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. - - name: Run pyright with stricter settings on some of the stubs - uses: jakebailey/pyright-action@v2 - with: - version: PATH - python-platform: ${{ matrix.python-platform }} - python-version: ${{ matrix.python-version }} - annotate: ${{ matrix.python-version == '3.13' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. - project: ./pyrightconfig.stricter.json +# - name: Run pyright with basic settings on all the stubs +# uses: jakebailey/pyright-action@v2 +# with: +# version: PATH +# python-platform: ${{ matrix.python-platform }} +# python-version: ${{ matrix.python-version }} +# annotate: ${{ matrix.python-version == '3.13' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. +# - name: Run pyright with stricter settings on some of the stubs +# uses: jakebailey/pyright-action@v2 +# with: +# version: PATH +# python-platform: ${{ matrix.python-platform }} +# python-version: ${{ matrix.python-version }} +# annotate: ${{ matrix.python-version == '3.13' && matrix.python-platform == 'Linux' }} # Having each job create the same comment is too noisy. +# project: ./pyrightconfig.stricter.json - name: Run pyright on the test cases uses: jakebailey/pyright-action@v2 with: