From 8867f50c7d0af262ac0e15a80b5569a56c659269 Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sat, 13 Aug 2022 18:53:28 +0200 Subject: [PATCH 1/9] add flake8-pie precommit hook --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eeac4684d91..851b27751a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,6 +43,7 @@ repos: - flake8-typing-imports==1.12.0 - flake8-use-fstring==1.4 - pep8-naming==0.13.1 + - flake8-pie==0.16.0 - repo: https://github.com/asottile/pyupgrade rev: v2.37.3 From 48dd3d7a8ab9d384541b3ed01c7b308a7a65f928 Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sat, 13 Aug 2022 18:54:18 +0200 Subject: [PATCH 2/9] fix PIE781 --- src/poetry/console/application.py | 9 +++---- src/poetry/console/commands/command.py | 3 +-- src/poetry/console/commands/config.py | 4 +--- src/poetry/console/commands/debug/info.py | 3 +-- src/poetry/console/commands/plugin/add.py | 3 +-- src/poetry/console/commands/plugin/remove.py | 3 +-- src/poetry/console/commands/plugin/show.py | 3 +-- src/poetry/console/commands/run.py | 4 +--- .../console/commands/self/self_command.py | 3 +-- .../console/commands/self/show/__init__.py | 3 +-- src/poetry/console/commands/self/update.py | 3 +-- src/poetry/installation/chooser.py | 4 +--- src/poetry/installation/executor.py | 8 ++----- .../installation/operations/operation.py | 3 +-- src/poetry/masonry/builders/editable.py | 6 ++--- src/poetry/mixology/incompatibility.py | 3 +-- src/poetry/mixology/version_solver.py | 12 ++++------ src/poetry/packages/dependency_package.py | 3 +-- src/poetry/packages/locker.py | 3 +-- src/poetry/publishing/uploader.py | 3 +-- src/poetry/puzzle/solver.py | 4 +--- src/poetry/repositories/pypi_repository.py | 6 ++--- src/poetry/utils/authenticator.py | 3 +-- src/poetry/utils/env.py | 24 +++++++------------ src/poetry/utils/helpers.py | 3 +-- src/poetry/utils/password_manager.py | 3 +-- src/poetry/vcs/git/backend.py | 11 +++------ tests/conftest.py | 4 +--- tests/console/commands/cache/test_clear.py | 3 +-- tests/installation/test_executor.py | 4 +--- tests/installation/test_pip_installer.py | 8 ++----- .../masonry/builders/test_editable_builder.py | 16 ++++--------- tests/packages/test_locker.py | 4 +--- tests/plugins/test_plugin_manager.py | 4 +--- tests/utils/test_env.py | 4 +--- 35 files changed, 56 insertions(+), 131 deletions(-) diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index 00a9488377b..5fc7f7dde48 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -43,8 +43,7 @@ def _load() -> Command: words = name.split(" ") module = import_module("poetry.console.commands." + ".".join(words)) command_class = getattr(module, "".join(c.title() for c in words) + "Command") - command: Command = command_class() - return command + return command_class() return _load @@ -186,8 +185,7 @@ def _run(self, io: IO) -> int: self._load_plugins(io) - exit_code: int = super()._run(io) - return exit_code + return super()._run(io) def _configure_io(self, io: IO) -> None: # We need to check if the command being run @@ -387,8 +385,7 @@ def _get_solution_provider_repository(self) -> SolutionProviderRepository: def main() -> int: - exit_code: int = Application().run() - return exit_code + return Application().run() if __name__ == "__main__": diff --git a/src/poetry/console/commands/command.py b/src/poetry/console/commands/command.py index 4bc26ad567b..6f6ac1b9ce1 100644 --- a/src/poetry/console/commands/command.py +++ b/src/poetry/console/commands/command.py @@ -28,8 +28,7 @@ def set_poetry(self, poetry: Poetry) -> None: self._poetry = poetry def get_application(self) -> Application: - application: Application = self.application - return application + return self.application def reset_poetry(self) -> None: self.get_application().reset_poetry() diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index 03773a5ef0d..33f20d9a409 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -53,7 +53,7 @@ class ConfigCommand(Command): @property def unique_config_values(self) -> dict[str, tuple[Any, Any, Any]]: - unique_config_values = { + return { "cache-dir": ( str, lambda val: str(Path(val)), @@ -123,8 +123,6 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any, Any]]: ), } - return unique_config_values - def handle(self) -> int: from pathlib import Path diff --git a/src/poetry/console/commands/debug/info.py b/src/poetry/console/commands/debug/info.py index f90d8e794d3..01dfe151001 100644 --- a/src/poetry/console/commands/debug/info.py +++ b/src/poetry/console/commands/debug/info.py @@ -24,5 +24,4 @@ def handle(self) -> int: ) command = self.application.get("env info") - exit_code: int = command.run(self.io) - return exit_code + return command.run(self.io) diff --git a/src/poetry/console/commands/plugin/add.py b/src/poetry/console/commands/plugin/add.py index b59729bc76d..24734056744 100644 --- a/src/poetry/console/commands/plugin/add.py +++ b/src/poetry/console/commands/plugin/add.py @@ -54,11 +54,10 @@ def handle(self) -> int: if self.option("--dry-run"): argv.append("--dry-run") - exit_code: int = command.run( + return command.run( IO( StringInput(" ".join(argv)), self.io.output, self.io.error_output, ) ) - return exit_code diff --git a/src/poetry/console/commands/plugin/remove.py b/src/poetry/console/commands/plugin/remove.py index d50bfaf2ed2..1791906defd 100644 --- a/src/poetry/console/commands/plugin/remove.py +++ b/src/poetry/console/commands/plugin/remove.py @@ -47,11 +47,10 @@ def handle(self) -> int: if self.option("--dry-run"): argv.append("--dry-run") - exit_code: int = command.run( + return command.run( IO( StringInput(" ".join(argv)), self.io.output, self.io.error_output, ) ) - return exit_code diff --git a/src/poetry/console/commands/plugin/show.py b/src/poetry/console/commands/plugin/show.py index f04ba7669c8..2fa3c1911d3 100644 --- a/src/poetry/console/commands/plugin/show.py +++ b/src/poetry/console/commands/plugin/show.py @@ -22,11 +22,10 @@ def handle(self) -> int: application = self.get_application() command = application.find("self show plugins") - exit_code: int = command.run( + return command.run( IO( StringInput(""), self.io.output, self.io.error_output, ) ) - return exit_code diff --git a/src/poetry/console/commands/run.py b/src/poetry/console/commands/run.py index 6496b45af24..b412a08b08a 100644 --- a/src/poetry/console/commands/run.py +++ b/src/poetry/console/commands/run.py @@ -40,9 +40,7 @@ def _module(self) -> Module: poetry = self.poetry package = poetry.package path = poetry.file.parent - module = Module(package.name, path.as_posix(), package.packages) - - return module + return Module(package.name, path.as_posix(), package.packages) def run_script(self, script: str | dict[str, str], args: str) -> int: if isinstance(script, dict): diff --git a/src/poetry/console/commands/self/self_command.py b/src/poetry/console/commands/self/self_command.py index 90d6f39216f..f68e72c12eb 100644 --- a/src/poetry/console/commands/self/self_command.py +++ b/src/poetry/console/commands/self/self_command.py @@ -103,8 +103,7 @@ def _system_project_handle(self) -> int: The default implementations handles cases where a `self` command delegates handling to an existing command. Eg: `SelfAddCommand(SelfCommand, AddCommand)`. """ - return_code: int = super().handle() - return return_code + return super().handle() def reset(self) -> None: """ diff --git a/src/poetry/console/commands/self/show/__init__.py b/src/poetry/console/commands/self/show/__init__.py index 7212d69c7e1..b13a8873d23 100644 --- a/src/poetry/console/commands/self/show/__init__.py +++ b/src/poetry/console/commands/self/show/__init__.py @@ -30,5 +30,4 @@ def activated_groups(self) -> set[str]: if self.option("addons", False): return {SelfCommand.ADDITIONAL_PACKAGE_GROUP} - groups: set[str] = super(ShowCommand, self).activated_groups - return groups + return super(ShowCommand, self).activated_groups diff --git a/src/poetry/console/commands/self/update.py b/src/poetry/console/commands/self/update.py index f42a3d477d8..d3eb7761afa 100644 --- a/src/poetry/console/commands/self/update.py +++ b/src/poetry/console/commands/self/update.py @@ -48,11 +48,10 @@ def _system_project_handle(self) -> int: if self.option("preview"): argv.append("--allow-prereleases") - exit_code: int = add_command.run( + return add_command.run( IO( StringInput(" ".join(argv)), self.io.output, self.io.error_output, ) ) - return exit_code diff --git a/src/poetry/installation/chooser.py b/src/poetry/installation/chooser.py index 600a46306ce..cfb4ef1b7dc 100644 --- a/src/poetry/installation/chooser.py +++ b/src/poetry/installation/chooser.py @@ -103,9 +103,7 @@ def choose_for(self, package: Package) -> Link: raise RuntimeError(f"Unable to find installation candidates for {package}") # Get the best link - chosen = max(links, key=lambda link: self._sort_key(package, link)) - - return chosen + return max(links, key=lambda link: self._sort_key(package, link)) def _get_links(self, package: Package) -> list[Link]: if package.source_type: diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index c582b0d9ea7..10eedf72cb7 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -757,7 +757,7 @@ def _save_url_reference(self, operation: Operation) -> None: writer.writerow([str(path), "", ""]) def _create_git_url_reference(self, package: Package) -> dict[str, Any]: - reference = { + return { "url": package.source_url, "vcs_info": { "vcs": "git", @@ -768,17 +768,13 @@ def _create_git_url_reference(self, package: Package) -> dict[str, Any]: if package.source_subdirectory: reference["subdirectory"] = package.source_subdirectory - return reference - def _create_url_url_reference(self, package: Package) -> dict[str, Any]: archive_info = {} if package.name in self._hashes: archive_info["hash"] = self._hashes[package.name] - reference = {"url": package.source_url, "archive_info": archive_info} - - return reference + return {"url": package.source_url, "archive_info": archive_info} def _create_file_url_reference(self, package: Package) -> dict[str, Any]: archive_info = {} diff --git a/src/poetry/installation/operations/operation.py b/src/poetry/installation/operations/operation.py index 816618a1b8d..99c12c39632 100644 --- a/src/poetry/installation/operations/operation.py +++ b/src/poetry/installation/operations/operation.py @@ -43,8 +43,7 @@ def package(self) -> Package: raise NotImplementedError() def format_version(self, package: Package) -> str: - version: str = package.full_pretty_version - return version + return package.full_pretty_version def skip(self: T, reason: str) -> T: self._skipped = True diff --git a/src/poetry/masonry/builders/editable.py b/src/poetry/masonry/builders/editable.py index fac1569e67c..70975887101 100644 --- a/src/poetry/masonry/builders/editable.py +++ b/src/poetry/masonry/builders/editable.py @@ -61,8 +61,7 @@ def build(self, target_dir: Path | None = None) -> Path: " - Falling back on using a setup.py" ) self._setup_build() - path: Path = self._path - return path + return self._path self._run_build_script(self._package.build_script) @@ -79,8 +78,7 @@ def build(self, target_dir: Path | None = None) -> Path: added_files += self._add_scripts() self._add_dist_info(added_files) - path = self._path - return path + return self._path def _run_build_script(self, build_script: str) -> None: with build_environment(poetry=self._poetry, env=self._env, io=self._io) as env: diff --git a/src/poetry/mixology/incompatibility.py b/src/poetry/mixology/incompatibility.py index b629ea7a699..3f52325313a 100644 --- a/src/poetry/mixology/incompatibility.py +++ b/src/poetry/mixology/incompatibility.py @@ -435,8 +435,7 @@ def _terse(self, term: Term, allow_every: bool = False) -> str: return f"every version of {term.dependency.complete_name}" if term.dependency.is_root: - pretty_name: str = term.dependency.pretty_name - return pretty_name + return term.dependency.pretty_name if term.dependency.source_type: return str(term.dependency) diff --git a/src/poetry/mixology/version_solver.py b/src/poetry/mixology/version_solver.py index b520737eb70..6fa397db7f6 100644 --- a/src/poetry/mixology/version_solver.py +++ b/src/poetry/mixology/version_solver.py @@ -225,8 +225,7 @@ def _propagate_incompatibility( unsatisfied.dependency, not unsatisfied.is_positive(), incompatibility ) - complete_name: str = unsatisfied.dependency.complete_name - return complete_name + return unsatisfied.dependency.complete_name def _resolve_conflict(self, incompatibility: Incompatibility) -> Incompatibility: """ @@ -414,8 +413,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: self._add_incompatibility( Incompatibility([Term(dependency, True)], PackageNotFoundCause(e)) ) - complete_name: str = dependency.complete_name - return complete_name + return dependency.complete_name package = None if dependency.name not in self._use_latest: @@ -443,8 +441,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: Incompatibility([Term(dependency, True)], NoVersionsCause()) ) - complete_name = dependency.complete_name - return complete_name + return dependency.complete_name else: package = locked @@ -472,8 +469,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: f" ({package.package.full_pretty_version})" ) - complete_name = dependency.complete_name - return complete_name + return dependency.complete_name def _result(self) -> SolverResult: """ diff --git a/src/poetry/packages/dependency_package.py b/src/poetry/packages/dependency_package.py index a06d28b65b0..048a5dc94b4 100644 --- a/src/poetry/packages/dependency_package.py +++ b/src/poetry/packages/dependency_package.py @@ -43,5 +43,4 @@ def __eq__(self, other: object) -> bool: if isinstance(other, DependencyPackage): other = other.package - equal: bool = self._package == other - return equal + return self._package == other diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py index 37be4e606d2..ce114b6578b 100644 --- a/src/poetry/packages/locker.py +++ b/src/poetry/packages/locker.py @@ -89,8 +89,7 @@ def is_fresh(self) -> bool: metadata = lock.get("metadata", {}) if "content-hash" in metadata: - fresh: bool = self._content_hash == metadata["content-hash"] - return fresh + return self._content_hash == metadata["content-hash"] return False diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 566f50eec5e..8adb7ecc6ae 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -61,8 +61,7 @@ def __init__(self, poetry: Poetry, io: IO) -> None: @property def user_agent(self) -> str: - agent: str = user_agent("poetry", __version__) - return agent + return user_agent("poetry", __version__) @property def adapter(self) -> adapters.HTTPAdapter: diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index 815e5d54766..a4c6b3e7267 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -211,14 +211,12 @@ def depth_first_search(source: PackageNode) -> list[list[PackageNode]]: node.visit(back_edges[node.id]) combined_nodes[node.name].append(node) - combined_topo_sorted_nodes: list[list[PackageNode]] = [ + return [ combined_nodes.pop(node.name) for node in topo_sorted_nodes if node.name in combined_nodes ] - return combined_topo_sorted_nodes - def dfs_visit( node: PackageNode, diff --git a/src/poetry/repositories/pypi_repository.py b/src/poetry/repositories/pypi_repository.py index 142b29d85d2..925a18b4c39 100644 --- a/src/poetry/repositories/pypi_repository.py +++ b/src/poetry/repositories/pypi_repository.py @@ -155,10 +155,9 @@ def get_package_info(self, name: str) -> dict[str, Any]: if self._disable_cache: return self._get_package_info(name) - package_info: dict[str, Any] = self._cache.store("packages").remember_forever( + return self._cache.store("packages").remember_forever( name, lambda: self._get_package_info(name) ) - return package_info def _get_package_info(self, name: str) -> dict[str, Any]: data = self._get(f"pypi/{name}/json") @@ -264,5 +263,4 @@ def _get(self, endpoint: str) -> dict[str, Any] | None: if json_response.status_code != 200: return None - json: dict[str, Any] = json_response.json() - return json + return json_response.json() diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index fbcb25ea502..142edb222aa 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -145,8 +145,7 @@ def create_session(self) -> requests.Session: if not self.is_cached: return session - session = CacheControl(sess=session, cache=self._cache_control) - return session + return CacheControl(sess=session, cache=self._cache_control) def get_session(self, url: str | None = None) -> requests.Session: if not url: diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 6c7e60deb34..1d508f2ceed 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1205,8 +1205,7 @@ def version_info(self) -> tuple[Any, ...]: @property def python_implementation(self) -> str: - implementation: str = self.marker_env["platform_python_implementation"] - return implementation + return self.marker_env["platform_python_implementation"] @property def python(self) -> str: @@ -1265,8 +1264,7 @@ def get_embedded_wheel(self, distribution: str) -> Path: wheel: Wheel = get_embed_wheel( distribution, f"{self.version_info[0]}.{self.version_info[1]}" ) - path: Path = wheel.path - return path + return wheel.path @property def pip_embedded(self) -> str: @@ -1403,8 +1401,7 @@ def get_paths(self) -> dict[str, str]: raise NotImplementedError() def is_valid_for_marker(self, marker: BaseMarker) -> bool: - valid: bool = marker.validate(self.marker_env) - return valid + return marker.validate(self.marker_env) def is_sane(self) -> bool: """ @@ -1657,8 +1654,7 @@ def __init__(self, path: Path, base: Path | None = None) -> None: def sys_path(self) -> list[str]: output = self.run_python_script(GET_SYS_PATH) assert isinstance(output, str) - paths: list[str] = json.loads(output) - return paths + return json.loads(output) def get_version_info(self) -> tuple[Any, ...]: output = self.run_python_script(GET_PYTHON_VERSION) @@ -1667,8 +1663,7 @@ def get_version_info(self) -> tuple[Any, ...]: return tuple(int(s) for s in output.strip().split(".")) def get_python_implementation(self) -> str: - implementation: str = self.marker_env["platform_python_implementation"] - return implementation + return self.marker_env["platform_python_implementation"] def get_pip_command(self, embedded: bool = False) -> list[str]: # We're in a virtualenv that is known to be sane, @@ -1688,8 +1683,7 @@ def get_marker_env(self) -> dict[str, Any]: output = self.run_python_script(GET_ENVIRONMENT_INFO) assert isinstance(output, str) - env: dict[str, Any] = json.loads(output) - return env + return json.loads(output) def get_pip_version(self) -> Version: output = self.run_pip("--version") @@ -1705,8 +1699,7 @@ def get_pip_version(self) -> Version: def get_paths(self) -> dict[str, str]: output = self.run_python_script(GET_PATHS) assert isinstance(output, str) - paths: dict[str, str] = json.loads(output) - return paths + return json.loads(output) def is_venv(self) -> bool: return True @@ -1822,8 +1815,7 @@ def get_paths(self) -> dict[str, str]: output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS) assert isinstance(output, str) - paths: dict[str, str] = json.loads(output) - return paths + return json.loads(output) def execute(self, bin: str, *args: str, **kwargs: Any) -> int: command = self.get_command_from_bin(bin) + list(args) diff --git a/src/poetry/utils/helpers.py b/src/poetry/utils/helpers.py index 432cbb6a99e..118a08e7ec2 100644 --- a/src/poetry/utils/helpers.py +++ b/src/poetry/utils/helpers.py @@ -123,8 +123,7 @@ def get_package_version_display_string( path = Path(os.path.relpath(package.source_url, root.as_posix())).as_posix() return f"{package.version} {path}" - pretty_version: str = package.full_pretty_version - return pretty_version + return package.full_pretty_version def paths_csv(paths: list[Path]) -> str: diff --git a/src/poetry/utils/password_manager.py b/src/poetry/utils/password_manager.py index 78a5559b2ae..2725691a81a 100644 --- a/src/poetry/utils/password_manager.py +++ b/src/poetry/utils/password_manager.py @@ -172,8 +172,7 @@ def set_pypi_token(self, name: str, token: str) -> None: def get_pypi_token(self, name: str) -> str | None: if not self.keyring.is_available(): - token: str | None = self._config.get(f"pypi-token.{name}") - return token + return self._config.get(f"pypi-token.{name}") return self.keyring.get_password(name, "__token__") diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index 389ebf682dd..5438af7c4a6 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -199,12 +199,11 @@ def _fetch_remote_refs(cls, url: str, local: Repo) -> FetchPackResult: client, path = get_transport_and_path(url, config=config, **kwargs) with local: - result: FetchPackResult = client.fetch( + return client.fetch( path, local, determine_wants=local.object_store.determine_wants_all, ) - return result @staticmethod def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo: @@ -240,8 +239,7 @@ def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo: f"Failed to checkout {url} at '{revision}'" ) - repo = Repo(str(target)) - return repo + return Repo(str(target)) @classmethod def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo: @@ -358,10 +356,7 @@ def _clone_submodules(cls, repo: Repo) -> None: def is_using_legacy_client() -> bool: from poetry.config.config import Config - legacy_client: bool = ( - Config.create().get("experimental", {}).get("system-git-client", False) - ) - return legacy_client + return Config.create().get("experimental", {}).get("system-git-client", False) @staticmethod def get_default_source_root() -> Path: diff --git a/tests/conftest.py b/tests/conftest.py index 4e529ec0487..01dd8a4a3b8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -186,9 +186,7 @@ def config_source(config_cache_dir: Path) -> DictConfigSource: @pytest.fixture def auth_config_source() -> DictConfigSource: - source = DictConfigSource() - - return source + return DictConfigSource() @pytest.fixture(autouse=True) diff --git a/tests/console/commands/cache/test_clear.py b/tests/console/commands/cache/test_clear.py index ce0243f4ac8..60ae6d2ea7e 100644 --- a/tests/console/commands/cache/test_clear.py +++ b/tests/console/commands/cache/test_clear.py @@ -19,8 +19,7 @@ def tester() -> ApplicationTester: app = Application() - tester = ApplicationTester(app) - return tester + return ApplicationTester(app) def test_cache_clear_all( diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 7f60905a33c..82a91bb6d32 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -66,9 +66,7 @@ def io_decorated() -> BufferedIO: @pytest.fixture() def io_not_decorated() -> BufferedIO: - io = BufferedIO(decorated=False) - - return io + return BufferedIO(decorated=False) @pytest.fixture() diff --git a/tests/installation/test_pip_installer.py b/tests/installation/test_pip_installer.py index 4763d71bb42..0de55809fa2 100644 --- a/tests/installation/test_pip_installer.py +++ b/tests/installation/test_pip_installer.py @@ -27,7 +27,7 @@ @pytest.fixture def package_git() -> Package: - package = Package( + return Package( "demo", "1.0.0", source_type="git", @@ -35,12 +35,10 @@ def package_git() -> Package: source_reference="master", ) - return package - @pytest.fixture def package_git_with_subdirectory() -> Package: - package = Package( + return Package( "subdirectories", "2.0.0", source_type="git", @@ -49,8 +47,6 @@ def package_git_with_subdirectory() -> Package: source_subdirectory="two", ) - return package - @pytest.fixture def pool() -> Pool: diff --git a/tests/masonry/builders/test_editable_builder.py b/tests/masonry/builders/test_editable_builder.py index 87c0c676f62..6e21c9441cc 100644 --- a/tests/masonry/builders/test_editable_builder.py +++ b/tests/masonry/builders/test_editable_builder.py @@ -31,41 +31,33 @@ @pytest.fixture() def simple_poetry() -> Poetry: - poetry = Factory().create_poetry( + return Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "simple_project" ) - return poetry - @pytest.fixture() def project_with_include() -> Poetry: - poetry = Factory().create_poetry( + return Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "with-include" ) - return poetry - @pytest.fixture() def extended_poetry() -> Poetry: - poetry = Factory().create_poetry( + return Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "extended_project" ) - return poetry - @pytest.fixture() def extended_without_setup_poetry() -> Poetry: - poetry = Factory().create_poetry( + return Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "extended_project_without_setup" ) - return poetry - @pytest.fixture() def env_manager(simple_poetry: Poetry) -> EnvManager: diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index e0ed720bf94..e655cb04ae1 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -33,9 +33,7 @@ def locker() -> Locker: with tempfile.NamedTemporaryFile() as f: f.close() - locker = Locker(f.name, {}) - - return locker + return Locker(f.name, {}) @pytest.fixture diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index 868d61f26f0..d5dc0d9dde8 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -48,7 +48,7 @@ def activate(self, poetry: Poetry, io: BufferedIO) -> None: @pytest.fixture() def poetry(tmp_dir: str, config: Config) -> Poetry: - poetry = Poetry( + return Poetry( CWD / "pyproject.toml", {}, ProjectPackage("simple-project", "1.2.3"), @@ -56,8 +56,6 @@ def poetry(tmp_dir: str, config: Config) -> Poetry: config, ) - return poetry - @pytest.fixture() def io() -> BufferedIO: diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 03c1e4c29ff..8c1bbf36989 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -1371,12 +1371,10 @@ def test_generate_env_name_uses_real_path(tmp_dir: str, mocker: MockerFixture): @pytest.fixture() def extended_without_setup_poetry() -> Poetry: - poetry = Factory().create_poetry( + return Factory().create_poetry( Path(__file__).parent.parent / "fixtures" / "extended_project_without_setup" ) - return poetry - def test_build_environment_called_build_script_specified( mocker: MockerFixture, extended_without_setup_poetry: Poetry, tmp_dir: str From 0a73f18e4733f5a5cbcd486cfac9c4b922b601c5 Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sat, 13 Aug 2022 20:16:06 +0200 Subject: [PATCH 3/9] PIE803 --- src/poetry/inspection/info.py | 6 ++++-- src/poetry/plugins/plugin_manager.py | 2 +- src/poetry/publishing/publisher.py | 4 ++-- src/poetry/puzzle/solver.py | 6 +++--- src/poetry/utils/authenticator.py | 2 +- src/poetry/utils/password_manager.py | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 7e851223b5a..d4b91ae3d19 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -201,8 +201,10 @@ def to_package( except ValueError: # Likely unable to parse constraint so we skip it logger.debug( - f"Invalid constraint ({req}) found in" - f" {package.name}-{package.version} dependencies, skipping", + "Invalid constraint (%s) found in %s-%s dependencies, skipping", + req, + package.name, + package.version, ) continue diff --git a/src/poetry/plugins/plugin_manager.py b/src/poetry/plugins/plugin_manager.py index 99d83ee91c5..1a01dc36335 100644 --- a/src/poetry/plugins/plugin_manager.py +++ b/src/poetry/plugins/plugin_manager.py @@ -71,7 +71,7 @@ def activate(self, *args: Any, **kwargs: Any) -> None: plugin.activate(*args, **kwargs) def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None: - logger.debug(f"Loading the {ep.name} plugin") # type: ignore[attr-defined] + logger.debug("Loading the %s plugin", ep.name) # type: ignore[attr-defined] plugin = ep.load() # type: ignore[no-untyped-call] diff --git a/src/poetry/publishing/publisher.py b/src/poetry/publishing/publisher.py index cf8515bcf46..a5335258041 100644 --- a/src/poetry/publishing/publisher.py +++ b/src/poetry/publishing/publisher.py @@ -57,14 +57,14 @@ def publish( # Check if we have a token first token = self._authenticator.get_pypi_token(repository_name) if token: - logger.debug(f"Found an API token for {repository_name}.") + logger.debug("Found an API token for %s.", repository_name) username = "__token__" password = token else: auth = self._authenticator.get_http_auth(repository_name) if auth: logger.debug( - f"Found authentication information for {repository_name}." + "Found authentication information for %s.", repository_name ) username = auth.username password = auth.password diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index a4c6b3e7267..feff82e74be 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -75,11 +75,11 @@ def solve(self, use_latest: list[str] | None = None) -> Transaction: if len(self._overrides) > 1: self._provider.debug( - f"Complete version solving took {end - start:.3f} seconds with" + f"Complete version solving took {end - start:.3f} seconds with" # noqa: PIE803 f" {len(self._overrides)} overrides" ) self._provider.debug( - "Resolved with overrides:" + "Resolved with overrides:" # noqa: PIE803 f" {', '.join(f'({b})' for b in self._overrides)}" ) @@ -99,7 +99,7 @@ def solve_in_compatibility_mode( depths = [] for override in overrides: self._provider.debug( - "Retrying dependency resolution " + "Retrying dependency resolution " # noqa: PIE803 f"with the following overrides ({override})." ) self._provider.set_overrides(override) diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index 142edb222aa..539a2d0d589 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -242,7 +242,7 @@ def request( if not is_last_attempt: attempt += 1 delay = 0.5 * attempt - logger.debug(f"Retrying HTTP request in {delay} seconds.") + logger.debug("Retrying HTTP request in %s seconds.", delay) time.sleep(delay) continue diff --git a/src/poetry/utils/password_manager.py b/src/poetry/utils/password_manager.py index 2725691a81a..9143794fb04 100644 --- a/src/poetry/utils/password_manager.py +++ b/src/poetry/utils/password_manager.py @@ -110,7 +110,7 @@ def _check(self) -> None: try: import keyring except Exception as e: - logger.debug(f"An error occurred while importing keyring: {e!s}") + logger.debug("An error occurred while importing keyring: %s", e) self._is_available = False return From 9e0d5706053b051f80b069d4bfac63286146213a Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sat, 13 Aug 2022 20:18:26 +0200 Subject: [PATCH 4/9] PIE786 --- src/poetry/console/logging/io_handler.py | 2 +- src/poetry/installation/executor.py | 2 +- src/poetry/utils/password_manager.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/poetry/console/logging/io_handler.py b/src/poetry/console/logging/io_handler.py index 213a87a3658..e759ca46af3 100644 --- a/src/poetry/console/logging/io_handler.py +++ b/src/poetry/console/logging/io_handler.py @@ -26,5 +26,5 @@ def emit(self, record: LogRecord) -> None: self._io.write_error_line(msg) else: self._io.write_line(msg) - except Exception: + except Exception: # noqa: PIE786 self.handleError(record) diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 10eedf72cb7..f540baf711c 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -254,7 +254,7 @@ def _execute_operation(self, operation: Operation) -> None: # error to be picked up by the error handler. if result == -2: raise KeyboardInterrupt - except Exception as e: + except Exception as e: # noqa: PIE786 try: from cleo.ui.exception_trace import ExceptionTrace diff --git a/src/poetry/utils/password_manager.py b/src/poetry/utils/password_manager.py index 9143794fb04..f62342568e3 100644 --- a/src/poetry/utils/password_manager.py +++ b/src/poetry/utils/password_manager.py @@ -109,7 +109,7 @@ def get_entry_name(self, name: str) -> str: def _check(self) -> None: try: import keyring - except Exception as e: + except ImportError as e: logger.debug("An error occurred while importing keyring: %s", e) self._is_available = False @@ -134,7 +134,7 @@ def _check(self) -> None: and "plaintext" not in b.name.lower() for b in backends ) - except Exception: + except ImportError: self._is_available = False if not self._is_available: From fe4638a46f697196ab079718219aa260c7265a04 Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sat, 13 Aug 2022 21:41:44 +0200 Subject: [PATCH 5/9] PIE798 --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.flake8 b/.flake8 index c2389cff812..6bb05f9c31b 100644 --- a/.flake8 +++ b/.flake8 @@ -17,6 +17,8 @@ extend-ignore = ANN101, # ANN102: Missing type annotation for cls in classmethod ANN102, + # PIE798 no-unnecessary-class: Consider using a module for namespacing instead + PIE798, per-file-ignores = # TC002: Move third-party import '...' into a type-checking block __init__.py:TC002, From 52ba5ee1a1b84ddc05578f8d256dd9dc84d29e1d Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sun, 14 Aug 2022 14:19:57 +0200 Subject: [PATCH 6/9] fix long line --- src/poetry/puzzle/solver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index feff82e74be..f798c9faea5 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -75,8 +75,8 @@ def solve(self, use_latest: list[str] | None = None) -> Transaction: if len(self._overrides) > 1: self._provider.debug( - f"Complete version solving took {end - start:.3f} seconds with" # noqa: PIE803 - f" {len(self._overrides)} overrides" + f"Complete version solving took {end - start:.3f}" # noqa: PIE803 + f" seconds with {len(self._overrides)} overrides" ) self._provider.debug( "Resolved with overrides:" # noqa: PIE803 From 8aacccb58a9346709fc7d49f31dcc3651f659681 Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sun, 14 Aug 2022 19:44:59 +0200 Subject: [PATCH 7/9] Revert "fix PIE781" This reverts commit 48dd3d7a8ab9d384541b3ed01c7b308a7a65f928. --- src/poetry/console/application.py | 9 ++++--- src/poetry/console/commands/command.py | 3 ++- src/poetry/console/commands/config.py | 4 +++- src/poetry/console/commands/debug/info.py | 3 ++- src/poetry/console/commands/plugin/add.py | 3 ++- src/poetry/console/commands/plugin/remove.py | 3 ++- src/poetry/console/commands/plugin/show.py | 3 ++- src/poetry/console/commands/run.py | 4 +++- .../console/commands/self/self_command.py | 3 ++- .../console/commands/self/show/__init__.py | 3 ++- src/poetry/console/commands/self/update.py | 3 ++- src/poetry/installation/chooser.py | 4 +++- src/poetry/installation/executor.py | 8 +++++-- .../installation/operations/operation.py | 3 ++- src/poetry/masonry/builders/editable.py | 6 +++-- src/poetry/mixology/incompatibility.py | 3 ++- src/poetry/mixology/version_solver.py | 12 ++++++---- src/poetry/packages/dependency_package.py | 3 ++- src/poetry/packages/locker.py | 3 ++- src/poetry/publishing/uploader.py | 3 ++- src/poetry/puzzle/solver.py | 4 +++- src/poetry/repositories/pypi_repository.py | 6 +++-- src/poetry/utils/authenticator.py | 3 ++- src/poetry/utils/env.py | 24 ++++++++++++------- src/poetry/utils/helpers.py | 3 ++- src/poetry/utils/password_manager.py | 3 ++- src/poetry/vcs/git/backend.py | 11 ++++++--- tests/conftest.py | 4 +++- tests/console/commands/cache/test_clear.py | 3 ++- tests/installation/test_executor.py | 4 +++- tests/installation/test_pip_installer.py | 8 +++++-- .../masonry/builders/test_editable_builder.py | 16 +++++++++---- tests/packages/test_locker.py | 4 +++- tests/plugins/test_plugin_manager.py | 4 +++- tests/utils/test_env.py | 4 +++- 35 files changed, 131 insertions(+), 56 deletions(-) diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index 5fc7f7dde48..00a9488377b 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -43,7 +43,8 @@ def _load() -> Command: words = name.split(" ") module = import_module("poetry.console.commands." + ".".join(words)) command_class = getattr(module, "".join(c.title() for c in words) + "Command") - return command_class() + command: Command = command_class() + return command return _load @@ -185,7 +186,8 @@ def _run(self, io: IO) -> int: self._load_plugins(io) - return super()._run(io) + exit_code: int = super()._run(io) + return exit_code def _configure_io(self, io: IO) -> None: # We need to check if the command being run @@ -385,7 +387,8 @@ def _get_solution_provider_repository(self) -> SolutionProviderRepository: def main() -> int: - return Application().run() + exit_code: int = Application().run() + return exit_code if __name__ == "__main__": diff --git a/src/poetry/console/commands/command.py b/src/poetry/console/commands/command.py index 6f6ac1b9ce1..4bc26ad567b 100644 --- a/src/poetry/console/commands/command.py +++ b/src/poetry/console/commands/command.py @@ -28,7 +28,8 @@ def set_poetry(self, poetry: Poetry) -> None: self._poetry = poetry def get_application(self) -> Application: - return self.application + application: Application = self.application + return application def reset_poetry(self) -> None: self.get_application().reset_poetry() diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index 33f20d9a409..03773a5ef0d 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -53,7 +53,7 @@ class ConfigCommand(Command): @property def unique_config_values(self) -> dict[str, tuple[Any, Any, Any]]: - return { + unique_config_values = { "cache-dir": ( str, lambda val: str(Path(val)), @@ -123,6 +123,8 @@ def unique_config_values(self) -> dict[str, tuple[Any, Any, Any]]: ), } + return unique_config_values + def handle(self) -> int: from pathlib import Path diff --git a/src/poetry/console/commands/debug/info.py b/src/poetry/console/commands/debug/info.py index 01dfe151001..f90d8e794d3 100644 --- a/src/poetry/console/commands/debug/info.py +++ b/src/poetry/console/commands/debug/info.py @@ -24,4 +24,5 @@ def handle(self) -> int: ) command = self.application.get("env info") - return command.run(self.io) + exit_code: int = command.run(self.io) + return exit_code diff --git a/src/poetry/console/commands/plugin/add.py b/src/poetry/console/commands/plugin/add.py index 24734056744..b59729bc76d 100644 --- a/src/poetry/console/commands/plugin/add.py +++ b/src/poetry/console/commands/plugin/add.py @@ -54,10 +54,11 @@ def handle(self) -> int: if self.option("--dry-run"): argv.append("--dry-run") - return command.run( + exit_code: int = command.run( IO( StringInput(" ".join(argv)), self.io.output, self.io.error_output, ) ) + return exit_code diff --git a/src/poetry/console/commands/plugin/remove.py b/src/poetry/console/commands/plugin/remove.py index 1791906defd..d50bfaf2ed2 100644 --- a/src/poetry/console/commands/plugin/remove.py +++ b/src/poetry/console/commands/plugin/remove.py @@ -47,10 +47,11 @@ def handle(self) -> int: if self.option("--dry-run"): argv.append("--dry-run") - return command.run( + exit_code: int = command.run( IO( StringInput(" ".join(argv)), self.io.output, self.io.error_output, ) ) + return exit_code diff --git a/src/poetry/console/commands/plugin/show.py b/src/poetry/console/commands/plugin/show.py index 2fa3c1911d3..f04ba7669c8 100644 --- a/src/poetry/console/commands/plugin/show.py +++ b/src/poetry/console/commands/plugin/show.py @@ -22,10 +22,11 @@ def handle(self) -> int: application = self.get_application() command = application.find("self show plugins") - return command.run( + exit_code: int = command.run( IO( StringInput(""), self.io.output, self.io.error_output, ) ) + return exit_code diff --git a/src/poetry/console/commands/run.py b/src/poetry/console/commands/run.py index b412a08b08a..6496b45af24 100644 --- a/src/poetry/console/commands/run.py +++ b/src/poetry/console/commands/run.py @@ -40,7 +40,9 @@ def _module(self) -> Module: poetry = self.poetry package = poetry.package path = poetry.file.parent - return Module(package.name, path.as_posix(), package.packages) + module = Module(package.name, path.as_posix(), package.packages) + + return module def run_script(self, script: str | dict[str, str], args: str) -> int: if isinstance(script, dict): diff --git a/src/poetry/console/commands/self/self_command.py b/src/poetry/console/commands/self/self_command.py index f68e72c12eb..90d6f39216f 100644 --- a/src/poetry/console/commands/self/self_command.py +++ b/src/poetry/console/commands/self/self_command.py @@ -103,7 +103,8 @@ def _system_project_handle(self) -> int: The default implementations handles cases where a `self` command delegates handling to an existing command. Eg: `SelfAddCommand(SelfCommand, AddCommand)`. """ - return super().handle() + return_code: int = super().handle() + return return_code def reset(self) -> None: """ diff --git a/src/poetry/console/commands/self/show/__init__.py b/src/poetry/console/commands/self/show/__init__.py index b13a8873d23..7212d69c7e1 100644 --- a/src/poetry/console/commands/self/show/__init__.py +++ b/src/poetry/console/commands/self/show/__init__.py @@ -30,4 +30,5 @@ def activated_groups(self) -> set[str]: if self.option("addons", False): return {SelfCommand.ADDITIONAL_PACKAGE_GROUP} - return super(ShowCommand, self).activated_groups + groups: set[str] = super(ShowCommand, self).activated_groups + return groups diff --git a/src/poetry/console/commands/self/update.py b/src/poetry/console/commands/self/update.py index d3eb7761afa..f42a3d477d8 100644 --- a/src/poetry/console/commands/self/update.py +++ b/src/poetry/console/commands/self/update.py @@ -48,10 +48,11 @@ def _system_project_handle(self) -> int: if self.option("preview"): argv.append("--allow-prereleases") - return add_command.run( + exit_code: int = add_command.run( IO( StringInput(" ".join(argv)), self.io.output, self.io.error_output, ) ) + return exit_code diff --git a/src/poetry/installation/chooser.py b/src/poetry/installation/chooser.py index cfb4ef1b7dc..600a46306ce 100644 --- a/src/poetry/installation/chooser.py +++ b/src/poetry/installation/chooser.py @@ -103,7 +103,9 @@ def choose_for(self, package: Package) -> Link: raise RuntimeError(f"Unable to find installation candidates for {package}") # Get the best link - return max(links, key=lambda link: self._sort_key(package, link)) + chosen = max(links, key=lambda link: self._sort_key(package, link)) + + return chosen def _get_links(self, package: Package) -> list[Link]: if package.source_type: diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index f540baf711c..1bde4573696 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -757,7 +757,7 @@ def _save_url_reference(self, operation: Operation) -> None: writer.writerow([str(path), "", ""]) def _create_git_url_reference(self, package: Package) -> dict[str, Any]: - return { + reference = { "url": package.source_url, "vcs_info": { "vcs": "git", @@ -768,13 +768,17 @@ def _create_git_url_reference(self, package: Package) -> dict[str, Any]: if package.source_subdirectory: reference["subdirectory"] = package.source_subdirectory + return reference + def _create_url_url_reference(self, package: Package) -> dict[str, Any]: archive_info = {} if package.name in self._hashes: archive_info["hash"] = self._hashes[package.name] - return {"url": package.source_url, "archive_info": archive_info} + reference = {"url": package.source_url, "archive_info": archive_info} + + return reference def _create_file_url_reference(self, package: Package) -> dict[str, Any]: archive_info = {} diff --git a/src/poetry/installation/operations/operation.py b/src/poetry/installation/operations/operation.py index 99c12c39632..816618a1b8d 100644 --- a/src/poetry/installation/operations/operation.py +++ b/src/poetry/installation/operations/operation.py @@ -43,7 +43,8 @@ def package(self) -> Package: raise NotImplementedError() def format_version(self, package: Package) -> str: - return package.full_pretty_version + version: str = package.full_pretty_version + return version def skip(self: T, reason: str) -> T: self._skipped = True diff --git a/src/poetry/masonry/builders/editable.py b/src/poetry/masonry/builders/editable.py index 70975887101..fac1569e67c 100644 --- a/src/poetry/masonry/builders/editable.py +++ b/src/poetry/masonry/builders/editable.py @@ -61,7 +61,8 @@ def build(self, target_dir: Path | None = None) -> Path: " - Falling back on using a setup.py" ) self._setup_build() - return self._path + path: Path = self._path + return path self._run_build_script(self._package.build_script) @@ -78,7 +79,8 @@ def build(self, target_dir: Path | None = None) -> Path: added_files += self._add_scripts() self._add_dist_info(added_files) - return self._path + path = self._path + return path def _run_build_script(self, build_script: str) -> None: with build_environment(poetry=self._poetry, env=self._env, io=self._io) as env: diff --git a/src/poetry/mixology/incompatibility.py b/src/poetry/mixology/incompatibility.py index 3f52325313a..b629ea7a699 100644 --- a/src/poetry/mixology/incompatibility.py +++ b/src/poetry/mixology/incompatibility.py @@ -435,7 +435,8 @@ def _terse(self, term: Term, allow_every: bool = False) -> str: return f"every version of {term.dependency.complete_name}" if term.dependency.is_root: - return term.dependency.pretty_name + pretty_name: str = term.dependency.pretty_name + return pretty_name if term.dependency.source_type: return str(term.dependency) diff --git a/src/poetry/mixology/version_solver.py b/src/poetry/mixology/version_solver.py index 6fa397db7f6..b520737eb70 100644 --- a/src/poetry/mixology/version_solver.py +++ b/src/poetry/mixology/version_solver.py @@ -225,7 +225,8 @@ def _propagate_incompatibility( unsatisfied.dependency, not unsatisfied.is_positive(), incompatibility ) - return unsatisfied.dependency.complete_name + complete_name: str = unsatisfied.dependency.complete_name + return complete_name def _resolve_conflict(self, incompatibility: Incompatibility) -> Incompatibility: """ @@ -413,7 +414,8 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: self._add_incompatibility( Incompatibility([Term(dependency, True)], PackageNotFoundCause(e)) ) - return dependency.complete_name + complete_name: str = dependency.complete_name + return complete_name package = None if dependency.name not in self._use_latest: @@ -441,7 +443,8 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: Incompatibility([Term(dependency, True)], NoVersionsCause()) ) - return dependency.complete_name + complete_name = dependency.complete_name + return complete_name else: package = locked @@ -469,7 +472,8 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: f" ({package.package.full_pretty_version})" ) - return dependency.complete_name + complete_name = dependency.complete_name + return complete_name def _result(self) -> SolverResult: """ diff --git a/src/poetry/packages/dependency_package.py b/src/poetry/packages/dependency_package.py index 048a5dc94b4..a06d28b65b0 100644 --- a/src/poetry/packages/dependency_package.py +++ b/src/poetry/packages/dependency_package.py @@ -43,4 +43,5 @@ def __eq__(self, other: object) -> bool: if isinstance(other, DependencyPackage): other = other.package - return self._package == other + equal: bool = self._package == other + return equal diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py index ce114b6578b..37be4e606d2 100644 --- a/src/poetry/packages/locker.py +++ b/src/poetry/packages/locker.py @@ -89,7 +89,8 @@ def is_fresh(self) -> bool: metadata = lock.get("metadata", {}) if "content-hash" in metadata: - return self._content_hash == metadata["content-hash"] + fresh: bool = self._content_hash == metadata["content-hash"] + return fresh return False diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 8adb7ecc6ae..566f50eec5e 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -61,7 +61,8 @@ def __init__(self, poetry: Poetry, io: IO) -> None: @property def user_agent(self) -> str: - return user_agent("poetry", __version__) + agent: str = user_agent("poetry", __version__) + return agent @property def adapter(self) -> adapters.HTTPAdapter: diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index f798c9faea5..0b59d7d31eb 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -211,12 +211,14 @@ def depth_first_search(source: PackageNode) -> list[list[PackageNode]]: node.visit(back_edges[node.id]) combined_nodes[node.name].append(node) - return [ + combined_topo_sorted_nodes: list[list[PackageNode]] = [ combined_nodes.pop(node.name) for node in topo_sorted_nodes if node.name in combined_nodes ] + return combined_topo_sorted_nodes + def dfs_visit( node: PackageNode, diff --git a/src/poetry/repositories/pypi_repository.py b/src/poetry/repositories/pypi_repository.py index 925a18b4c39..142b29d85d2 100644 --- a/src/poetry/repositories/pypi_repository.py +++ b/src/poetry/repositories/pypi_repository.py @@ -155,9 +155,10 @@ def get_package_info(self, name: str) -> dict[str, Any]: if self._disable_cache: return self._get_package_info(name) - return self._cache.store("packages").remember_forever( + package_info: dict[str, Any] = self._cache.store("packages").remember_forever( name, lambda: self._get_package_info(name) ) + return package_info def _get_package_info(self, name: str) -> dict[str, Any]: data = self._get(f"pypi/{name}/json") @@ -263,4 +264,5 @@ def _get(self, endpoint: str) -> dict[str, Any] | None: if json_response.status_code != 200: return None - return json_response.json() + json: dict[str, Any] = json_response.json() + return json diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index 539a2d0d589..f13e46673c8 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -145,7 +145,8 @@ def create_session(self) -> requests.Session: if not self.is_cached: return session - return CacheControl(sess=session, cache=self._cache_control) + session = CacheControl(sess=session, cache=self._cache_control) + return session def get_session(self, url: str | None = None) -> requests.Session: if not url: diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 1d508f2ceed..6c7e60deb34 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1205,7 +1205,8 @@ def version_info(self) -> tuple[Any, ...]: @property def python_implementation(self) -> str: - return self.marker_env["platform_python_implementation"] + implementation: str = self.marker_env["platform_python_implementation"] + return implementation @property def python(self) -> str: @@ -1264,7 +1265,8 @@ def get_embedded_wheel(self, distribution: str) -> Path: wheel: Wheel = get_embed_wheel( distribution, f"{self.version_info[0]}.{self.version_info[1]}" ) - return wheel.path + path: Path = wheel.path + return path @property def pip_embedded(self) -> str: @@ -1401,7 +1403,8 @@ def get_paths(self) -> dict[str, str]: raise NotImplementedError() def is_valid_for_marker(self, marker: BaseMarker) -> bool: - return marker.validate(self.marker_env) + valid: bool = marker.validate(self.marker_env) + return valid def is_sane(self) -> bool: """ @@ -1654,7 +1657,8 @@ def __init__(self, path: Path, base: Path | None = None) -> None: def sys_path(self) -> list[str]: output = self.run_python_script(GET_SYS_PATH) assert isinstance(output, str) - return json.loads(output) + paths: list[str] = json.loads(output) + return paths def get_version_info(self) -> tuple[Any, ...]: output = self.run_python_script(GET_PYTHON_VERSION) @@ -1663,7 +1667,8 @@ def get_version_info(self) -> tuple[Any, ...]: return tuple(int(s) for s in output.strip().split(".")) def get_python_implementation(self) -> str: - return self.marker_env["platform_python_implementation"] + implementation: str = self.marker_env["platform_python_implementation"] + return implementation def get_pip_command(self, embedded: bool = False) -> list[str]: # We're in a virtualenv that is known to be sane, @@ -1683,7 +1688,8 @@ def get_marker_env(self) -> dict[str, Any]: output = self.run_python_script(GET_ENVIRONMENT_INFO) assert isinstance(output, str) - return json.loads(output) + env: dict[str, Any] = json.loads(output) + return env def get_pip_version(self) -> Version: output = self.run_pip("--version") @@ -1699,7 +1705,8 @@ def get_pip_version(self) -> Version: def get_paths(self) -> dict[str, str]: output = self.run_python_script(GET_PATHS) assert isinstance(output, str) - return json.loads(output) + paths: dict[str, str] = json.loads(output) + return paths def is_venv(self) -> bool: return True @@ -1815,7 +1822,8 @@ def get_paths(self) -> dict[str, str]: output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS) assert isinstance(output, str) - return json.loads(output) + paths: dict[str, str] = json.loads(output) + return paths def execute(self, bin: str, *args: str, **kwargs: Any) -> int: command = self.get_command_from_bin(bin) + list(args) diff --git a/src/poetry/utils/helpers.py b/src/poetry/utils/helpers.py index 118a08e7ec2..432cbb6a99e 100644 --- a/src/poetry/utils/helpers.py +++ b/src/poetry/utils/helpers.py @@ -123,7 +123,8 @@ def get_package_version_display_string( path = Path(os.path.relpath(package.source_url, root.as_posix())).as_posix() return f"{package.version} {path}" - return package.full_pretty_version + pretty_version: str = package.full_pretty_version + return pretty_version def paths_csv(paths: list[Path]) -> str: diff --git a/src/poetry/utils/password_manager.py b/src/poetry/utils/password_manager.py index f62342568e3..dfb72870375 100644 --- a/src/poetry/utils/password_manager.py +++ b/src/poetry/utils/password_manager.py @@ -172,7 +172,8 @@ def set_pypi_token(self, name: str, token: str) -> None: def get_pypi_token(self, name: str) -> str | None: if not self.keyring.is_available(): - return self._config.get(f"pypi-token.{name}") + token: str | None = self._config.get(f"pypi-token.{name}") + return token return self.keyring.get_password(name, "__token__") diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index 5438af7c4a6..389ebf682dd 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -199,11 +199,12 @@ def _fetch_remote_refs(cls, url: str, local: Repo) -> FetchPackResult: client, path = get_transport_and_path(url, config=config, **kwargs) with local: - return client.fetch( + result: FetchPackResult = client.fetch( path, local, determine_wants=local.object_store.determine_wants_all, ) + return result @staticmethod def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo: @@ -239,7 +240,8 @@ def _clone_legacy(url: str, refspec: GitRefSpec, target: Path) -> Repo: f"Failed to checkout {url} at '{revision}'" ) - return Repo(str(target)) + repo = Repo(str(target)) + return repo @classmethod def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo: @@ -356,7 +358,10 @@ def _clone_submodules(cls, repo: Repo) -> None: def is_using_legacy_client() -> bool: from poetry.config.config import Config - return Config.create().get("experimental", {}).get("system-git-client", False) + legacy_client: bool = ( + Config.create().get("experimental", {}).get("system-git-client", False) + ) + return legacy_client @staticmethod def get_default_source_root() -> Path: diff --git a/tests/conftest.py b/tests/conftest.py index 01dd8a4a3b8..4e529ec0487 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -186,7 +186,9 @@ def config_source(config_cache_dir: Path) -> DictConfigSource: @pytest.fixture def auth_config_source() -> DictConfigSource: - return DictConfigSource() + source = DictConfigSource() + + return source @pytest.fixture(autouse=True) diff --git a/tests/console/commands/cache/test_clear.py b/tests/console/commands/cache/test_clear.py index 60ae6d2ea7e..ce0243f4ac8 100644 --- a/tests/console/commands/cache/test_clear.py +++ b/tests/console/commands/cache/test_clear.py @@ -19,7 +19,8 @@ def tester() -> ApplicationTester: app = Application() - return ApplicationTester(app) + tester = ApplicationTester(app) + return tester def test_cache_clear_all( diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 82a91bb6d32..7f60905a33c 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -66,7 +66,9 @@ def io_decorated() -> BufferedIO: @pytest.fixture() def io_not_decorated() -> BufferedIO: - return BufferedIO(decorated=False) + io = BufferedIO(decorated=False) + + return io @pytest.fixture() diff --git a/tests/installation/test_pip_installer.py b/tests/installation/test_pip_installer.py index 0de55809fa2..4763d71bb42 100644 --- a/tests/installation/test_pip_installer.py +++ b/tests/installation/test_pip_installer.py @@ -27,7 +27,7 @@ @pytest.fixture def package_git() -> Package: - return Package( + package = Package( "demo", "1.0.0", source_type="git", @@ -35,10 +35,12 @@ def package_git() -> Package: source_reference="master", ) + return package + @pytest.fixture def package_git_with_subdirectory() -> Package: - return Package( + package = Package( "subdirectories", "2.0.0", source_type="git", @@ -47,6 +49,8 @@ def package_git_with_subdirectory() -> Package: source_subdirectory="two", ) + return package + @pytest.fixture def pool() -> Pool: diff --git a/tests/masonry/builders/test_editable_builder.py b/tests/masonry/builders/test_editable_builder.py index 6e21c9441cc..87c0c676f62 100644 --- a/tests/masonry/builders/test_editable_builder.py +++ b/tests/masonry/builders/test_editable_builder.py @@ -31,33 +31,41 @@ @pytest.fixture() def simple_poetry() -> Poetry: - return Factory().create_poetry( + poetry = Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "simple_project" ) + return poetry + @pytest.fixture() def project_with_include() -> Poetry: - return Factory().create_poetry( + poetry = Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "with-include" ) + return poetry + @pytest.fixture() def extended_poetry() -> Poetry: - return Factory().create_poetry( + poetry = Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "extended_project" ) + return poetry + @pytest.fixture() def extended_without_setup_poetry() -> Poetry: - return Factory().create_poetry( + poetry = Factory().create_poetry( Path(__file__).parent.parent.parent / "fixtures" / "extended_project_without_setup" ) + return poetry + @pytest.fixture() def env_manager(simple_poetry: Poetry) -> EnvManager: diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index e655cb04ae1..e0ed720bf94 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -33,7 +33,9 @@ def locker() -> Locker: with tempfile.NamedTemporaryFile() as f: f.close() - return Locker(f.name, {}) + locker = Locker(f.name, {}) + + return locker @pytest.fixture diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index d5dc0d9dde8..868d61f26f0 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -48,7 +48,7 @@ def activate(self, poetry: Poetry, io: BufferedIO) -> None: @pytest.fixture() def poetry(tmp_dir: str, config: Config) -> Poetry: - return Poetry( + poetry = Poetry( CWD / "pyproject.toml", {}, ProjectPackage("simple-project", "1.2.3"), @@ -56,6 +56,8 @@ def poetry(tmp_dir: str, config: Config) -> Poetry: config, ) + return poetry + @pytest.fixture() def io() -> BufferedIO: diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 8c1bbf36989..03c1e4c29ff 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -1371,10 +1371,12 @@ def test_generate_env_name_uses_real_path(tmp_dir: str, mocker: MockerFixture): @pytest.fixture() def extended_without_setup_poetry() -> Poetry: - return Factory().create_poetry( + poetry = Factory().create_poetry( Path(__file__).parent.parent / "fixtures" / "extended_project_without_setup" ) + return poetry + def test_build_environment_called_build_script_specified( mocker: MockerFixture, extended_without_setup_poetry: Poetry, tmp_dir: str From fb643a22e4fc8d8276c5cd047a901de4e72c3b94 Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sun, 14 Aug 2022 19:46:37 +0200 Subject: [PATCH 8/9] ignore PIE781 altogether --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.flake8 b/.flake8 index 6bb05f9c31b..2d16cf2abc3 100644 --- a/.flake8 +++ b/.flake8 @@ -17,6 +17,8 @@ extend-ignore = ANN101, # ANN102: Missing type annotation for cls in classmethod ANN102, + # PIE781: assign-and-return + PIE781, # PIE798 no-unnecessary-class: Consider using a module for namespacing instead PIE798, per-file-ignores = From 2343437be1334aa820fa1252a7910a002db5c6ec Mon Sep 17 00:00:00 2001 From: Alp Aribal Date: Sun, 21 Aug 2022 23:27:31 +0200 Subject: [PATCH 9/9] add explanation about noqa --- src/poetry/puzzle/solver.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index 0b59d7d31eb..d519e530004 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -75,10 +75,12 @@ def solve(self, use_latest: list[str] | None = None) -> Transaction: if len(self._overrides) > 1: self._provider.debug( + # ignore the warning as provider does not do interpolation f"Complete version solving took {end - start:.3f}" # noqa: PIE803 f" seconds with {len(self._overrides)} overrides" ) self._provider.debug( + # ignore the warning as provider does not do interpolation "Resolved with overrides:" # noqa: PIE803 f" {', '.join(f'({b})' for b in self._overrides)}" ) @@ -99,6 +101,7 @@ def solve_in_compatibility_mode( depths = [] for override in overrides: self._provider.debug( + # ignore the warning as provider does not do interpolation "Retrying dependency resolution " # noqa: PIE803 f"with the following overrides ({override})." )