From b4b4449477da7e8ae081ae7351cab146c663408a Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 17 Oct 2024 00:45:59 -0700 Subject: [PATCH] Upgrade to mypy 1.12.1 --- .pre-commit-config.yaml | 2 +- news/10EC0CC0-C535-4B04-8924-CBF3DAA3315D.trivial.rst | 0 src/pip/_internal/cli/parser.py | 4 ++-- src/pip/_internal/cli/progress_bars.py | 2 +- src/pip/_internal/locations/_distutils.py | 6 +++--- src/pip/_internal/network/lazy_wheel.py | 2 +- src/pip/_internal/utils/misc.py | 7 +------ tests/lib/test_wheel.py | 2 +- tests/lib/wheel.py | 2 +- 9 files changed, 11 insertions(+), 16 deletions(-) create mode 100644 news/10EC0CC0-C535-4B04-8924-CBF3DAA3315D.trivial.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27816138007..3a0319c2356 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.0 + rev: v1.12.1 hooks: - id: mypy exclude: tests/data diff --git a/news/10EC0CC0-C535-4B04-8924-CBF3DAA3315D.trivial.rst b/news/10EC0CC0-C535-4B04-8924-CBF3DAA3315D.trivial.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/cli/parser.py b/src/pip/_internal/cli/parser.py index b7d7c1f600a..bc4aca032d4 100644 --- a/src/pip/_internal/cli/parser.py +++ b/src/pip/_internal/cli/parser.py @@ -6,7 +6,7 @@ import sys import textwrap from contextlib import suppress -from typing import Any, Dict, Generator, List, Optional, Tuple +from typing import Any, Dict, Generator, List, NoReturn, Optional, Tuple from pip._internal.cli.status_codes import UNKNOWN_ERROR from pip._internal.configuration import Configuration, ConfigurationError @@ -289,6 +289,6 @@ def get_default_values(self) -> optparse.Values: defaults[option.dest] = option.check_value(opt_str, default) return optparse.Values(defaults) - def error(self, msg: str) -> None: + def error(self, msg: str) -> NoReturn: self.print_usage(sys.stderr) self.exit(UNKNOWN_ERROR, f"{msg}\n") diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index 883359c9ce7..1236180c086 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -25,7 +25,7 @@ def _rich_progress_bar( iterable: Iterable[bytes], *, bar_type: str, - size: int, + size: Optional[int], ) -> Generator[bytes, None, None]: assert bar_type == "on", "This should only be used in the default mode." diff --git a/src/pip/_internal/locations/_distutils.py b/src/pip/_internal/locations/_distutils.py index 0e18c6e1e14..3d856256986 100644 --- a/src/pip/_internal/locations/_distutils.py +++ b/src/pip/_internal/locations/_distutils.py @@ -21,7 +21,7 @@ from distutils.command.install import SCHEME_KEYS from distutils.command.install import install as distutils_install_command from distutils.sysconfig import get_python_lib -from typing import Dict, List, Optional, Union, cast +from typing import Dict, List, Optional, Union from pip._internal.models.scheme import Scheme from pip._internal.utils.compat import WINDOWS @@ -64,7 +64,7 @@ def distutils_scheme( obj: Optional[DistutilsCommand] = None obj = d.get_command_obj("install", create=True) assert obj is not None - i = cast(distutils_install_command, obj) + i: distutils_install_command = obj # NOTE: setting user or home has the side-effect of creating the home dir # or user base for installations during finalize_options() # ideally, we'd prefer a scheme class that has no side-effects. @@ -78,7 +78,7 @@ def distutils_scheme( i.root = root or i.root i.finalize_options() - scheme = {} + scheme: Dict[str, str] = {} for key in SCHEME_KEYS: scheme[key] = getattr(i, "install_" + key) diff --git a/src/pip/_internal/network/lazy_wheel.py b/src/pip/_internal/network/lazy_wheel.py index 82ec50d5106..03f883c1fc4 100644 --- a/src/pip/_internal/network/lazy_wheel.py +++ b/src/pip/_internal/network/lazy_wheel.py @@ -159,7 +159,7 @@ def _check_zip(self) -> None: try: # For read-only ZIP files, ZipFile only needs # methods read, seek, seekable and tell. - ZipFile(self) # type: ignore + ZipFile(self) except BadZipFile: pass else: diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index f6f13ed121f..c0a3e4d3b9d 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -129,12 +129,7 @@ def rmtree( onexc = _onerror_ignore if onexc is None: onexc = _onerror_reraise - handler: OnErr = partial( - # `[func, path, Union[ExcInfo, BaseException]] -> Any` is equivalent to - # `Union[([func, path, ExcInfo] -> Any), ([func, path, BaseException] -> Any)]`. - cast(Union[OnExc, OnErr], rmtree_errorhandler), - onexc=onexc, - ) + handler: OnErr = partial(rmtree_errorhandler, onexc=onexc) if sys.version_info >= (3, 12): # See https://docs.python.org/3.12/whatsnew/3.12.html#shutil. shutil.rmtree(dir, onexc=handler) # type: ignore diff --git a/tests/lib/test_wheel.py b/tests/lib/test_wheel.py index a171484a549..abbfaf77ef5 100644 --- a/tests/lib/test_wheel.py +++ b/tests/lib/test_wheel.py @@ -80,7 +80,7 @@ def test_make_metadata_file_custom_value_overrides() -> None: def test_make_metadata_file_custom_contents() -> None: value = b"hello" - f = default_make_metadata(value=value) + f = default_make_metadata(value=value) # type: ignore[arg-type] assert f is not None assert f.contents == value diff --git a/tests/lib/wheel.py b/tests/lib/wheel.py index 342abbacaad..e2634e72c86 100644 --- a/tests/lib/wheel.py +++ b/tests/lib/wheel.py @@ -109,7 +109,7 @@ def make_metadata_file( def make_wheel_metadata_file( name: str, version: str, - value: Defaulted[Optional[AnyStr]], + value: Defaulted[Union[bytes, str, None]], tags: Sequence[Tuple[str, str, str]], updates: Defaulted[Dict[str, HeaderValue]], ) -> Optional[File]: