summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzu-ping Chung <uranusjr@gmail.com>2022-07-18 14:33:12 +0800
committerTzu-ping Chung <uranusjr@gmail.com>2022-07-18 15:13:12 +0800
commit360b96305aa673b4dee277059717fb87ac55088c (patch)
tree0e1ba70195a0f6ea3f775f39e4d72a6a7bfa4625
parenta7a35dc20d7d0f1f5d1862ebca7b12c5a40bfd03 (diff)
downloadpip-360b96305aa673b4dee277059717fb87ac55088c.tar.gz
Upgrade pre-commit hooks
Also fix some Mypy errors newly found with upgrade.
-rw-r--r--.pre-commit-config.yaml6
-rw-r--r--src/pip/_internal/metadata/importlib/_compat.py4
-rw-r--r--src/pip/_internal/metadata/importlib/_dists.py18
-rw-r--r--src/pip/_internal/network/lazy_wheel.py4
-rw-r--r--src/pip/_internal/network/session.py2
5 files changed, 25 insertions, 9 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4d88637ff..6dde3d6ff 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -2,7 +2,7 @@ exclude: 'src/pip/_vendor/'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.2.0
+ rev: v4.3.0
hooks:
- id: check-builtin-literals
- id: check-added-large-files
@@ -17,7 +17,7 @@ repos:
exclude: .patch
- repo: https://github.com/psf/black
- rev: 22.3.0
+ rev: 22.6.0
hooks:
- id: black
@@ -39,7 +39,7 @@ repos:
files: \.py$
- repo: https://github.com/pre-commit/mirrors-mypy
- rev: v0.942
+ rev: v0.961
hooks:
- id: mypy
exclude: tests/data
diff --git a/src/pip/_internal/metadata/importlib/_compat.py b/src/pip/_internal/metadata/importlib/_compat.py
index 2bc6bfd27..e0879807a 100644
--- a/src/pip/_internal/metadata/importlib/_compat.py
+++ b/src/pip/_internal/metadata/importlib/_compat.py
@@ -13,7 +13,9 @@ class BasePath(Protocol):
in both classes *that we need*.
"""
- name: str
+ @property
+ def name(self) -> str:
+ raise NotImplementedError()
@property
def parent(self) -> "BasePath":
diff --git a/src/pip/_internal/metadata/importlib/_dists.py b/src/pip/_internal/metadata/importlib/_dists.py
index ba039c4bf..fbf9a9321 100644
--- a/src/pip/_internal/metadata/importlib/_dists.py
+++ b/src/pip/_internal/metadata/importlib/_dists.py
@@ -3,7 +3,16 @@ import importlib.metadata
import os
import pathlib
import zipfile
-from typing import Collection, Dict, Iterable, Iterator, Mapping, Optional, Sequence
+from typing import (
+ Collection,
+ Dict,
+ Iterable,
+ Iterator,
+ Mapping,
+ Optional,
+ Sequence,
+ cast,
+)
from pip._vendor.packaging.requirements import Requirement
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
@@ -173,7 +182,12 @@ class Distribution(BaseDistribution):
return self._dist.entry_points
def _metadata_impl(self) -> email.message.Message:
- return self._dist.metadata
+ # From Python 3.10+, importlib.metadata declares PackageMetadata as the
+ # return type. This protocol is unfortunately a disaster now and misses
+ # a ton of fields that we need, including get() and get_payload(). We
+ # rely on the implementation that the object is actually a Message now,
+ # until upstream can improve the protocol. (python/cpython#94952)
+ return cast(email.message.Message, self._dist.metadata)
def iter_provided_extras(self) -> Iterable[str]:
return (
diff --git a/src/pip/_internal/network/lazy_wheel.py b/src/pip/_internal/network/lazy_wheel.py
index b0de53566..2d1ddaa89 100644
--- a/src/pip/_internal/network/lazy_wheel.py
+++ b/src/pip/_internal/network/lazy_wheel.py
@@ -135,8 +135,8 @@ class LazyZipOverHTTP:
self._file.__enter__()
return self
- def __exit__(self, *exc: Any) -> Optional[bool]:
- return self._file.__exit__(*exc)
+ def __exit__(self, *exc: Any) -> None:
+ self._file.__exit__(*exc)
@contextmanager
def _stay(self) -> Generator[None, None, None]:
diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py
index f5b834d09..e512ac784 100644
--- a/src/pip/_internal/network/session.py
+++ b/src/pip/_internal/network/session.py
@@ -465,7 +465,7 @@ class PipSession(requests.Session):
continue
try:
- addr = ipaddress.ip_address(origin_host)
+ addr = ipaddress.ip_address(origin_host or "")
network = ipaddress.ip_network(secure_host)
except ValueError:
# We don't have both a valid address or a valid network, so