sera-2 1.14.3__py3-none-any.whl → 1.14.4__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.
sera/make/make_python_model.py
CHANGED
@@ -370,25 +370,24 @@ def make_python_data_model(
|
|
370
370
|
continue
|
371
371
|
|
372
372
|
if isinstance(prop, DataProperty):
|
373
|
-
pytype = prop.get_data_model_datatype().get_python_type()
|
374
|
-
if prop.is_optional:
|
375
|
-
pytype = pytype.as_optional_type()
|
376
|
-
|
377
|
-
for dep in pytype.deps:
|
378
|
-
program.import_(dep, True)
|
379
|
-
|
380
|
-
pytype_type = pytype.type
|
373
|
+
pytype = prop.get_data_model_datatype().get_python_type().clone()
|
381
374
|
if len(prop.data.constraints) > 0:
|
382
375
|
# if the property has constraints, we need to figure out
|
383
376
|
program.import_("typing.Annotated", True)
|
384
377
|
if len(prop.data.constraints) == 1:
|
385
|
-
|
386
|
-
|
378
|
+
pytype.type = "Annotated[%s, %s]" % (
|
379
|
+
pytype.type,
|
387
380
|
prop.data.constraints[0].get_msgspec_constraint(),
|
388
381
|
)
|
389
382
|
else:
|
390
383
|
raise NotImplementedError(prop.data.constraints)
|
391
384
|
|
385
|
+
if prop.is_optional:
|
386
|
+
pytype = pytype.as_optional_type()
|
387
|
+
|
388
|
+
for dep in pytype.deps:
|
389
|
+
program.import_(dep, True)
|
390
|
+
|
392
391
|
# private property are available for creating, but not for updating.
|
393
392
|
# so we do not need to skip it.
|
394
393
|
# if prop.data.is_private:
|
@@ -416,7 +415,7 @@ def make_python_data_model(
|
|
416
415
|
|
417
416
|
cls_ast(
|
418
417
|
stmt.DefClassVarStatement(
|
419
|
-
prop.name,
|
418
|
+
prop.name, pytype.type, prop_default_value
|
420
419
|
)
|
421
420
|
)
|
422
421
|
elif isinstance(prop, ObjectProperty):
|
@@ -440,12 +439,10 @@ def make_python_data_model(
|
|
440
439
|
elif prop.is_optional:
|
441
440
|
pytype = pytype.as_optional_type()
|
442
441
|
|
443
|
-
pytype_type = pytype.type
|
444
|
-
|
445
442
|
for dep in pytype.deps:
|
446
443
|
program.import_(dep, True)
|
447
444
|
|
448
|
-
cls_ast(stmt.DefClassVarStatement(prop.name,
|
445
|
+
cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
|
449
446
|
|
450
447
|
if is_on_create_value_updated:
|
451
448
|
program.import_("typing.Optional", True)
|
@@ -558,30 +555,30 @@ def make_python_data_model(
|
|
558
555
|
continue
|
559
556
|
|
560
557
|
if isinstance(prop, DataProperty):
|
561
|
-
pytype = prop.get_data_model_datatype().get_python_type()
|
562
|
-
if prop.is_optional:
|
563
|
-
pytype = pytype.as_optional_type()
|
558
|
+
pytype = prop.get_data_model_datatype().get_python_type().clone()
|
564
559
|
|
565
|
-
for dep in pytype.deps:
|
566
|
-
program.import_(dep, True)
|
567
|
-
|
568
|
-
pytype_type = pytype.type
|
569
560
|
if len(prop.data.constraints) > 0:
|
570
561
|
# if the property has constraints, we need to figure out
|
571
562
|
program.import_("typing.Annotated", True)
|
572
563
|
if len(prop.data.constraints) == 1:
|
573
|
-
|
574
|
-
|
564
|
+
pytype.type = "Annotated[%s, %s]" % (
|
565
|
+
pytype.type,
|
575
566
|
prop.data.constraints[0].get_msgspec_constraint(),
|
576
567
|
)
|
577
568
|
else:
|
578
569
|
raise NotImplementedError(prop.data.constraints)
|
579
570
|
|
571
|
+
if prop.is_optional:
|
572
|
+
pytype = pytype.as_optional_type()
|
573
|
+
|
574
|
+
for dep in pytype.deps:
|
575
|
+
program.import_(dep, True)
|
576
|
+
|
580
577
|
if prop.data.is_private:
|
581
578
|
program.import_("typing.Union", True)
|
582
579
|
program.import_("sera.typing.UnsetType", True)
|
583
580
|
program.import_("sera.typing.UNSET", True)
|
584
|
-
|
581
|
+
pytype.type = f"Union[{pytype.type}, UnsetType]"
|
585
582
|
|
586
583
|
prop_default_value = None
|
587
584
|
if prop.data.is_private:
|
@@ -602,7 +599,7 @@ def make_python_data_model(
|
|
602
599
|
|
603
600
|
cls_ast(
|
604
601
|
stmt.DefClassVarStatement(
|
605
|
-
prop.name,
|
602
|
+
prop.name, pytype.type, prop_default_value
|
606
603
|
)
|
607
604
|
)
|
608
605
|
elif isinstance(prop, ObjectProperty):
|
@@ -626,12 +623,10 @@ def make_python_data_model(
|
|
626
623
|
elif prop.is_optional:
|
627
624
|
pytype = pytype.as_optional_type()
|
628
625
|
|
629
|
-
pytype_type = pytype.type
|
630
|
-
|
631
626
|
for dep in pytype.deps:
|
632
627
|
program.import_(dep, True)
|
633
628
|
|
634
|
-
cls_ast(stmt.DefClassVarStatement(prop.name,
|
629
|
+
cls_ast(stmt.DefClassVarStatement(prop.name, pytype.type))
|
635
630
|
|
636
631
|
if is_on_update_value_updated:
|
637
632
|
program.import_("typing.Optional", True)
|
sera/models/_datatype.py
CHANGED
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import datetime
|
4
4
|
from dataclasses import dataclass, field
|
5
|
-
from enum import Enum
|
6
5
|
from typing import Literal
|
7
6
|
|
8
7
|
from codegen.models import expr
|
@@ -64,6 +63,10 @@ class PyTypeWithDep:
|
|
64
63
|
)
|
65
64
|
return PyTypeWithDep(type=f"Optional[{self.type}]", deps=deps)
|
66
65
|
|
66
|
+
def clone(self) -> PyTypeWithDep:
|
67
|
+
"""Clone the type with the same dependencies."""
|
68
|
+
return PyTypeWithDep(type=self.type, deps=list(self.deps))
|
69
|
+
|
67
70
|
|
68
71
|
@dataclass
|
69
72
|
class TsTypeWithDep:
|
@@ -17,7 +17,7 @@ sera/make/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
sera/make/__main__.py,sha256=bt-gDF8E026OWc2zqr9_a3paMOiDkFd3ybWn8ltL2g0,1448
|
18
18
|
sera/make/make_app.py,sha256=n9NtW73O3s_5Q31VHIRmnd-jEIcpDO7ksAsOdovde2s,5999
|
19
19
|
sera/make/make_python_api.py,sha256=iXGbKQ3IJvsY1ur_fhurr_THFNnH66E3Wl85o0emUbw,26853
|
20
|
-
sera/make/make_python_model.py,sha256=
|
20
|
+
sera/make/make_python_model.py,sha256=cRb-fuHX0WH7XPAAliu6lycC0iEjE5kcKg4bBU40GwQ,61275
|
21
21
|
sera/make/make_python_services.py,sha256=0ZpWLwQ7Nwfn8BXAikAB4JRpNknpSJyJgY5b1cjtxV4,2073
|
22
22
|
sera/make/make_typescript_model.py,sha256=ugDdSTw_1ayHLuL--92RQ8hf_D-dpJtnvmUZNxcwcDs,63687
|
23
23
|
sera/misc/__init__.py,sha256=Dh4uDq0D4N53h3zhvmwfa5a0TPVRSUvLzb0hkFuPirk,411
|
@@ -27,7 +27,7 @@ sera/models/__init__.py,sha256=vJC5Kzo_N7wd16ocNPy1VvAZDGNiWeiAhWJ4ihATKvA,780
|
|
27
27
|
sera/models/_class.py,sha256=9XSnJli2SGF-jm-v0swsfY6-omiQ5Xeh33R2pM9Kg_g,2526
|
28
28
|
sera/models/_collection.py,sha256=ZnQEriKC4X88Zz48Kn1AVZKH-1_l8OgWa-zf2kcQOOE,1414
|
29
29
|
sera/models/_constraints.py,sha256=RpWDU-TfCslXaMUaTG9utWbl5z8Z6nzvF_fhqlek6ew,1987
|
30
|
-
sera/models/_datatype.py,sha256=
|
30
|
+
sera/models/_datatype.py,sha256=Lq1iEGqQaNHiG5NlRTcOTWROiUFjoiPoTeSJKFU6lSE,7281
|
31
31
|
sera/models/_default.py,sha256=ABggW6qdPR4ZDqIPJdJ0GCGQ-7kfsfZmQ_DchgZEa-I,137
|
32
32
|
sera/models/_enum.py,sha256=sy0q7E646F-APsqrVQ52r1fAQ_DCAeaNq5YM5QN3zIk,2070
|
33
33
|
sera/models/_module.py,sha256=I-GfnTgAa-5R87qTAvEzOt-VVEGeFBBwubGCgUkXVSw,5159
|
@@ -36,6 +36,6 @@ sera/models/_parse.py,sha256=ohexBbjFv6A1wZsEtokfw0zMVoR-RGXYrXa_tAub_Vs,12147
|
|
36
36
|
sera/models/_property.py,sha256=Y98bYIjuCQDcSWpDxERNIFgmxXIaJiwBNFtYeGbDYRE,6812
|
37
37
|
sera/models/_schema.py,sha256=VxJEiqgVvbXgcSUK4UW6JnRcggk4nsooVSE6MyXmfNY,1636
|
38
38
|
sera/typing.py,sha256=Fl4-UzLJu1GdLLk_g87fA7nT9wQGelNnGzag6dg_0gs,980
|
39
|
-
sera_2-1.14.
|
40
|
-
sera_2-1.14.
|
41
|
-
sera_2-1.14.
|
39
|
+
sera_2-1.14.4.dist-info/METADATA,sha256=PTLgXrXqoFQ74mPm4mgMK3DaBGMh0A45FNuUd40tb94,852
|
40
|
+
sera_2-1.14.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
41
|
+
sera_2-1.14.4.dist-info/RECORD,,
|
File without changes
|