Loading behave_utils/behave.py +3 −2 Original line number Diff line number Diff line Loading @@ -27,8 +27,9 @@ __all__ = [ if TYPE_CHECKING: from typing_extensions import Self T = TypeVar("T") C = TypeVar("C", bound="PatternEnum") class PatternConverter(Protocol): Loading Loading @@ -112,5 +113,5 @@ class PatternEnum(enum.Enum, metaclass=EnumMeta): """ @classmethod def _missing_(cls: type[C], key: Any) -> C: def _missing_(cls, key: Any) -> Self: return cls[key] behave_utils/docker.py +8 −13 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ from typing import TYPE_CHECKING from typing import Any from typing import NewType from typing import Protocol from typing import TypeVar from typing import Union from typing import cast from urllib.parse import urlparse Loading @@ -55,6 +54,9 @@ from .proc import MutableArguments from .proc import exec_io from .utils import wait if TYPE_CHECKING: from typing_extensions import Self LOCALHOST = ipaddress.IPv4Address(0x7f000001) ShaID = NewType("ShaID", str) Loading Loading @@ -152,10 +154,8 @@ class IPv4Address(ipaddress.IPv4Address): Subclass of IPv4Address that handle's docker idiosyncratic tendency to add a mask suffix """ T = TypeVar("T", bound="IPv4Address") @classmethod def with_suffix(cls: type[T], address: str) -> T: def with_suffix(cls, address: str) -> Self: """ Construct an instance with a suffixed bitmask size """ Loading Loading @@ -190,13 +190,11 @@ class Image: _cache = dict[str, ShaID]() T = TypeVar('T', bound='Image') def __init__(self, iid: ShaID): self.iid = iid @classmethod def build(cls: type[T], context: Path, target: str = "", **build_args: str|None) -> T: def build(cls, context: Path, target: str = "", **build_args: str|None) -> Self: """ Build an image from the given context Loading @@ -217,7 +215,7 @@ class Image: return cls(iid) @classmethod def pull(cls: type[T], repository: str) -> T: def pull(cls, repository: str) -> Self: """ Pull an image from a registry """ Loading Loading @@ -253,9 +251,6 @@ class Container: exiting the context. """ if TYPE_CHECKING: T = TypeVar('T', bound='Container') DEFAULT_ALIASES = tuple[str]() def __init__( Loading Loading @@ -286,7 +281,7 @@ class Container: if network: self.connect(network, *self.DEFAULT_ALIASES) def __enter__(self: T) -> T: def __enter__(self) -> Self: return self def __exit__(self, etype: type[BaseException], exc: BaseException, tb: TracebackType) -> None: Loading @@ -298,7 +293,7 @@ class Container: logging.getLogger(__name__).exception("ignoring exception while stopping") @contextmanager def started(self: T) -> Iterator[T]: def started(self) -> Iterator[Self]: """ Return a context manager that ensures the container is started when the context is entered """ Loading behave_utils/json.py +6 −6 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ from __future__ import annotations from collections.abc import Callable from types import GenericAlias from typing import TYPE_CHECKING from typing import Any from typing import TypeVar from typing import overload Loading @@ -19,6 +20,9 @@ from typing import overload import orjson from jsonpath import JSONPath if TYPE_CHECKING: from typing_extensions import Self __all__ = [ "JSONObject", "JSONArray", Loading Loading @@ -57,10 +61,8 @@ class JSONObject(JSONPathMixin, dict[str, Any]): A dict for JSON objects that implements `.path` for getting child items by a JSON path """ T = TypeVar("T", bound="JSONObject") @classmethod def from_string(cls: type[T], string: bytes) -> T: def from_string(cls, string: bytes) -> Self: """ Create a JSONObject from a JSON string """ Loading @@ -75,10 +77,8 @@ class JSONArray(JSONPathMixin, list[Any]): A list for JSON arrays that implements `.path` for getting child items by a JSON path """ T = TypeVar("T", bound="JSONArray") @classmethod def from_string(cls: type[T], string: bytes) -> T: def from_string(cls, string: bytes) -> Self: """ Create a JSONArray from a JSON string """ Loading behave_utils/proc.py +4 −4 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ from warnings import warn import trio.abc if TYPE_CHECKING: from typing_extensions import Self T = TypeVar('T') Deserialiser = Callable[[memoryview], T] Loading Loading @@ -224,9 +227,6 @@ async def _passthru(in_stream: trio.abc.ReceiveStream, out_stream: IO[str]|IO[by class _ExecutorBase(list[Argument]): if TYPE_CHECKING: E = TypeVar("E", bound="_ExecutorBase") def __init__(self, *cmd: Argument): self[:] = cmd Loading @@ -243,7 +243,7 @@ class _ExecutorBase(list[Argument]): """ return cmd def subcommand(self: E, *args: Argument) -> E: def subcommand(self, *args: Argument) -> Self: """ Return a new Executor instance of the same class with additional arguments appended Loading Loading
behave_utils/behave.py +3 −2 Original line number Diff line number Diff line Loading @@ -27,8 +27,9 @@ __all__ = [ if TYPE_CHECKING: from typing_extensions import Self T = TypeVar("T") C = TypeVar("C", bound="PatternEnum") class PatternConverter(Protocol): Loading Loading @@ -112,5 +113,5 @@ class PatternEnum(enum.Enum, metaclass=EnumMeta): """ @classmethod def _missing_(cls: type[C], key: Any) -> C: def _missing_(cls, key: Any) -> Self: return cls[key]
behave_utils/docker.py +8 −13 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ from typing import TYPE_CHECKING from typing import Any from typing import NewType from typing import Protocol from typing import TypeVar from typing import Union from typing import cast from urllib.parse import urlparse Loading @@ -55,6 +54,9 @@ from .proc import MutableArguments from .proc import exec_io from .utils import wait if TYPE_CHECKING: from typing_extensions import Self LOCALHOST = ipaddress.IPv4Address(0x7f000001) ShaID = NewType("ShaID", str) Loading Loading @@ -152,10 +154,8 @@ class IPv4Address(ipaddress.IPv4Address): Subclass of IPv4Address that handle's docker idiosyncratic tendency to add a mask suffix """ T = TypeVar("T", bound="IPv4Address") @classmethod def with_suffix(cls: type[T], address: str) -> T: def with_suffix(cls, address: str) -> Self: """ Construct an instance with a suffixed bitmask size """ Loading Loading @@ -190,13 +190,11 @@ class Image: _cache = dict[str, ShaID]() T = TypeVar('T', bound='Image') def __init__(self, iid: ShaID): self.iid = iid @classmethod def build(cls: type[T], context: Path, target: str = "", **build_args: str|None) -> T: def build(cls, context: Path, target: str = "", **build_args: str|None) -> Self: """ Build an image from the given context Loading @@ -217,7 +215,7 @@ class Image: return cls(iid) @classmethod def pull(cls: type[T], repository: str) -> T: def pull(cls, repository: str) -> Self: """ Pull an image from a registry """ Loading Loading @@ -253,9 +251,6 @@ class Container: exiting the context. """ if TYPE_CHECKING: T = TypeVar('T', bound='Container') DEFAULT_ALIASES = tuple[str]() def __init__( Loading Loading @@ -286,7 +281,7 @@ class Container: if network: self.connect(network, *self.DEFAULT_ALIASES) def __enter__(self: T) -> T: def __enter__(self) -> Self: return self def __exit__(self, etype: type[BaseException], exc: BaseException, tb: TracebackType) -> None: Loading @@ -298,7 +293,7 @@ class Container: logging.getLogger(__name__).exception("ignoring exception while stopping") @contextmanager def started(self: T) -> Iterator[T]: def started(self) -> Iterator[Self]: """ Return a context manager that ensures the container is started when the context is entered """ Loading
behave_utils/json.py +6 −6 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ from __future__ import annotations from collections.abc import Callable from types import GenericAlias from typing import TYPE_CHECKING from typing import Any from typing import TypeVar from typing import overload Loading @@ -19,6 +20,9 @@ from typing import overload import orjson from jsonpath import JSONPath if TYPE_CHECKING: from typing_extensions import Self __all__ = [ "JSONObject", "JSONArray", Loading Loading @@ -57,10 +61,8 @@ class JSONObject(JSONPathMixin, dict[str, Any]): A dict for JSON objects that implements `.path` for getting child items by a JSON path """ T = TypeVar("T", bound="JSONObject") @classmethod def from_string(cls: type[T], string: bytes) -> T: def from_string(cls, string: bytes) -> Self: """ Create a JSONObject from a JSON string """ Loading @@ -75,10 +77,8 @@ class JSONArray(JSONPathMixin, list[Any]): A list for JSON arrays that implements `.path` for getting child items by a JSON path """ T = TypeVar("T", bound="JSONArray") @classmethod def from_string(cls: type[T], string: bytes) -> T: def from_string(cls, string: bytes) -> Self: """ Create a JSONArray from a JSON string """ Loading
behave_utils/proc.py +4 −4 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ from warnings import warn import trio.abc if TYPE_CHECKING: from typing_extensions import Self T = TypeVar('T') Deserialiser = Callable[[memoryview], T] Loading Loading @@ -224,9 +227,6 @@ async def _passthru(in_stream: trio.abc.ReceiveStream, out_stream: IO[str]|IO[by class _ExecutorBase(list[Argument]): if TYPE_CHECKING: E = TypeVar("E", bound="_ExecutorBase") def __init__(self, *cmd: Argument): self[:] = cmd Loading @@ -243,7 +243,7 @@ class _ExecutorBase(list[Argument]): """ return cmd def subcommand(self: E, *args: Argument) -> E: def subcommand(self, *args: Argument) -> Self: """ Return a new Executor instance of the same class with additional arguments appended Loading