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

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) 

12 

13from typing_extensions import ParamSpec 

14 

15AnyHttpUrl: TypeAlias = str 

16 

17F_Return = TypeVar("F_Return") 

18F_Spec = ParamSpec("F_Spec") 

19 

20AnyCallable: TypeAlias = Callable[..., Any] 

21NoneCallable: TypeAlias = Callable[..., None] 

22AsyncFunc: TypeAlias = Callable[..., Awaitable[Any]] 

23AsyncFuncAny: TypeAlias = Callable[[Any], Awaitable[Any]] 

24 

25DecoratedCallable: TypeAlias = AnyCallable 

26DecoratedCallableNone: TypeAlias = NoneCallable 

27 

28Decorator: TypeAlias = Callable[[AnyCallable], AnyCallable] 

29 

30JsonArray: TypeAlias = Sequence["DecodedMessage"] 

31 

32JsonTable: TypeAlias = dict[str, "DecodedMessage"] 

33 

34JsonDecodable: TypeAlias = bool | bytes | bytearray | float | int | str | None 

35 

36DecodedMessage: TypeAlias = JsonDecodable | JsonArray | JsonTable 

37 

38SendableArray: TypeAlias = Sequence["BaseSendableMessage"] 

39 

40SendableTable: TypeAlias = dict[str, "BaseSendableMessage"] 

41 

42 

43class StandardDataclass(Protocol): 

44 """Protocol to check type is dataclass.""" 

45 

46 __slots__ = () 

47 

48 __dataclass_fields__: ClassVar[dict[str, Any]] 

49 

50 

51BaseSendableMessage: TypeAlias = ( 

52 JsonDecodable 

53 | Decimal 

54 | datetime 

55 | StandardDataclass 

56 | SendableTable 

57 | SendableArray 

58 | None 

59) 

60 

61try: 

62 from pydantic import BaseModel 

63 

64 HAS_PYDANTIC = True 

65except ImportError: 

66 HAS_PYDANTIC = False 

67 

68try: 

69 from msgspec import Struct 

70 

71 HAS_MSGSPEC = True 

72except ImportError: 

73 HAS_MSGSPEC = False 

74 

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] 

83 

84SettingField: TypeAlias = ( 

85 bool | str | list[bool | str] | list[str] | list[bool] | int | None 

86) 

87 

88Lifespan: TypeAlias = Callable[..., AbstractAsyncContextManager[None]] 

89 

90 

91class LoggerProto(Protocol): 

92 __slots__ = () 

93 

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: ...