Skip to content

Commit 44a034a

Browse files
committed
Move all remaining type comments to annotations
Use the com2ann tool to convert remaining comments to annotations. Now, no type comments remain. https://github.com/ilevkivskyi/com2ann Some types are not available at runtime (e.g. Literal) or require a forward reference and so were quoted.
1 parent 7aaea4e commit 44a034a

File tree

8 files changed

+237
-393
lines changed

8 files changed

+237
-393
lines changed

news/dba409af-2178-4e27-9292-2066782aba0b.trivial.rst

Whitespace-only changes.

src/pip/_internal/utils/hashes.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class Hashes:
2828
2929
"""
3030

31-
def __init__(self, hashes=None):
32-
# type: (Dict[str, List[str]]) -> None
31+
def __init__(self, hashes: Dict[str, List[str]] = None) -> None:
3332
"""
3433
:param hashes: A dict of algorithm names pointing to lists of allowed
3534
hex digests
@@ -41,8 +40,7 @@ def __init__(self, hashes=None):
4140
allowed[alg] = sorted(keys)
4241
self._allowed = allowed
4342

44-
def __and__(self, other):
45-
# type: (Hashes) -> Hashes
43+
def __and__(self, other: "Hashes") -> "Hashes":
4644
if not isinstance(other, Hashes):
4745
return NotImplemented
4846

@@ -62,21 +60,14 @@ def __and__(self, other):
6260
return Hashes(new)
6361

6462
@property
65-
def digest_count(self):
66-
# type: () -> int
63+
def digest_count(self) -> int:
6764
return sum(len(digests) for digests in self._allowed.values())
6865

69-
def is_hash_allowed(
70-
self,
71-
hash_name, # type: str
72-
hex_digest, # type: str
73-
):
74-
# type: (...) -> bool
66+
def is_hash_allowed(self, hash_name: str, hex_digest: str) -> bool:
7567
"""Return whether the given hex digest is allowed."""
7668
return hex_digest in self._allowed.get(hash_name, [])
7769

78-
def check_against_chunks(self, chunks):
79-
# type: (Iterator[bytes]) -> None
70+
def check_against_chunks(self, chunks: Iterator[bytes]) -> None:
8071
"""Check good hashes against ones built from iterable of chunks of
8172
data.
8273
@@ -99,37 +90,31 @@ def check_against_chunks(self, chunks):
9990
return
10091
self._raise(gots)
10192

102-
def _raise(self, gots):
103-
# type: (Dict[str, _Hash]) -> NoReturn
93+
def _raise(self, gots: Dict[str, "_Hash"]) -> "NoReturn":
10494
raise HashMismatch(self._allowed, gots)
10595

106-
def check_against_file(self, file):
107-
# type: (BinaryIO) -> None
96+
def check_against_file(self, file: BinaryIO) -> None:
10897
"""Check good hashes against a file-like object
10998
11099
Raise HashMismatch if none match.
111100
112101
"""
113102
return self.check_against_chunks(read_chunks(file))
114103

115-
def check_against_path(self, path):
116-
# type: (str) -> None
104+
def check_against_path(self, path: str) -> None:
117105
with open(path, "rb") as file:
118106
return self.check_against_file(file)
119107

120-
def __bool__(self):
121-
# type: () -> bool
108+
def __bool__(self) -> bool:
122109
"""Return whether I know any known-good hashes."""
123110
return bool(self._allowed)
124111

125-
def __eq__(self, other):
126-
# type: (object) -> bool
112+
def __eq__(self, other: object) -> bool:
127113
if not isinstance(other, Hashes):
128114
return NotImplemented
129115
return self._allowed == other._allowed
130116

131-
def __hash__(self):
132-
# type: () -> int
117+
def __hash__(self) -> int:
133118
return hash(
134119
",".join(
135120
sorted(
@@ -149,13 +134,11 @@ class MissingHashes(Hashes):
149134
150135
"""
151136

152-
def __init__(self):
153-
# type: () -> None
137+
def __init__(self) -> None:
154138
"""Don't offer the ``hashes`` kwarg."""
155139
# Pass our favorite hash in to generate a "gotten hash". With the
156140
# empty list, it will never match, so an error will always raise.
157141
super().__init__(hashes={FAVORITE_HASH: []})
158142

159-
def _raise(self, gots):
160-
# type: (Dict[str, _Hash]) -> NoReturn
143+
def _raise(self, gots: Dict[str, "_Hash"]) -> "NoReturn":
161144
raise HashMissing(gots[FAVORITE_HASH].hexdigest())

0 commit comments

Comments
 (0)