Coverage for src/typedal/types.py: 100%

1"""

2 Stuff to make mypy happy.

3"""

4 from datetime import datetime

5 from typing import Any, Optional, TypedDict

6

7 from pydal.objects import Expression as _Expression

8 from pydal.objects import Field as _Field

9 from pydal.objects import Query as _Query

10 from typing_extensions import NotRequired

11

12

13 class Query(_Query): # type: ignore

14 """

15 Pydal Query object.

16

17 Makes mypy happy.

18 """

19

20

21 class Expression(_Expression): # type: ignore

22 """

23 Pydal Expression object.

24

25 Make mypy happy.

26 """

27

28

29 class Field(_Field):

30 """

31 Pydal Field object.

32

33 Make mypy happy.

34 """

35

36

37 class _Types:

38 """

39 Internal type storage for stuff that mypy otherwise won't understand.

40 """

41

42 NONETYPE = type(None)

43

44

45 class Pagination(TypedDict):

46 """

47 Pagination key of a paginate dict has these items.

48 """

49

50 total_items: int

51 current_page: int

52 per_page: int

53 total_pages: int

54 has_next_page: bool

55 has_prev_page: bool

56 next_page: Optional[int]

57 prev_page: Optional[int]

58

59

60 class PaginateDict(TypedDict):

61 """

62 Result of PaginatedRows.as_dict().

63 """

64

65 data: dict[int, dict[str, Any]]

66 pagination: Pagination

67

68

69 class CacheMetadata(TypedDict):

70 """

71 Used by query builder metadata in the 'cache' key.

72 """

73

74 enabled: bool

75 depends_on: list[Any]

76 key: NotRequired[str | None]

77 status: NotRequired[str | None]

78 expires_at: NotRequired[datetime | None]

79 cached_at: NotRequired[datetime | None]

80

81

82 class PaginationMetadata(TypedDict):

83 """

84 Used by query builder metadata in the 'pagination' key.

85 """

86

87 limit: int

88 current_page: int

89 max_page: int

90 rows: int

91 min_max: tuple[int, int]

92

93

94 class Metadata(TypedDict):

95 """

96 Loosely structured metadata used by Query Builder.

97 """

98

99 cache: NotRequired[CacheMetadata]

100 pagination: NotRequired[PaginationMetadata]

101

102 query: NotRequired[Query | str | None]

103 ids: NotRequired[str]

104

105 final_query: NotRequired[Query | str | None]

106 final_args: NotRequired[list[Any]]

107 final_kwargs: NotRequired[dict[str, Any]]

108 relationships: NotRequired[set[str]]

109

110 sql: NotRequired[str]