arpakitlib 1.8.259__py3-none-any.whl → 1.8.261__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user.py +2 -3
- arpakitlib/ar_pydantic_schema_from_sqlalchemy_model.py +19 -23
- {arpakitlib-1.8.259.dist-info → arpakitlib-1.8.261.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.259.dist-info → arpakitlib-1.8.261.dist-info}/RECORD +7 -7
- {arpakitlib-1.8.259.dist-info → arpakitlib-1.8.261.dist-info}/LICENSE +0 -0
- {arpakitlib-1.8.259.dist-info → arpakitlib-1.8.261.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.259.dist-info → arpakitlib-1.8.261.dist-info}/entry_points.txt +0 -0
@@ -1,4 +1,3 @@
|
|
1
|
-
from __future__ import annotations
|
2
1
|
|
3
2
|
import datetime as dt
|
4
3
|
from typing import TYPE_CHECKING, Any
|
@@ -92,14 +91,14 @@ class UserDBM(SimpleDBM):
|
|
92
91
|
)
|
93
92
|
|
94
93
|
# many to one
|
95
|
-
user_tokens: Mapped[list[UserTokenDBM]] = relationship(
|
94
|
+
user_tokens: Mapped[list["UserTokenDBM"]] = relationship(
|
96
95
|
"UserTokenDBM",
|
97
96
|
uselist=True,
|
98
97
|
back_populates="user",
|
99
98
|
foreign_keys="UserTokenDBM.user_id",
|
100
99
|
cascade="all, delete-orphan"
|
101
100
|
)
|
102
|
-
verification_codes: Mapped[list[VerificationCodeDBM]] = relationship(
|
101
|
+
verification_codes: Mapped[list["VerificationCodeDBM"]] = relationship(
|
103
102
|
"VerificationCodeDBM",
|
104
103
|
uselist=True,
|
105
104
|
back_populates="user",
|
@@ -4,14 +4,13 @@ from typing import Any, get_type_hints, get_origin, Union, Annotated, get_args
|
|
4
4
|
from pydantic import BaseModel, ConfigDict
|
5
5
|
from sqlalchemy import inspect
|
6
6
|
from sqlalchemy.orm import ColumnProperty, Mapped
|
7
|
-
from sqlalchemy.util import get_annotations
|
8
7
|
|
9
8
|
from project.sqlalchemy_db_.sqlalchemy_model import UserDBM
|
10
9
|
|
11
10
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
12
11
|
|
13
12
|
|
14
|
-
def
|
13
|
+
def _define_sqlalchemy_column_mapped_type(type_: Any) -> Any:
|
15
14
|
"""
|
16
15
|
Возвращает тип колонки ИСКЛЮЧИТЕЛЬНО из аннотации поля.
|
17
16
|
Разворачивает оболочки:
|
@@ -19,22 +18,13 @@ def __declared_sqlalchemy_column_type(declared_type: Any) -> Any:
|
|
19
18
|
- Mapped[T] -> T
|
20
19
|
Если аннотации нет — возвращает Any.
|
21
20
|
"""
|
22
|
-
if declared_type is None or declared_type is Any:
|
23
|
-
return Any
|
24
21
|
|
25
|
-
origin = get_origin(
|
26
|
-
|
27
|
-
# Annotated[T, ...] -> T
|
28
|
-
if origin is Annotated:
|
29
|
-
args = get_args(declared_type)
|
30
|
-
return __declared_sqlalchemy_column_type(args[0]) if args else Any
|
22
|
+
origin = get_origin(type_)
|
31
23
|
|
32
|
-
# Mapped[T] -> T
|
33
24
|
if origin is Mapped:
|
34
|
-
|
35
|
-
return __declared_sqlalchemy_column_type(args[0]) if args else Any
|
25
|
+
return get_args(type_)[0] if get_args(type_) else Any
|
36
26
|
|
37
|
-
return
|
27
|
+
return type_
|
38
28
|
|
39
29
|
|
40
30
|
def _get_property_name_to_type_from_model_class(
|
@@ -102,6 +92,16 @@ def _type_matches(*, type_: Any, allowed_types: list[type]) -> bool:
|
|
102
92
|
return False
|
103
93
|
|
104
94
|
|
95
|
+
def _get_sqlalchemy_mapped_types(sqlalchemy_model):
|
96
|
+
result = {}
|
97
|
+
for cls in reversed(sqlalchemy_model.__mro__):
|
98
|
+
annotations = getattr(cls, "__annotations__", {})
|
99
|
+
for field, annotation in annotations.items():
|
100
|
+
if get_origin(annotation) is Mapped:
|
101
|
+
result[field] = annotation
|
102
|
+
return result
|
103
|
+
|
104
|
+
|
105
105
|
def pydantic_schema_from_sqlalchemy_model(
|
106
106
|
sqlalchemy_model: type,
|
107
107
|
*,
|
@@ -144,16 +144,13 @@ def pydantic_schema_from_sqlalchemy_model(
|
|
144
144
|
# 1) Колонки
|
145
145
|
if include_columns:
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
for prop in mapper.column_attrs:
|
151
|
-
if not isinstance(prop, ColumnProperty):
|
147
|
+
for column_attr in mapper.column_attrs:
|
148
|
+
if not isinstance(column_attr, ColumnProperty):
|
152
149
|
continue
|
153
|
-
if
|
150
|
+
if column_attr.key in exclude_column_names:
|
154
151
|
continue
|
155
|
-
|
156
|
-
annotations[
|
152
|
+
mapped_type = _get_sqlalchemy_mapped_types(sqlalchemy_model=sqlalchemy_model)[column_attr.key]
|
153
|
+
annotations[column_attr.key] = _define_sqlalchemy_column_mapped_type(type_=mapped_type)
|
157
154
|
|
158
155
|
# 2) Свойства (@property)
|
159
156
|
if include_properties:
|
@@ -241,4 +238,3 @@ def pydantic_schema_from_sqlalchemy_model(
|
|
241
238
|
attrs["model_config"] = ConfigDict(extra="ignore", arbitrary_types_allowed=True, from_attributes=True)
|
242
239
|
|
243
240
|
return type(model_name, (base_model,), attrs)
|
244
|
-
|
@@ -275,7 +275,7 @@ arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model
|
|
275
275
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/common.py,sha256=NsZbGGJvsn1IgfUQ9J4_6qBQyNBADDmt2Q8waRePD0c,5851
|
276
276
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/operation.py,sha256=6mDtD20H0bQEoSwReLPzaqNp6vLHgOQ7D1DD7KC7zIU,7111
|
277
277
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/story_log.py,sha256=Xou8XvEGQfLuEHH5RKdq6pXCZWMhmtyshQvvohT-Go8,2507
|
278
|
-
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user.py,sha256=
|
278
|
+
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user.py,sha256=rLR4uWTS-tCX2SMVy8YrkMI-01b5kXEhaBHDbrLmmFI,7867
|
279
279
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/user_token.py,sha256=Yy4XZLHJqNEt_SlQOcVCDwHqxpuBwtOmyOfGKbYqKeo,1988
|
280
280
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/sqlalchemy_model/verification_code.py,sha256=xM5e9C8ELI1RJBAaSXZPn9Qpwl4DT2TgRvbYOxsKZsM,3137
|
281
281
|
arpakitlib/_arpakit_project_template_v_5/project/sqlalchemy_db_/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -414,7 +414,7 @@ arpakitlib/ar_need_type_util.py,sha256=XmY1kswz8j9oo5f9CxRu0_zgfvxWrXPYKOj6MM04s
|
|
414
414
|
arpakitlib/ar_openai_api_client_util.py,sha256=dWgsSPXtxNBxS5VRi_NharGQrUXF_YjIfhU3Bj5cW9M,5651
|
415
415
|
arpakitlib/ar_parse_command.py,sha256=1WTdQoWVshoDZ1jDaKeTzajfqaYHP3FNO0-REyo1aMY,3003
|
416
416
|
arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
|
417
|
-
arpakitlib/ar_pydantic_schema_from_sqlalchemy_model.py,sha256=
|
417
|
+
arpakitlib/ar_pydantic_schema_from_sqlalchemy_model.py,sha256=K2XCYp6tcRYKXljyfqgJ09B6qPZGsP7PazoAvnE5v-s,10330
|
418
418
|
arpakitlib/ar_raise_own_exception_if_exception.py,sha256=A6TuNSBk1pHaQ_qxnUmE2LgsNGA1IGqX26b1_HEA4Nc,5978
|
419
419
|
arpakitlib/ar_rat_func_util.py,sha256=Ca10o3RJwyx_DJLxjTxgHDO6NU3M6CWgUR4bif67OE4,2006
|
420
420
|
arpakitlib/ar_really_validate_email.py,sha256=HBfhyiDB3INI6Iq6hR2WOMKA5wVWWRl0Qun-x__OZ9o,1201
|
@@ -430,8 +430,8 @@ arpakitlib/ar_sqlalchemy_util.py,sha256=FDva9onjtCPrYZYIHHb93NMwD1WlmaORjiWgPRJQ
|
|
430
430
|
arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
|
431
431
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
432
432
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
|
433
|
-
arpakitlib-1.8.
|
434
|
-
arpakitlib-1.8.
|
435
|
-
arpakitlib-1.8.
|
436
|
-
arpakitlib-1.8.
|
437
|
-
arpakitlib-1.8.
|
433
|
+
arpakitlib-1.8.261.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
434
|
+
arpakitlib-1.8.261.dist-info/METADATA,sha256=njGc54LxVJzDMEvck7dP82cipNhUByRon9zEyk4x7Tw,3919
|
435
|
+
arpakitlib-1.8.261.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
436
|
+
arpakitlib-1.8.261.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
437
|
+
arpakitlib-1.8.261.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|