From 102d8187a1f5a4cd5de7a549fd8a9af34e89a54f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:24:45 +0200 Subject: [PATCH] Enforce ruff/pyupgrade rules (UP) (#12936) --- pyproject.toml | 2 +- src/pip/_internal/cli/index_command.py | 2 +- src/pip/_internal/commands/list.py | 2 +- src/pip/_internal/commands/search.py | 2 +- src/pip/_internal/exceptions.py | 2 +- src/pip/_internal/req/constructors.py | 2 +- tests/functional/test_search.py | 6 +++--- tests/unit/resolution_resolvelib/test_provider.py | 2 +- tests/unit/resolution_resolvelib/test_resolver.py | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cf098eea061..4d8d1181697 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,7 +181,7 @@ select = [ "PLR0", "W", "RUF100", - "UP032", + "UP", ] [tool.ruff.lint.isort] diff --git a/src/pip/_internal/cli/index_command.py b/src/pip/_internal/cli/index_command.py index 226f8da1e94..db105d0fef9 100644 --- a/src/pip/_internal/cli/index_command.py +++ b/src/pip/_internal/cli/index_command.py @@ -54,7 +54,7 @@ class SessionCommandMixin(CommandContextMixIn): def __init__(self) -> None: super().__init__() - self._session: Optional["PipSession"] = None + self._session: Optional[PipSession] = None @classmethod def _get_index_urls(cls, options: Values) -> Optional[List[str]]: diff --git a/src/pip/_internal/commands/list.py b/src/pip/_internal/commands/list.py index 82fc46a118f..84943702410 100644 --- a/src/pip/_internal/commands/list.py +++ b/src/pip/_internal/commands/list.py @@ -176,7 +176,7 @@ def run(self, options: Values, args: List[str]) -> int: if options.excludes: skip.update(canonicalize_name(n) for n in options.excludes) - packages: "_ProcessedDists" = [ + packages: _ProcessedDists = [ cast("_DistWithLatestInfo", d) for d in get_environment(options.path).iter_installed_distributions( local_only=options.local, diff --git a/src/pip/_internal/commands/search.py b/src/pip/_internal/commands/search.py index e0d329d58ad..74b8d656b47 100644 --- a/src/pip/_internal/commands/search.py +++ b/src/pip/_internal/commands/search.py @@ -89,7 +89,7 @@ def transform_hits(hits: List[Dict[str, str]]) -> List["TransformedHit"]: packages with the list of versions stored inline. This converts the list from pypi into one we can use. """ - packages: Dict[str, "TransformedHit"] = OrderedDict() + packages: Dict[str, TransformedHit] = OrderedDict() for hit in hits: name = hit["name"] summary = hit["summary"] diff --git a/src/pip/_internal/exceptions.py b/src/pip/_internal/exceptions.py index 2587740f73a..8ceb818a35d 100644 --- a/src/pip/_internal/exceptions.py +++ b/src/pip/_internal/exceptions.py @@ -429,7 +429,7 @@ class HashErrors(InstallationError): """Multiple HashError instances rolled into one for reporting""" def __init__(self) -> None: - self.errors: List["HashError"] = [] + self.errors: List[HashError] = [] def append(self, error: "HashError") -> None: self.errors.append(error) diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index d73236e05c6..56a964f3177 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -80,7 +80,7 @@ def _set_requirement_extras(req: Requirement, new_extras: Set[str]) -> Requireme assert ( pre is not None and post is not None ), f"regex group selection for requirement {req} failed, this should never happen" - extras: str = "[%s]" % ",".join(sorted(new_extras)) if new_extras else "" + extras: str = "[{}]".format(",".join(sorted(new_extras)) if new_extras else "") return get_requirement(f"{pre}{extras}{post}") diff --git a/tests/functional/test_search.py b/tests/functional/test_search.py index 3f784e5dd1c..3d4baeb4832 100644 --- a/tests/functional/test_search.py +++ b/tests/functional/test_search.py @@ -45,7 +45,7 @@ def test_pypi_xml_transformation() -> None: "version": "1.0", }, ] - expected: List["TransformedHit"] = [ + expected: List[TransformedHit] = [ { "versions": ["1.0", "2.0"], "name": "foo", @@ -159,7 +159,7 @@ def test_latest_prerelease_install_message( """ Test documentation for installing pre-release packages is displayed """ - hits: List["TransformedHit"] = [ + hits: List[TransformedHit] = [ { "name": "ni", "summary": "For knights who say Ni!", @@ -188,7 +188,7 @@ def test_search_print_results_should_contain_latest_versions( """ Test that printed search results contain the latest package versions """ - hits: List["TransformedHit"] = [ + hits: List[TransformedHit] = [ { "name": "testlib1", "summary": "Test library 1.", diff --git a/tests/unit/resolution_resolvelib/test_provider.py b/tests/unit/resolution_resolvelib/test_provider.py index 77d1d299a0e..5f30e2bc1dd 100644 --- a/tests/unit/resolution_resolvelib/test_provider.py +++ b/tests/unit/resolution_resolvelib/test_provider.py @@ -19,7 +19,7 @@ def build_requirement_information( install_requirement = install_req_from_req_string(name) # RequirementInformation is typed as a tuple, but it is a namedtupled. # https://github.com/sarugaku/resolvelib/blob/7bc025aa2a4e979597c438ad7b17d2e8a08a364e/src/resolvelib/resolvers.pyi#L20-L22 - requirement_information: "PreferenceInformation" = RequirementInformation( + requirement_information: PreferenceInformation = RequirementInformation( requirement=SpecifierRequirement(install_requirement), # type: ignore[call-arg] parent=parent, ) diff --git a/tests/unit/resolution_resolvelib/test_resolver.py b/tests/unit/resolution_resolvelib/test_resolver.py index b1525a20a56..f2f36770fe6 100644 --- a/tests/unit/resolution_resolvelib/test_resolver.py +++ b/tests/unit/resolution_resolvelib/test_resolver.py @@ -38,7 +38,7 @@ def _make_graph( ) -> "DirectedGraph[Optional[str]]": """Build graph from edge declarations.""" - graph: "DirectedGraph[Optional[str]]" = DirectedGraph() + graph: DirectedGraph[Optional[str]] = DirectedGraph() for parent, child in edges: parent = cast(str, canonicalize_name(parent)) if parent else None child = cast(str, canonicalize_name(child)) if child else None