Coverage for src/typedal/types.py: 100%
63 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-05 14:43 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-05 14:43 +0100
1"""
2Stuff to make mypy happy.
3"""
4import typing
5from datetime import datetime
6from typing import Any, Optional, TypedDict
8from pydal.helpers.classes import OpRow as _OpRow
9from pydal.helpers.classes import Reference as _Reference
10from pydal.objects import Expression as _Expression
11from pydal.objects import Field as _Field
12from pydal.objects import Query as _Query
13from pydal.objects import Rows as _Rows
14from pydal.objects import Set as _Set
15from pydal.validators import Validator as _Validator
16from typing_extensions import NotRequired
19class Query(_Query): # type: ignore
20 """
21 Pydal Query object.
23 Makes mypy happy.
24 """
27class Expression(_Expression): # type: ignore
28 """
29 Pydal Expression object.
31 Make mypy happy.
32 """
35class Set(_Set): # type: ignore
36 """
37 Pydal Set object.
39 Make mypy happy.
40 """
43class OpRow(_OpRow): # type: ignore
44 """
45 Pydal OpRow object.
47 Make mypy happy.
48 """
51class Reference(_Reference): # type: ignore
52 """
53 Pydal Reference object.
55 Make mypy happy.
56 """
59class Field(_Field): # type: ignore
60 """
61 Pydal Field object.
63 Make mypy happy.
64 """
67class Rows(_Rows): # type: ignore
68 """
69 Pydal Rows object.
71 Make mypy happy.
72 """
75class Validator(_Validator): # type: ignore
76 """
77 Pydal Validator object.
79 Make mypy happy.
80 """
83class _Types:
84 """
85 Internal type storage for stuff that mypy otherwise won't understand.
86 """
88 NONETYPE = type(None)
91BeforeInsertCallable: typing.TypeAlias = typing.Callable[[OpRow], Any]
92AfterInsertCallable: typing.TypeAlias = typing.Callable[[OpRow, Reference], Any]
93BeforeUpdateCallable: typing.TypeAlias = typing.Callable[[Set, OpRow], Any]
94AfterUpdateCallable: typing.TypeAlias = typing.Callable[[Set, OpRow], Any]
95BeforeDeleteCallable: typing.TypeAlias = typing.Callable[[Set], Any]
96AfterDeleteCallable: typing.TypeAlias = typing.Callable[[Set], Any]
99class Pagination(TypedDict):
100 """
101 Pagination key of a paginate dict has these items.
102 """
104 total_items: int
105 current_page: int
106 per_page: int
107 total_pages: int
108 has_next_page: bool
109 has_prev_page: bool
110 next_page: Optional[int]
111 prev_page: Optional[int]
114class PaginateDict(TypedDict):
115 """
116 Result of PaginatedRows.as_dict().
117 """
119 data: dict[int, dict[str, Any]]
120 pagination: Pagination
123class CacheMetadata(TypedDict):
124 """
125 Used by query builder metadata in the 'cache' key.
126 """
128 enabled: bool
129 depends_on: list[Any]
130 key: NotRequired[str | None]
131 status: NotRequired[str | None]
132 expires_at: NotRequired[datetime | None]
133 cached_at: NotRequired[datetime | None]
136class PaginationMetadata(TypedDict):
137 """
138 Used by query builder metadata in the 'pagination' key.
139 """
141 limit: int
142 current_page: int
143 max_page: int
144 rows: int
145 min_max: tuple[int, int]
148class Metadata(TypedDict):
149 """
150 Loosely structured metadata used by Query Builder.
151 """
153 cache: NotRequired[CacheMetadata]
154 pagination: NotRequired[PaginationMetadata]
156 query: NotRequired[Query | str | None]
157 ids: NotRequired[str]
159 final_query: NotRequired[Query | str | None]
160 final_args: NotRequired[list[Any]]
161 final_kwargs: NotRequired[dict[str, Any]]
162 relationships: NotRequired[set[str]]
164 sql: NotRequired[str]