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

Codebase modernisation #464

Merged
merged 5 commits into from
Oct 29, 2021
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 packaging/_musllinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
with contextlib.ExitStack() as stack:
try:
f = stack.enter_context(open(executable, "rb"))
except IOError:
except OSError:
return None
ld = _parse_ld_musl_from_elf(f)
if not ld:
Expand Down
6 changes: 0 additions & 6 deletions packaging/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def __le__(self, other: object) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)

def __ne__(self, other: object) -> bool:
return not isinstance(other, self.__class__)

def __gt__(self, other: object) -> bool:
return True

Expand Down Expand Up @@ -51,9 +48,6 @@ def __le__(self, other: object) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)

def __ne__(self, other: object) -> bool:
return not isinstance(other, self.__class__)

def __gt__(self, other: object) -> bool:
return False

Expand Down
30 changes: 2 additions & 28 deletions packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ def __eq__(self, other: object) -> bool:
objects are equal.
"""

@abc.abstractmethod
def __ne__(self, other: object) -> bool:
"""
Returns a boolean representing whether or not the two Specifier like
objects are not equal.
"""

@abc.abstractproperty
def prereleases(self) -> Optional[bool]:
"""
Expand Down Expand Up @@ -119,7 +112,7 @@ def __repr__(self) -> str:
else ""
)

return "<{}({!r}{})>".format(self.__class__.__name__, str(self), pre)
return f"<{self.__class__.__name__}({str(self)!r}{pre})>"

def __str__(self) -> str:
return "{}{}".format(*self._spec)
Expand All @@ -142,17 +135,6 @@ def __eq__(self, other: object) -> bool:

return self._canonical_spec == other._canonical_spec

def __ne__(self, other: object) -> bool:
if isinstance(other, str):
try:
other = self.__class__(str(other))
except InvalidSpecifier:
return NotImplemented
elif not isinstance(other, self.__class__):
return NotImplemented

return self._spec != other._spec

def _get_operator(self, op: str) -> CallableOperator:
operator_callable: CallableOperator = getattr(
self, f"_compare_{self._operators[op]}"
Expand Down Expand Up @@ -667,7 +649,7 @@ def __repr__(self) -> str:
else ""
)

return "<SpecifierSet({!r}{})>".format(str(self), pre)
return f"<SpecifierSet({str(self)!r}{pre})>"

def __str__(self) -> str:
return ",".join(sorted(str(s) for s in self._specs))
Expand Down Expand Up @@ -706,14 +688,6 @@ def __eq__(self, other: object) -> bool:

return self._specs == other._specs

def __ne__(self, other: object) -> bool:
if isinstance(other, (str, _IndividualSpecifier)):
other = SpecifierSet(str(other))
elif not isinstance(other, SpecifierSet):
return NotImplemented

return self._specs != other._specs

def __len__(self) -> int:
return len(self._specs)

Expand Down
10 changes: 5 additions & 5 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __str__(self) -> str:
return f"{self._interpreter}-{self._abi}-{self._platform}"

def __repr__(self) -> str:
return "<{self} @ {self_id}>".format(self=self, self_id=id(self))
return f"<{self} @ {id(self)}>"


def parse_tag(tag: str) -> FrozenSet[Tag]:
Expand Down Expand Up @@ -192,7 +192,7 @@ def cpython_tags(
if not python_version:
python_version = sys.version_info[:2]

interpreter = "cp{}".format(_version_nodot(python_version[:2]))
interpreter = f"cp{_version_nodot(python_version[:2])}"

if abis is None:
if len(python_version) > 1:
Expand Down Expand Up @@ -268,11 +268,11 @@ def _py_interpreter_range(py_version: PythonVersion) -> Iterator[str]:
all previous versions of that major version.
"""
if len(py_version) > 1:
yield "py{version}".format(version=_version_nodot(py_version[:2]))
yield "py{major}".format(major=py_version[0])
yield f"py{_version_nodot(py_version[:2])}"
yield f"py{py_version[0]}"
if len(py_version) > 1:
for minor in range(py_version[1] - 1, -1, -1):
yield "py{version}".format(version=_version_nodot((py_version[0], minor)))
yield f"py{_version_nodot((py_version[0], minor))}"


def compatible_tags(
Expand Down