Skip to content

Commit c83f986

Browse files
post-rebase fixes
1 parent ef67886 commit c83f986

File tree

4 files changed

+37
-52
lines changed

4 files changed

+37
-52
lines changed

alluka/_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ class InjectedTypes(int, enum.Enum):
198198
"""
199199

200200

201-
InjectedTuple = typing.Union[
202-
tuple[typing.Literal[InjectedTypes.CALLBACK], InjectedCallback],
203-
tuple[typing.Literal[InjectedTypes.TYPE], InjectedType],
204-
]
201+
InjectedTuple = (
202+
tuple[typing.Literal[InjectedTypes.CALLBACK], InjectedCallback]
203+
| tuple[typing.Literal[InjectedTypes.TYPE], InjectedType]
204+
)
205205
"""Type of the tuple used to describe an injected value."""
206206

207207
_TypeT = type[_T]

alluka/managed/_config.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@
3737
from collections import abc as collections
3838

3939
if typing.TYPE_CHECKING:
40-
import typing_extensions
41-
from typing_extensions import Self
40+
from typing import Self
4241

43-
_P = typing_extensions.ParamSpec("_P")
42+
_P = typing.ParamSpec("_P")
4443
_CoroT = collections.Coroutine[typing.Any, typing.Any, "_T"]
4544

4645

4746
_T = typing.TypeVar("_T")
4847
_OtherT = typing.TypeVar("_OtherT")
49-
_DictKeyT = typing.Union[str, int, float, bool, None]
50-
_DictValueT = typing.Union[
51-
collections.Mapping[_DictKeyT, "_DictValueT"], collections.Sequence["_DictValueT"], _DictKeyT
52-
]
48+
_DictKeyT = str | int | float | bool | None
49+
_DictValueT = collections.Mapping[_DictKeyT, "_DictValueT"] | collections.Sequence["_DictValueT"] | _DictKeyT
5350

5451

5552
class TypeConfig(typing.Generic[_T]):
@@ -68,10 +65,10 @@ def __init__(
6865
name: str,
6966
/,
7067
*,
71-
async_cleanup: typing.Optional[collections.Callable[[_T], _CoroT[None]]] = None,
68+
async_cleanup: collections.Callable[[_T], _CoroT[None]] | None = None,
7269
async_create: collections.Callable[..., _CoroT[_T]],
73-
cleanup: typing.Optional[collections.Callable[[_T], None]] = None,
74-
create: typing.Optional[collections.Callable[..., _T]] = None,
70+
cleanup: collections.Callable[[_T], None] | None = None,
71+
create: collections.Callable[..., _T] | None = None,
7572
) -> None: ...
7673

7774
@typing.overload
@@ -81,9 +78,9 @@ def __init__(
8178
name: str,
8279
/,
8380
*,
84-
async_cleanup: typing.Optional[collections.Callable[[_T], _CoroT[None]]] = None,
85-
async_create: typing.Optional[collections.Callable[..., _CoroT[_T]]] = None,
86-
cleanup: typing.Optional[collections.Callable[[_T], None]] = None,
81+
async_cleanup: collections.Callable[[_T], _CoroT[None]] | None = None,
82+
async_create: collections.Callable[..., _CoroT[_T]] | None = None,
83+
cleanup: collections.Callable[[_T], None] | None = None,
8784
create: collections.Callable[..., _T],
8885
) -> None: ...
8986

@@ -93,10 +90,10 @@ def __init__(
9390
name: str,
9491
/,
9592
*,
96-
async_cleanup: typing.Optional[collections.Callable[[_T], _CoroT[None]]] = None,
97-
async_create: typing.Optional[collections.Callable[..., _CoroT[_T]]] = None,
98-
cleanup: typing.Optional[collections.Callable[[_T], None]] = None,
99-
create: typing.Optional[collections.Callable[..., _T]] = None,
93+
async_cleanup: collections.Callable[[_T], _CoroT[None]] | None = None,
94+
async_create: collections.Callable[..., _CoroT[_T]] | None = None,
95+
cleanup: collections.Callable[[_T], None] | None = None,
96+
create: collections.Callable[..., _T] | None = None,
10097
) -> None:
10198
"""Initialise a type config.
10299
@@ -184,22 +181,22 @@ def decorator(callback: collections.Callable[..., _CoroT[_OtherT]], /) -> TypeCo
184181
return decorator
185182

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

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

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

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

alluka/managed/_index.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@
5252
_LOGGER = logging.getLogger("alluka.managed")
5353

5454
_T = typing.TypeVar("_T")
55-
_DictKeyT = typing.Union[str, int, float, bool, None]
56-
_DictValueT = typing.Union[
57-
collections.Mapping[_DictKeyT, "_DictValueT"], collections.Sequence["_DictValueT"], _DictKeyT
58-
]
55+
_DictKeyT = str | int | float | bool | None
56+
_DictValueT = collections.Mapping[_DictKeyT, "_DictValueT"] | collections.Sequence["_DictValueT"] | _DictKeyT
5957

6058

6159
_ENTRY_POINT_GROUP_NAME = "alluka.managed"
@@ -153,9 +151,7 @@ def set_descriptors(
153151
"""
154152
self._descriptors[callback] = descriptors
155153

156-
def get_descriptors(
157-
self, callback: alluka.CallbackSig[typing.Any], /
158-
) -> typing.Optional[dict[str, _types.InjectedTuple]]:
154+
def get_descriptors(self, callback: alluka.CallbackSig[typing.Any], /) -> dict[str, _types.InjectedTuple] | None:
159155
"""Get the dependency injection descriptors cached for a callback.
160156
161157
Parameters
@@ -258,7 +254,7 @@ def _scan_libraries(self) -> None:
258254
_LOGGER.debug("Registering TypeConfig from %r", entry_point)
259255
continue
260256

261-
_LOGGER.warn(
257+
_LOGGER.warning(
262258
"Unexpected value found at %, expected a PluginConfig class but found %r. "
263259
"An alluka entry point is misconfigured.",
264260
entry_point.value,

alluka/managed/_manager.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import json
3737
import logging
3838
import pathlib
39+
import tomllib
3940
import typing
4041
import weakref
4142
from collections import abc as collections
@@ -47,30 +48,19 @@
4748
from . import _index
4849

4950
if typing.TYPE_CHECKING:
50-
from typing_extensions import Self
51+
from typing import Self
5152

5253

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

55-
_DictKeyT = typing.Union[str, int, float, bool, None]
56-
_DictValueT = typing.Union[
57-
collections.Mapping[_DictKeyT, "_DictValueT"], collections.Sequence["_DictValueT"], _DictKeyT
58-
]
56+
_DictKeyT = str | int | float | bool | None
57+
_DictValueT = collections.Mapping[_DictKeyT, "_DictValueT"] | collections.Sequence["_DictValueT"] | _DictKeyT
5958
_PARSERS: dict[str, collections.Callable[[typing.BinaryIO], collections.Mapping[_DictKeyT, _DictValueT]]] = {
60-
"json": json.load
59+
"json": json.load,
60+
"toml": tomllib.load,
6161
}
6262

6363

64-
try:
65-
import tomllib # pyright: ignore[reportMissingImports]
66-
67-
except ModuleNotFoundError:
68-
pass
69-
70-
else:
71-
_PARSERS["toml"] = tomllib.load # type: ignore
72-
73-
7464
class Manager:
7565
"""A type dependency lifetime manager implementation.
7666
@@ -93,7 +83,7 @@ def __init__(self, client: abc.Client, /) -> None:
9383
self._load_types: dict[type[typing.Any], _config.TypeConfig[typing.Any]] = {}
9484
self._processed_callbacks: weakref.WeakSet[collections.Callable[..., typing.Any]] = weakref.WeakSet()
9585

96-
def load_config(self, config: typing.Union[pathlib.Path, _config.ConfigFile], /) -> Self:
86+
def load_config(self, config: pathlib.Path | _config.ConfigFile, /) -> Self:
9787
"""Load plugin and dependency configuration into this manager.
9888
9989
Parameters
@@ -143,7 +133,7 @@ def load_config(self, config: typing.Union[pathlib.Path, _config.ConfigFile], /)
143133
return self
144134

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

186176
else:
187-
_LOGGER.warn("Type dependency %r skipped as it can only be created in an async context", type_info.name)
177+
_LOGGER.warning(
178+
"Type dependency %r skipped as it can only be created in an async context", type_info.name
179+
)
188180

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

0 commit comments

Comments
 (0)