Skip to content

Commit aa48168

Browse files
committed
OPT: improve typing 🎨
1 parent 30e90f4 commit aa48168

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

combadge/_helpers/pydantic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from functools import cache
2-
from typing import Any
32

43
from pydantic import TypeAdapter
54

5+
from combadge.core.typevars import AnyT
6+
67

78
@cache
8-
def get_type_adapter(type_: Any) -> TypeAdapter[Any]:
9+
def get_type_adapter(type_: AnyT) -> TypeAdapter[AnyT]:
910
"""Get cached type adapter for the given type."""
1011
return TypeAdapter(type_)

combadge/_helpers/typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from typing_extensions import TypeAliasType
44

55

6-
def unwrap_type_alias(type_: Any) -> Any:
6+
def unwrap_type_alias(type_: type[Any] | None) -> type[Any] | None:
77
"""Extract the inner type, if the given type is a type alias."""
88
if isinstance(type_, TypeAliasType):
99
type_ = type_.__value__
1010
return type_
1111

1212

13-
def unwrap_annotated(type_: Any) -> Any:
13+
def unwrap_annotated(type_: type[Any] | None) -> type[Any] | None:
1414
"""Extract the inner type, if the given type is an `Annotated` form."""
1515
if get_origin(type_) is Annotated:
1616
type_ = get_args(type_)[0]

combadge/core/backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any
2+
from typing import cast
33

44
from typing_extensions import Self
55

@@ -20,7 +20,7 @@ class BaseBackend(ABC):
2020
__slots__ = ("_service_cache",)
2121

2222
def __init__(self) -> None: # noqa: D107
23-
self._service_cache: dict[type, Any] = {}
23+
self._service_cache: dict[type, object] = {}
2424

2525
@classmethod
2626
@abstractmethod
@@ -56,7 +56,7 @@ def __getitem__(self, protocol: type[ServiceProtocolT]) -> ServiceProtocolT:
5656
service = self._service_cache.get(protocol)
5757
if service is None:
5858
service = self._service_cache[protocol] = bind(protocol, self)
59-
return service # noqa: RET504
59+
return cast(ServiceProtocolT, service) # noqa: RET504
6060

6161
def __delitem__(self, protocol: type) -> None:
6262
"""

combadge/core/binder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BoundService(BaseBoundService, from_protocol): # type: ignore[misc, valid
6363
return BoundService
6464

6565

66-
def _wrap(method: Callable[..., Any], with_markers: Iterable[MethodMarker]) -> Callable[..., Any]:
66+
def _wrap(method: FunctionT, with_markers: Iterable[MethodMarker]) -> FunctionT:
6767
"""
6868
Apply method markers.
6969
@@ -78,7 +78,7 @@ def _wrap(method: Callable[..., Any], with_markers: Iterable[MethodMarker]) -> C
7878
return method
7979

8080

81-
def _enumerate_methods(of_protocol: type) -> Iterable[tuple[str, Any]]:
81+
def _enumerate_methods(of_protocol: type) -> Iterable[tuple[str, Callable[..., Any]]]:
8282
"""Enumerate the service protocol methods."""
8383

8484
for name, method in get_members(of_protocol, callable):

combadge/core/signature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Signature:
4242
"""A callable that binds the method's arguments, it is cached here to improve performance."""
4343

4444
@classmethod
45-
def from_method(cls, method: Any) -> Signature:
45+
def from_method(cls, method: Callable[..., Any]) -> Signature:
4646
"""Create a signature from the specified method."""
4747
annotations_ = get_annotations(method, eval_str=True)
4848
return_type = cls._extract_return_type(annotations_)

combadge/support/soap/abc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from dataclasses import dataclass
2-
from typing import Any
32

43
from annotated_types import SLOTS
54

@@ -21,5 +20,5 @@ def get_operation_name(self) -> str:
2120
class SoapHeader:
2221
"""SOAP request header."""
2322

24-
soap_header: Any | None = None
23+
soap_header: object | None = None
2524
"""SOAP header payload."""

0 commit comments

Comments
 (0)