Skip to content

Commit e9cf21c

Browse files
authored
Merge pull request #10262 from jdufresne/nonzero
Remove Python 2 __nonzero__ method definitions
2 parents 657ed2a + 21fd93d commit e9cf21c

File tree

5 files changed

+3
-16
lines changed

5 files changed

+3
-16
lines changed

news/51d70b65-78e9-426c-80a6-47efcaad9628.trivial.rst

Whitespace-only changes.

src/pip/_internal/exceptions.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,9 @@ def __str__(self):
189189
return '\n'.join(lines)
190190
return ''
191191

192-
def __nonzero__(self):
193-
# type: () -> bool
194-
return bool(self.errors)
195-
196192
def __bool__(self):
197193
# type: () -> bool
198-
return self.__nonzero__()
194+
return bool(self.errors)
199195

200196

201197
class HashError(InstallationError):

src/pip/_internal/resolution/resolvelib/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ def from_ireq(cls, ireq: InstallRequirement) -> "Constraint":
3636
links = frozenset([ireq.link]) if ireq.link else frozenset()
3737
return Constraint(ireq.specifier, ireq.hashes(trust_internet=False), links)
3838

39-
def __nonzero__(self) -> bool:
40-
return bool(self.specifier) or bool(self.hashes) or bool(self.links)
41-
4239
def __bool__(self) -> bool:
43-
return self.__nonzero__()
40+
return bool(self.specifier) or bool(self.hashes) or bool(self.links)
4441

4542
def __and__(self, other: InstallRequirement) -> "Constraint":
4643
if not isinstance(other, InstallRequirement):

src/pip/_internal/resolution/resolvelib/found_candidates.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,3 @@ def __bool__(self) -> bool:
138138
if self._prefers_installed and self._installed:
139139
return True
140140
return any(self)
141-
142-
__nonzero__ = __bool__ # XXX: Python 2.

src/pip/_internal/utils/hashes.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,11 @@ def check_against_path(self, path):
117117
with open(path, "rb") as file:
118118
return self.check_against_file(file)
119119

120-
def __nonzero__(self):
120+
def __bool__(self):
121121
# type: () -> bool
122122
"""Return whether I know any known-good hashes."""
123123
return bool(self._allowed)
124124

125-
def __bool__(self):
126-
# type: () -> bool
127-
return self.__nonzero__()
128-
129125
def __eq__(self, other):
130126
# type: (object) -> bool
131127
if not isinstance(other, Hashes):

0 commit comments

Comments
 (0)