Coverage for src/typedal/types.py: 100%
46 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 14:59 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 14:59 +0100
1"""
2Stuff to make mypy happy.
3"""
4from datetime import datetime
5from typing import Any, Optional, TypedDict
7from pydal.objects import Expression as _Expression
8from pydal.objects import Field as _Field
9from pydal.objects import Query as _Query
10from typing_extensions import NotRequired
13class Query(_Query): # type: ignore
14 """
15 Pydal Query object.
17 Makes mypy happy.
18 """
21class Expression(_Expression): # type: ignore
22 """
23 Pydal Expression object.
25 Make mypy happy.
26 """
29class Field(_Field):
30 """
31 Pydal Field object.
33 Make mypy happy.
34 """
37class _Types:
38 """
39 Internal type storage for stuff that mypy otherwise won't understand.
40 """
42 NONETYPE = type(None)
45class Pagination(TypedDict):
46 """
47 Pagination key of a paginate dict has these items.
48 """
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]
60class PaginateDict(TypedDict):
61 """
62 Result of PaginatedRows.as_dict().
63 """
65 data: dict[int, dict[str, Any]]
66 pagination: Pagination
69class CacheMetadata(TypedDict):
70 """
71 Used by query builder metadata in the 'cache' key.
72 """
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]
82class PaginationMetadata(TypedDict):
83 """
84 Used by query builder metadata in the 'pagination' key.
85 """
87 limit: int
88 current_page: int
89 max_page: int
90 rows: int
91 min_max: tuple[int, int]
94class Metadata(TypedDict):
95 """
96 Loosely structured metadata used by Query Builder.
97 """
99 cache: NotRequired[CacheMetadata]
100 pagination: NotRequired[PaginationMetadata]
102 query: NotRequired[Query | str | None]
103 ids: NotRequired[str]
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]]
110 sql: NotRequired[str]