Skip to content

Commit

Permalink
ABC (Abstract Base Class) fixups (#9719)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSven73 authored Sep 29, 2024
1 parent cb43217 commit 65ccfb2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
12 changes: 7 additions & 5 deletions src/poetry/config/config_source.py
Original file line number Diff line number Diff line change
@@ -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: ...
9 changes: 6 additions & 3 deletions src/poetry/console/logging/formatters/formatter.py
Original file line number Diff line number Diff line change
@@ -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: ...
12 changes: 7 additions & 5 deletions src/poetry/installation/operations/operation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from abc import ABC
from abc import abstractmethod
from typing import TYPE_CHECKING


Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/plugins/base_plugin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,4 +19,3 @@ def group(self) -> str:
"""
Name of entrypoint group the plugin belongs to.
"""
raise NotImplementedError()
3 changes: 1 addition & 2 deletions src/poetry/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
24 changes: 13 additions & 11 deletions src/poetry/utils/env/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +34,7 @@
PythonVersion = Tuple[int, int, int, str, int]


class Env:
class Env(ABC):
"""
An abstract Python environment.
"""
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -262,20 +264,20 @@ 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():
return [str(self.python), str(self.pip_embedded)]
# 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)
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 65ccfb2

Please sign in to comment.