Skip to content

Commit

Permalink
post-rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FasterSpeeding committed Nov 18, 2024
1 parent ef67886 commit c83f986
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 52 deletions.
8 changes: 4 additions & 4 deletions alluka/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ class InjectedTypes(int, enum.Enum):
"""


InjectedTuple = typing.Union[
tuple[typing.Literal[InjectedTypes.CALLBACK], InjectedCallback],
tuple[typing.Literal[InjectedTypes.TYPE], InjectedType],
]
InjectedTuple = (
tuple[typing.Literal[InjectedTypes.CALLBACK], InjectedCallback]
| tuple[typing.Literal[InjectedTypes.TYPE], InjectedType]
)
"""Type of the tuple used to describe an injected value."""

_TypeT = type[_T]
Expand Down
39 changes: 18 additions & 21 deletions alluka/managed/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,16 @@
from collections import abc as collections

if typing.TYPE_CHECKING:
import typing_extensions
from typing_extensions import Self
from typing import Self

_P = typing_extensions.ParamSpec("_P")
_P = typing.ParamSpec("_P")
_CoroT = collections.Coroutine[typing.Any, typing.Any, "_T"]


_T = typing.TypeVar("_T")
_OtherT = typing.TypeVar("_OtherT")
_DictKeyT = typing.Union[str, int, float, bool, None]
_DictValueT = typing.Union[
collections.Mapping[_DictKeyT, "_DictValueT"], collections.Sequence["_DictValueT"], _DictKeyT
]
_DictKeyT = str | int | float | bool | None
_DictValueT = collections.Mapping[_DictKeyT, "_DictValueT"] | collections.Sequence["_DictValueT"] | _DictKeyT


class TypeConfig(typing.Generic[_T]):
Expand All @@ -68,10 +65,10 @@ def __init__(
name: str,
/,
*,
async_cleanup: typing.Optional[collections.Callable[[_T], _CoroT[None]]] = None,
async_cleanup: collections.Callable[[_T], _CoroT[None]] | None = None,
async_create: collections.Callable[..., _CoroT[_T]],
cleanup: typing.Optional[collections.Callable[[_T], None]] = None,
create: typing.Optional[collections.Callable[..., _T]] = None,
cleanup: collections.Callable[[_T], None] | None = None,
create: collections.Callable[..., _T] | None = None,
) -> None: ...

@typing.overload
Expand All @@ -81,9 +78,9 @@ def __init__(
name: str,
/,
*,
async_cleanup: typing.Optional[collections.Callable[[_T], _CoroT[None]]] = None,
async_create: typing.Optional[collections.Callable[..., _CoroT[_T]]] = None,
cleanup: typing.Optional[collections.Callable[[_T], None]] = None,
async_cleanup: collections.Callable[[_T], _CoroT[None]] | None = None,
async_create: collections.Callable[..., _CoroT[_T]] | None = None,
cleanup: collections.Callable[[_T], None] | None = None,
create: collections.Callable[..., _T],
) -> None: ...

Expand All @@ -93,10 +90,10 @@ def __init__(
name: str,
/,
*,
async_cleanup: typing.Optional[collections.Callable[[_T], _CoroT[None]]] = None,
async_create: typing.Optional[collections.Callable[..., _CoroT[_T]]] = None,
cleanup: typing.Optional[collections.Callable[[_T], None]] = None,
create: typing.Optional[collections.Callable[..., _T]] = None,
async_cleanup: collections.Callable[[_T], _CoroT[None]] | None = None,
async_create: collections.Callable[..., _CoroT[_T]] | None = None,
cleanup: collections.Callable[[_T], None] | None = None,
create: collections.Callable[..., _T] | None = None,
) -> None:
"""Initialise a type config.
Expand Down Expand Up @@ -184,22 +181,22 @@ def decorator(callback: collections.Callable[..., _CoroT[_OtherT]], /) -> TypeCo
return decorator

@property
def async_cleanup(self) -> typing.Optional[collections.Callable[[_T], _CoroT[None]]]:
def async_cleanup(self) -> collections.Callable[[_T], _CoroT[None]] | None:
"""Callback used to use to cleanup the dependency in an async runtime."""
return self._async_cleanup

@property
def async_create(self) -> typing.Optional[collections.Callable[..., _CoroT[_T]]]:
def async_create(self) -> collections.Callable[..., _CoroT[_T]] | None:
"""Callback used to use to create the dependency in an async runtime."""
return self._async_create

@property
def cleanup(self) -> typing.Optional[collections.Callable[[_T], None]]:
def cleanup(self) -> collections.Callable[[_T], None] | None:
"""Callback used to use to cleanup the dependency in a sync runtime."""
return self._cleanup

@property
def create(self) -> typing.Optional[collections.Callable[..., _T]]:
def create(self) -> collections.Callable[..., _T] | None:
"""Callback used to use to create the dependency in an async runtime."""
return self._create

Expand Down
12 changes: 4 additions & 8 deletions alluka/managed/_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
_LOGGER = logging.getLogger("alluka.managed")

_T = typing.TypeVar("_T")
_DictKeyT = typing.Union[str, int, float, bool, None]
_DictValueT = typing.Union[
collections.Mapping[_DictKeyT, "_DictValueT"], collections.Sequence["_DictValueT"], _DictKeyT
]
_DictKeyT = str | int | float | bool | None
_DictValueT = collections.Mapping[_DictKeyT, "_DictValueT"] | collections.Sequence["_DictValueT"] | _DictKeyT


_ENTRY_POINT_GROUP_NAME = "alluka.managed"
Expand Down Expand Up @@ -153,9 +151,7 @@ def set_descriptors(
"""
self._descriptors[callback] = descriptors

def get_descriptors(
self, callback: alluka.CallbackSig[typing.Any], /
) -> typing.Optional[dict[str, _types.InjectedTuple]]:
def get_descriptors(self, callback: alluka.CallbackSig[typing.Any], /) -> dict[str, _types.InjectedTuple] | None:
"""Get the dependency injection descriptors cached for a callback.
Parameters
Expand Down Expand Up @@ -258,7 +254,7 @@ def _scan_libraries(self) -> None:
_LOGGER.debug("Registering TypeConfig from %r", entry_point)
continue

_LOGGER.warn(
_LOGGER.warning(
"Unexpected value found at %, expected a PluginConfig class but found %r. "
"An alluka entry point is misconfigured.",
entry_point.value,
Expand Down
30 changes: 11 additions & 19 deletions alluka/managed/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import json
import logging
import pathlib
import tomllib
import typing
import weakref
from collections import abc as collections
Expand All @@ -47,30 +48,19 @@
from . import _index

if typing.TYPE_CHECKING:
from typing_extensions import Self
from typing import Self


_LOGGER = logging.getLogger("alluka.managed")

_DictKeyT = typing.Union[str, int, float, bool, None]
_DictValueT = typing.Union[
collections.Mapping[_DictKeyT, "_DictValueT"], collections.Sequence["_DictValueT"], _DictKeyT
]
_DictKeyT = str | int | float | bool | None
_DictValueT = collections.Mapping[_DictKeyT, "_DictValueT"] | collections.Sequence["_DictValueT"] | _DictKeyT
_PARSERS: dict[str, collections.Callable[[typing.BinaryIO], collections.Mapping[_DictKeyT, _DictValueT]]] = {
"json": json.load
"json": json.load,
"toml": tomllib.load,
}


try:
import tomllib # pyright: ignore[reportMissingImports]

except ModuleNotFoundError:
pass

else:
_PARSERS["toml"] = tomllib.load # type: ignore


class Manager:
"""A type dependency lifetime manager implementation.
Expand All @@ -93,7 +83,7 @@ def __init__(self, client: abc.Client, /) -> None:
self._load_types: dict[type[typing.Any], _config.TypeConfig[typing.Any]] = {}
self._processed_callbacks: weakref.WeakSet[collections.Callable[..., typing.Any]] = weakref.WeakSet()

def load_config(self, config: typing.Union[pathlib.Path, _config.ConfigFile], /) -> Self:
def load_config(self, config: pathlib.Path | _config.ConfigFile, /) -> Self:
"""Load plugin and dependency configuration into this manager.
Parameters
Expand Down Expand Up @@ -143,7 +133,7 @@ def load_config(self, config: typing.Union[pathlib.Path, _config.ConfigFile], /)
return self

def _to_resolvers(
self, type_id: typing.Union[str, type[typing.Any]], /, *, mimo: typing.Optional[set[type[typing.Any]]] = None
self, type_id: str | type[typing.Any], /, *, mimo: set[type[typing.Any]] | None = None
) -> collections.Iterator[_config.TypeConfig[typing.Any]]:
if mimo is None:
mimo = set()
Expand Down Expand Up @@ -184,7 +174,9 @@ def load_deps(self) -> None:
self._client.set_type_dependency(type_info.dep_type, value)

else:
_LOGGER.warn("Type dependency %r skipped as it can only be created in an async context", type_info.name)
_LOGGER.warning(
"Type dependency %r skipped as it can only be created in an async context", type_info.name
)

async def load_deps_async(self) -> None: # noqa: ASYNC910
"""Initialise the configured dependencies asynchronously.
Expand Down

0 comments on commit c83f986

Please sign in to comment.