From 2c3449694b7f3c545b616f5d489a1cfbff6e3f0b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 30 Apr 2023 15:31:08 +0100 Subject: [PATCH] Run mypy and pyright on our py312 stubs in CI (#10119) --- .github/workflows/tests.yml | 4 ++-- requirements-tests.txt | 2 +- stdlib/configparser.pyi | 4 +++- stdlib/itertools.pyi | 2 +- tests/mypy_test.py | 11 +++++++++-- tests/regr_test.py | 2 +- tests/typecheck_typeshed.py | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b5911cfd..305c2e35d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,7 +85,7 @@ jobs: strategy: matrix: platform: ["linux", "win32", "darwin"] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] fail-fast: false steps: - uses: actions/checkout@v3 @@ -116,7 +116,7 @@ jobs: strategy: matrix: python-platform: ["Linux", "Windows", "Darwin"] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] fail-fast: false steps: - uses: actions/checkout@v3 diff --git a/requirements-tests.txt b/requirements-tests.txt index f08f60bec..8a233763d 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,4 +1,4 @@ -aiohttp==3.8.4 +aiohttp==3.8.4; python_version < "3.12" # aiohttp can't be installed on 3.12 yet black==23.3.0 # must match .pre-commit-config.yaml flake8==6.0.0; python_version >= "3.8" # must match .pre-commit-config.yaml flake8-bugbear==23.3.23; python_version >= "3.8" # must match .pre-commit-config.yaml diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 92931a89b..6f9f78831 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -17,7 +17,6 @@ __all__ = [ "ParsingError", "MissingSectionHeaderError", "ConfigParser", - "SafeConfigParser", "RawConfigParser", "Interpolation", "BasicInterpolation", @@ -29,6 +28,9 @@ __all__ = [ "MAX_INTERPOLATION_DEPTH", ] +if sys.version_info < (3, 12): + __all__ += ["SafeConfigParser"] + _Section: TypeAlias = Mapping[str, str] _Parser: TypeAlias = MutableMapping[str, _Section] _ConverterCallback: TypeAlias = Callable[[str], Any] diff --git a/stdlib/itertools.pyi b/stdlib/itertools.pyi index c7b92c3ae..4b5d624c7 100644 --- a/stdlib/itertools.pyi +++ b/stdlib/itertools.pyi @@ -272,7 +272,7 @@ if sys.version_info >= (3, 10): def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): - class batched(Iterator[_T_co], Generic[_T_co]): + class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]): def __new__(cls, iterable: Iterable[_T_co], n: int) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T_co, ...]: ... diff --git a/tests/mypy_test.py b/tests/mypy_test.py index b812731da..709ba0186 100644 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -47,7 +47,7 @@ except ImportError: print_error("Cannot import mypy. Did you install it?") sys.exit(1) -SUPPORTED_VERSIONS = ["3.11", "3.10", "3.9", "3.8", "3.7"] +SUPPORTED_VERSIONS = ["3.12", "3.11", "3.10", "3.9", "3.8", "3.7"] SUPPORTED_PLATFORMS = ("linux", "win32", "darwin") DIRECTORIES_TO_TEST = [Path("stdlib"), Path("stubs")] @@ -76,6 +76,13 @@ def valid_path(cmd_arg: str) -> Path: return path +def remove_dev_suffix(version: str) -> str: + """Helper function for argument-parsing""" + if version.endswith("-dev"): + return version[: -len("-dev")] + return version + + parser = argparse.ArgumentParser( description="Typecheck typeshed's stubs with mypy. Patterns are unanchored regexps on the full path." ) @@ -105,7 +112,7 @@ parser.add_argument("-v", "--verbose", action="count", default=0, help="More out parser.add_argument( "-p", "--python-version", - type=str, + type=remove_dev_suffix, choices=SUPPORTED_VERSIONS, nargs="*", action="extend", diff --git a/tests/regr_test.py b/tests/regr_test.py index bbb3d0e44..6746b2bc7 100644 --- a/tests/regr_test.py +++ b/tests/regr_test.py @@ -35,7 +35,7 @@ VENV_DIR = ".venv" TYPESHED = "typeshed" SUPPORTED_PLATFORMS = ["linux", "darwin", "win32"] -SUPPORTED_VERSIONS = ["3.11", "3.10", "3.9", "3.8", "3.7"] +SUPPORTED_VERSIONS = ["3.12", "3.11", "3.10", "3.9", "3.8", "3.7"] def package_with_test_cases(package_name: str) -> PackageInfo: diff --git a/tests/typecheck_typeshed.py b/tests/typecheck_typeshed.py index 1423d515f..5d5de981e 100644 --- a/tests/typecheck_typeshed.py +++ b/tests/typecheck_typeshed.py @@ -13,7 +13,7 @@ from utils import colored, print_error ReturnCode: TypeAlias = int SUPPORTED_PLATFORMS = ("linux", "darwin", "win32") -SUPPORTED_VERSIONS = ("3.11", "3.10", "3.9") +SUPPORTED_VERSIONS = ("3.12", "3.11", "3.10", "3.9") LOWEST_SUPPORTED_VERSION = min(SUPPORTED_VERSIONS, key=lambda x: int(x.split(".")[1])) DIRECTORIES_TO_TEST = ("scripts", "tests") EMPTY: list[str] = []