diff --git a/src/poetry/config/config_source.py b/src/poetry/config/config_source.py index ed97fa9176a..ae9da9da050 100644 --- a/src/poetry/config/config_source.py +++ b/src/poetry/config/config_source.py @@ -1,11 +1,13 @@ from __future__ import annotations +from abc import ABC +from abc import abstractmethod from typing import Any -class ConfigSource: - def add_property(self, key: str, value: Any) -> None: - raise NotImplementedError() +class ConfigSource(ABC): + @abstractmethod + def add_property(self, key: str, value: Any) -> None: ... - def remove_property(self, key: str) -> None: - raise NotImplementedError() + @abstractmethod + def remove_property(self, key: str) -> None: ... diff --git a/src/poetry/console/logging/formatters/formatter.py b/src/poetry/console/logging/formatters/formatter.py index d18002be4b7..4d0f1302bab 100644 --- a/src/poetry/console/logging/formatters/formatter.py +++ b/src/poetry/console/logging/formatters/formatter.py @@ -1,6 +1,9 @@ from __future__ import annotations +from abc import ABC +from abc import abstractmethod -class Formatter: - def format(self, msg: str) -> str: - raise NotImplementedError() + +class Formatter(ABC): + @abstractmethod + def format(self, msg: str) -> str: ... diff --git a/src/poetry/installation/operations/operation.py b/src/poetry/installation/operations/operation.py index 21c0cfa133f..824da8b852e 100644 --- a/src/poetry/installation/operations/operation.py +++ b/src/poetry/installation/operations/operation.py @@ -1,5 +1,7 @@ from __future__ import annotations +from abc import ABC +from abc import abstractmethod from typing import TYPE_CHECKING @@ -8,7 +10,7 @@ from typing_extensions import Self -class Operation: +class Operation(ABC): def __init__(self, reason: str | None = None, priority: float = 0) -> None: self._reason = reason @@ -17,8 +19,8 @@ def __init__(self, reason: str | None = None, priority: float = 0) -> None: self._priority = priority @property - def job_type(self) -> str: - raise NotImplementedError + @abstractmethod + def job_type(self) -> str: ... @property def reason(self) -> str | None: @@ -37,8 +39,8 @@ def priority(self) -> float: return self._priority @property - def package(self) -> Package: - raise NotImplementedError() + @abstractmethod + def package(self) -> Package: ... def format_version(self, package: Package) -> str: version: str = package.full_pretty_version diff --git a/src/poetry/plugins/base_plugin.py b/src/poetry/plugins/base_plugin.py index 07146060746..4df1c984621 100644 --- a/src/poetry/plugins/base_plugin.py +++ b/src/poetry/plugins/base_plugin.py @@ -1,9 +1,10 @@ from __future__ import annotations +from abc import ABC from abc import abstractmethod -class BasePlugin: +class BasePlugin(ABC): """ Base class for all plugin types @@ -18,4 +19,3 @@ def group(self) -> str: """ Name of entrypoint group the plugin belongs to. """ - raise NotImplementedError() diff --git a/src/poetry/plugins/plugin.py b/src/poetry/plugins/plugin.py index ea72662c3c2..0e00bbba3c5 100644 --- a/src/poetry/plugins/plugin.py +++ b/src/poetry/plugins/plugin.py @@ -20,5 +20,4 @@ class Plugin(BasePlugin): group = "poetry.plugin" @abstractmethod - def activate(self, poetry: Poetry, io: IO) -> None: - raise NotImplementedError() + def activate(self, poetry: Poetry, io: IO) -> None: ... diff --git a/src/poetry/utils/env/base_env.py b/src/poetry/utils/env/base_env.py index 5a8f2fc6146..79cfec600a0 100644 --- a/src/poetry/utils/env/base_env.py +++ b/src/poetry/utils/env/base_env.py @@ -7,6 +7,8 @@ import sys import sysconfig +from abc import ABC +from abc import abstractmethod from functools import cached_property from pathlib import Path from subprocess import CalledProcessError @@ -32,7 +34,7 @@ PythonVersion = Tuple[int, int, int, str, int] -class Env: +class Env(ABC): """ An abstract Python environment. """ @@ -223,8 +225,8 @@ def is_path_relative_to_lib(self, path: Path) -> bool: return False @property - def sys_path(self) -> list[str]: - raise NotImplementedError() + @abstractmethod + def sys_path(self) -> list[str]: ... @property def paths(self) -> dict[str, str]: @@ -262,8 +264,8 @@ def get_base_prefix(cls) -> Path: return Path(sys.prefix) - def get_marker_env(self) -> dict[str, Any]: - raise NotImplementedError() + @abstractmethod + def get_marker_env(self) -> dict[str, Any]: ... def get_pip_command(self, embedded: bool = False) -> list[str]: if embedded or not Path(self._bin(self._pip_executable)).exists(): @@ -271,11 +273,11 @@ def get_pip_command(self, embedded: bool = False) -> list[str]: # run as module so that pip can update itself on Windows return [str(self.python), "-m", "pip"] - def get_supported_tags(self) -> list[Tag]: - raise NotImplementedError() + @abstractmethod + def get_supported_tags(self) -> list[Tag]: ... - def get_paths(self) -> dict[str, str]: - raise NotImplementedError() + @abstractmethod + def get_paths(self) -> dict[str, str]: ... def is_valid_for_marker(self, marker: BaseMarker) -> bool: valid: bool = marker.validate(self.marker_env) @@ -351,8 +353,8 @@ def execute(self, bin: str, *args: str, **kwargs: Any) -> int: exe.communicate() return exe.returncode - def is_venv(self) -> bool: - raise NotImplementedError() + @abstractmethod + def is_venv(self) -> bool: ... @property def script_dirs(self) -> list[Path]: