diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index fa1919af3579..6a40d3400c22 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -36,28 +36,18 @@ jobs: matrix: # tkinter doesn't import on macOS-12 os: ["ubuntu-latest", "windows-latest", "macos-11"] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] fail-fast: false steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} - if: ${{ matrix.os != 'macos-11' || matrix.python-version != '3.7' }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: requirements-tests.txt allow-prereleases: true - # Handle the py37 run on macos differently, - # to workaround https://github.com/actions/setup-python/issues/682 - - name: Setup Python 3.7.16 on macos - if: ${{ matrix.os == 'macos-11' && matrix.python-version == '3.7' }} - uses: actions/setup-python@v4 - with: - python-version: "3.7.16" - cache: pip - cache-dependency-path: requirements-tests.txt - name: Install dependencies run: pip install -r requirements-tests.txt - name: Run stubtest diff --git a/.github/workflows/stubtest_stdlib.yml b/.github/workflows/stubtest_stdlib.yml index b4ede529e6c0..ae38dcccaea1 100644 --- a/.github/workflows/stubtest_stdlib.yml +++ b/.github/workflows/stubtest_stdlib.yml @@ -32,28 +32,18 @@ jobs: matrix: # tkinter doesn't import on macOS 12 os: ["ubuntu-latest", "windows-latest", "macos-11"] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] fail-fast: false steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} - if: ${{ matrix.os != 'macos-11' || matrix.python-version != '3.7' }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: requirements-tests.txt allow-prereleases: true - # Handle the py37 run on macos differently, - # to workaround https://github.com/actions/setup-python/issues/682 - - name: Setup Python 3.7.16 on macos - if: ${{ matrix.os == 'macos-11' && matrix.python-version == '3.7' }} - uses: actions/setup-python@v4 - with: - python-version: "3.7.16" - cache: pip - cache-dependency-path: requirements-tests.txt - name: Install dependencies run: pip install -r requirements-tests.txt - name: Run stubtest diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a659ca9feb99..c86922bce00c 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.8", "3.9", "3.10", "3.11"] fail-fast: false steps: - uses: actions/checkout@v3 @@ -98,8 +98,7 @@ jobs: - run: python ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }} # Run mypy slightly differently on the py312 stubs, - # as mypyc doesn't work on Python 3.12 yet - # (and various non-types dependencies can't be installed on Python 3.12 yet) + # as at least one non-types dependency (greenlet) can't be installed on Python 3.12 yet mypy-312: name: Run mypy against the stubs (3.12) runs-on: ubuntu-latest diff --git a/.vscode/settings.default.json b/.vscode/settings.default.json index 83883dbc31b8..32bbd68a3924 100644 --- a/.vscode/settings.default.json +++ b/.vscode/settings.default.json @@ -97,11 +97,11 @@ "mypy-type-checker.importStrategy": "fromEnvironment", "mypy-type-checker.args": [ "--custom-typeshed-dir=${workspaceFolder}", - "--python-version=3.7", - "--strict" - // Needed because a library stubbed in typeshed won't necessarily be installed inthe dev's environment - // Currentyl broken in dmypy: https://github.com/python/mypy/issues/10709 - // "--ignore-missing-imports" + // We only guarantee all of our tests can be run if you're on Python 3.9 or higher + "--python-version=3.9", + "--strict", + // Needed because a library stubbed in typeshed won't necessarily be installed in the dev's environment + "--ignore-missing-imports" ], // Ensure typeshed's configs are used, and not user's VSCode settings "flake8.args": [ diff --git a/requirements-tests.txt b/requirements-tests.txt index de3e7a2aad8e..5a758df42fda 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -7,7 +7,7 @@ flake8-bugbear==23.7.10; python_version >= "3.8" # must match .pre-commit-confi flake8-noqa==1.3.2; python_version >= "3.8" # must match .pre-commit-config.yaml flake8-pyi==23.6.0; python_version >= "3.8" # must match .pre-commit-config.yaml isort==5.12.0; python_version >= "3.8" # must match .pre-commit-config.yaml -mypy==1.4.1 +mypy==1.5.1 pre-commit-hooks==4.4.0 # must match .pre-commit-config.yaml pytype==2023.8.14; platform_system != "Windows" and python_version >= "3.8" and python_version < "3.11" ruff==0.0.280 # must match .pre-commit-config.yaml diff --git a/test_cases/stdlib/check_dataclasses.py b/test_cases/stdlib/check_dataclasses.py index b06c4a9fff7c..2dabee6fdfe0 100644 --- a/test_cases/stdlib/check_dataclasses.py +++ b/test_cases/stdlib/check_dataclasses.py @@ -87,4 +87,9 @@ def check_other_isdataclass_overloads(x: type, y: object) -> None: assert_type(dc.fields(y), Tuple[dc.Field[Any], ...]) assert_type(dc.asdict(y), Dict[str, Any]) assert_type(dc.astuple(y), Tuple[Any, ...]) - dc.replace(y) + + # No longer passes with mypy 1.5.0 + # now that mypy gives a tailored signature for dataclasses.replace() + # (https://github.com/python/mypy/issues/15843): + # + # dc.replace(y) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 709ba0186468..3d10ad689466 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -12,7 +12,6 @@ import tempfile import time from collections import defaultdict -from collections.abc import Sequence from dataclasses import dataclass from itertools import product from pathlib import Path @@ -47,7 +46,7 @@ print_error("Cannot import mypy. Did you install it?") sys.exit(1) -SUPPORTED_VERSIONS = ["3.12", "3.11", "3.10", "3.9", "3.8", "3.7"] +SUPPORTED_VERSIONS = ["3.12", "3.11", "3.10", "3.9", "3.8"] SUPPORTED_PLATFORMS = ("linux", "win32", "darwin") DIRECTORIES_TO_TEST = [Path("stdlib"), Path("stubs")] @@ -86,21 +85,6 @@ def remove_dev_suffix(version: str) -> str: parser = argparse.ArgumentParser( description="Typecheck typeshed's stubs with mypy. Patterns are unanchored regexps on the full path." ) -if sys.version_info < (3, 8): - - class ExtendAction(argparse.Action): - def __call__( - self, - parser: argparse.ArgumentParser, - namespace: argparse.Namespace, - values: Sequence[str], - option_string: object = None, - ) -> None: - items = getattr(namespace, self.dest) or [] - items.extend(values) - setattr(namespace, self.dest, items) - - parser.register("action", "extend", ExtendAction) parser.add_argument( "filter", type=valid_path, diff --git a/tests/stubtest_allowlists/darwin-py37.txt b/tests/stubtest_allowlists/darwin-py37.txt deleted file mode 100644 index 1237f3ac9f0d..000000000000 --- a/tests/stubtest_allowlists/darwin-py37.txt +++ /dev/null @@ -1,8 +0,0 @@ -ctypes.wintypes -pwd.getpwnam - -# ========== -# Allowlist entries that cannot or should not be fixed -# ========== - -ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 diff --git a/tests/stubtest_allowlists/linux-py37.txt b/tests/stubtest_allowlists/linux-py37.txt deleted file mode 100644 index 1237f3ac9f0d..000000000000 --- a/tests/stubtest_allowlists/linux-py37.txt +++ /dev/null @@ -1,8 +0,0 @@ -ctypes.wintypes -pwd.getpwnam - -# ========== -# Allowlist entries that cannot or should not be fixed -# ========== - -ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt deleted file mode 100644 index 3a7413858aed..000000000000 --- a/tests/stubtest_allowlists/py37.txt +++ /dev/null @@ -1,186 +0,0 @@ -_collections_abc.AsyncGenerator.ag_await -_collections_abc.AsyncGenerator.ag_code -_collections_abc.AsyncGenerator.ag_frame -_collections_abc.AsyncGenerator.ag_running -_dummy_threading -asyncio.AbstractEventLoop.run_in_executor # allowed to return a Future, changed in 3.8 -asyncio.events.AbstractEventLoop.run_in_executor # allowed to return a Future, changed in 3.8 -asyncio.Future.__init__ # Usually initialized from c object -asyncio.futures.Future.__init__ # Usually initialized from c object -asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub -asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub -asyncio.transports.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself -asyncio.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself -builtins.float.__set_format__ # Internal method for CPython test suite -builtins.str.maketrans -builtins.input # Incorrect default value in text signature, fixed in 3.10 -bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set -cmath.log -collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. -collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 -collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 -collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 -collections.AsyncGenerator.ag_await -collections.AsyncGenerator.ag_code -collections.AsyncGenerator.ag_frame -collections.AsyncGenerator.ag_running -collections.ByteString # see comments in py3_common.txt -collections.Callable -collections.Mapping.__reversed__ # Set to None at runtime for a better error message -configparser.ParsingError.filename -contextvars.ContextVar.get -dummy_threading.Condition.acquire -dummy_threading.Condition.release -dummy_threading.Event.isSet -dummy_threading.local.__new__ -enum.Enum._generate_next_value_ -fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve -importlib.abc.Finder.find_module -inspect.Signature.from_builtin # Removed in 3.11, can add if someone needs this -inspect.Signature.from_function # Removed in 3.11, can add if someone needs this -ipaddress._BaseNetwork.__init__ -json.loads -(os|posix).utime -random.Random.randrange # missing undocumented arg _int -sched.Event.__doc__ # __slots__ is overridden -typing.NamedTuple._asdict -typing.NamedTuple._make -typing.NamedTuple._replace -typing._SpecialForm.__new__ -typing.runtime_checkable -uuid.UUID.int -uuid.UUID.is_safe -xml.etree.ElementTree.TreeBuilder.start # Discrepancy between Python and C modules, fixed in bpo-39495 -xml.etree.cElementTree.TreeBuilder.start # bpo-39495 -typing_extensions\.get_original_bases - -# Exist at runtime for internal reasons, no need to put them in the stub -typing_extensions\.TypeAliasType\.__call__ -typing_extensions\.TypeAliasType\.__init_subclass__ -# We call them read-only properties, runtime implementation is slightly different -typing_extensions\.TypeAliasType\.__(parameters|type_params|name|module|value)__ - -collections.Coroutine.cr_await -collections.Coroutine.cr_code -collections.Coroutine.cr_frame -collections.Coroutine.cr_running -collections.Generator.gi_code -collections.Generator.gi_frame -collections.Generator.gi_running -collections.Generator.gi_yieldfrom -collections.Mapping.get # Adding None to the Union messed up mypy -collections.Sequence.index # Supporting None in end is not mandatory - -# SpooledTemporaryFile implements IO except these methods before Python 3.11 -# See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918 -tempfile.SpooledTemporaryFile.__next__ -tempfile.SpooledTemporaryFile.readable -tempfile.SpooledTemporaryFile.seekable -tempfile.SpooledTemporaryFile.writable - -# Default values given in the stub are a white lie, see #9637 -tkinter.Tcl -tkinter.Tk.__init__ - -# Exists at runtime, but missing from stubs -contextvars.ContextVar.__class_getitem__ -datetime.datetime_CAPI -dummy_threading.Lock -dummy_threading.RLock -html.parser.HTMLParser.unescape -platform.popen -plistlib.Data.asBase64 -plistlib.Data.fromBase64 -ssl.OP_ENABLE_MIDDLEBOX_COMPAT -ssl.Options.OP_ENABLE_MIDDLEBOX_COMPAT -ssl.SSLObject.verify_client_post_handshake -ssl.SSLSocket.verify_client_post_handshake -tempfile.SpooledTemporaryFile.softspace -tkinter.Tk.split -tkinter.commondialog.[A-Z_]+ -tkinter.commondialog.TclVersion -tkinter.commondialog.TkVersion -tkinter.commondialog.wantobjects -tkinter.dialog.[A-Z_]+ -tkinter.dialog.TclVersion -tkinter.dialog.TkVersion -tkinter.dialog.wantobjects -tkinter.dnd.Icon -tkinter.dnd.Tester -tkinter.dnd.test -tkinter.filedialog.[A-Z_]+ -tkinter.filedialog.TclVersion -tkinter.filedialog.TkVersion -tkinter.filedialog.wantobjects -tkinter.simpledialog.wantobjects -tkinter.tix.wantobjects - -# ========== -# Allowlist entries that cannot or should not be fixed -# ========== - -# Side effects from module initialization -_compat_pickle.excname -email.contentmanager.maintype -email.contentmanager.subtype -inspect.k -inspect.mod_dict -inspect.v -json.encoder.i -lib2to3.pgen2.grammar.line -lib2to3.pgen2.grammar.name -lib2to3.pgen2.grammar.op -pydoc.Helper.symbol # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 -pydoc.Helper.symbols_ # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 -pydoc.Helper.topic # Loop variable in class https://github.com/python/typeshed/issues/6401#issuecomment-981178522 - -# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. -collections.Set.__rand__ -collections.Set.__ror__ -collections.Set.__rsub__ -collections.Set.__rxor__ - -builtins.memoryview.__iter__ # C type that implements __getitem__ -builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only - -# C signature is broader than what is actually accepted -queue.SimpleQueue.__init__ - -pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args -xml.parsers.expat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args -pyexpat.XMLParserType.intern # does exist but stubtest can't see it (https://github.com/python/cpython/blob/3.7/Modules/pyexpat.c#L1322) -xml.parsers.expat.XMLParserType.intern # does exist but stubtest can't see it (https://github.com/python/cpython/blob/3.7/Modules/pyexpat.c#L1322) - -# Runtime signature is incorrect (https://github.com/python/cpython/issues/93021) -builtins.classmethod.__get__ -builtins.property.__get__ -builtins.staticmethod.__get__ -types.FunctionType.__get__ -types.LambdaType.__get__ -types.ClassMethodDescriptorType.__get__ -types.GetSetDescriptorType.__get__ -types.MemberDescriptorType.__get__ -types.MethodDescriptorType.__get__ -types.WrapperDescriptorType.__get__ - -# https://github.com/python/mypy/issues/15302 -typing_extensions\.assert_never -typing_extensions\.assert_type -typing_extensions\.reveal_type - -# Doesn't exist at runtime -typing\.Protocol - -# We lie about the existence of these methods -.*.__buffer__ -.*.__release_buffer__ - -# Removed in 3.12 -distutils\..* -asyncore.dispatcher.addr -asyncore.dispatcher.handle_accepted -asynchat.async_chat.encoding -asynchat.async_chat.use_encoding -asynchat.find_prefix_at_end -pkgutil.ImpImporter\..* -pkgutil.ImpLoader\..* diff --git a/tests/stubtest_allowlists/win32-py37.txt b/tests/stubtest_allowlists/win32-py37.txt deleted file mode 100644 index 05db77c1edb9..000000000000 --- a/tests/stubtest_allowlists/win32-py37.txt +++ /dev/null @@ -1,20 +0,0 @@ - # The following methods were changed in point releases from Python 3.6 to 3.9 - # as part of a security fix. These excludes can be removed when the GitHub - # action workflow uses Python versions that include the fix (adding a - # separator argument). -cgi.FieldStorage.__init__ -cgi.parse -cgi.parse_multipart -urllib.parse.parse_qs -urllib.parse.parse_qsl - -# ========== -# Allowlist entries that cannot or should not be fixed -# ========== - -# pathlib methods that exist on Windows, but always raise NotImplementedError, -# so are omitted from the stub -pathlib.Path.is_mount -pathlib.WindowsPath.group -pathlib.WindowsPath.owner -pathlib.WindowsPath.is_mount diff --git a/tests/utils.py b/tests/utils.py index 11a590327fc4..dd5243a5905c 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -23,7 +23,7 @@ def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type: # A backport of functools.cache for Python <3.9 -# This module is imported by mypy_test.py, which needs to run on 3.7 in CI +# This module is imported by mypy_test.py, which needs to run on 3.8 in CI cache = lru_cache(None)