Coverage for faststream/_internal/basic_types.py: 66%
35 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
1from collections.abc import Awaitable, Callable, Mapping, Sequence
2from contextlib import AbstractAsyncContextManager
3from datetime import datetime
4from decimal import Decimal
5from typing import (
6 Any,
7 ClassVar,
8 Protocol,
9 TypeAlias,
10 TypeVar,
11)
13from typing_extensions import ParamSpec
15AnyHttpUrl: TypeAlias = str
17F_Return = TypeVar("F_Return")
18F_Spec = ParamSpec("F_Spec")
20AnyCallable: TypeAlias = Callable[..., Any]
21NoneCallable: TypeAlias = Callable[..., None]
22AsyncFunc: TypeAlias = Callable[..., Awaitable[Any]]
23AsyncFuncAny: TypeAlias = Callable[[Any], Awaitable[Any]]
25DecoratedCallable: TypeAlias = AnyCallable
26DecoratedCallableNone: TypeAlias = NoneCallable
28Decorator: TypeAlias = Callable[[AnyCallable], AnyCallable]
30JsonArray: TypeAlias = Sequence["DecodedMessage"]
32JsonTable: TypeAlias = dict[str, "DecodedMessage"]
34JsonDecodable: TypeAlias = bool | bytes | bytearray | float | int | str | None
36DecodedMessage: TypeAlias = JsonDecodable | JsonArray | JsonTable
38SendableArray: TypeAlias = Sequence["BaseSendableMessage"]
40SendableTable: TypeAlias = dict[str, "BaseSendableMessage"]
43class StandardDataclass(Protocol):
44 """Protocol to check type is dataclass."""
46 __slots__ = ()
48 __dataclass_fields__: ClassVar[dict[str, Any]]
51BaseSendableMessage: TypeAlias = (
52 JsonDecodable
53 | Decimal
54 | datetime
55 | StandardDataclass
56 | SendableTable
57 | SendableArray
58 | None
59)
61try:
62 from pydantic import BaseModel
64 HAS_PYDANTIC = True
65except ImportError:
66 HAS_PYDANTIC = False
68try:
69 from msgspec import Struct
71 HAS_MSGSPEC = True
72except ImportError:
73 HAS_MSGSPEC = False
75if HAS_PYDANTIC and HAS_MSGSPEC: 75 ↛ 77line 75 didn't jump to line 77 because the condition on line 75 was always true
76 SendableMessage: TypeAlias = Struct | BaseModel | BaseSendableMessage # type: ignore[possibly-undefined]
77elif HAS_PYDANTIC:
78 SendableMessage: TypeAlias = BaseModel | BaseSendableMessage # type: ignore[no-redef,misc,possibly-undefined]
79elif HAS_MSGSPEC:
80 SendableMessage: TypeAlias = Struct | BaseSendableMessage # type: ignore[no-redef,misc,possibly-undefined]
81else:
82 SendableMessage: TypeAlias = BaseSendableMessage # type: ignore[no-redef,misc]
84SettingField: TypeAlias = (
85 bool | str | list[bool | str] | list[str] | list[bool] | int | None
86)
88Lifespan: TypeAlias = Callable[..., AbstractAsyncContextManager[None]]
91class LoggerProto(Protocol):
92 __slots__ = ()
94 def log(
95 self,
96 level: int,
97 msg: Any,
98 /,
99 *,
100 exc_info: Any = None,
101 extra: Mapping[str, Any] | None = None,
102 ) -> None: ...