Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to mypy 1.12.1 #13022

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
6 changes: 3 additions & 3 deletions src/pip/_internal/locations/_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/network/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know the reason of this one? Is that some regression in mypy?

Copy link
Contributor Author

@hauntsaninja hauntsaninja Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to mypy 1.11, mypy did not understand functools.partial at all, so calls here were effectively going unchecked. mypy now struggles a little to solve the value constrained type var once it's been partially solved in the functools.partial call.

Looking at it a little closer, the type variable in make_wheel_metadata_file is actually unnecessary, so I'll remove it to make one of the two of these go away

assert f is not None
assert f.contents == value

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
Loading