From 2df23f51bc1420d7c517532e77104ca97d438156 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Mon, 11 Oct 2021 21:38:21 +0100 Subject: [PATCH 1/2] Run pyupgrade --py36-plus on all files This should update the codebase to use modern Python 3 features. --- packaging/_musllinux.py | 2 +- packaging/specifiers.py | 4 ++-- packaging/tags.py | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packaging/_musllinux.py b/packaging/_musllinux.py index 85450faf..8ac3059b 100644 --- a/packaging/_musllinux.py +++ b/packaging/_musllinux.py @@ -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: diff --git a/packaging/specifiers.py b/packaging/specifiers.py index ce66bd4a..39252e49 100644 --- a/packaging/specifiers.py +++ b/packaging/specifiers.py @@ -119,7 +119,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) @@ -667,7 +667,7 @@ def __repr__(self) -> str: else "" ) - return "".format(str(self), pre) + return f"" def __str__(self) -> str: return ",".join(sorted(str(s) for s in self._specs)) diff --git a/packaging/tags.py b/packaging/tags.py index e65890a9..92541a9d 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -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]: @@ -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: @@ -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( From 7c3b58d469cfe1d1da2fc899432aefbfb0bf9699 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Mon, 11 Oct 2021 21:39:26 +0100 Subject: [PATCH 2/2] Drop all `__ne__` methods This is no longer necessary, since Python 2 support has been dropped. --- packaging/_structures.py | 6 ------ packaging/specifiers.py | 26 -------------------------- 2 files changed, 32 deletions(-) diff --git a/packaging/_structures.py b/packaging/_structures.py index 95154975..90a6465f 100644 --- a/packaging/_structures.py +++ b/packaging/_structures.py @@ -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 @@ -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 diff --git a/packaging/specifiers.py b/packaging/specifiers.py index 39252e49..0e218a6f 100644 --- a/packaging/specifiers.py +++ b/packaging/specifiers.py @@ -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]: """ @@ -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]}" @@ -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)