explicit-python 3.0.0__py3-none-any.whl → 3.1.0__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.
@@ -6,6 +6,7 @@ from .factories import (
6
6
  )
7
7
  from .fields import (
8
8
  Field,
9
+ get_field_attribute,
9
10
  get_field_title,
10
11
  )
11
12
  from .model import (
@@ -39,6 +40,7 @@ __all__ = [
39
40
  'asdict',
40
41
  'Field',
41
42
  'get_field_title',
43
+ 'get_field_attribute',
42
44
  'UnsetUUID',
43
45
  'Bool',
44
46
  'Date',
explicit/domain/fields.py CHANGED
@@ -3,6 +3,9 @@
3
3
  from functools import (
4
4
  partial,
5
5
  )
6
+ from typing import (
7
+ Any,
8
+ )
6
9
 
7
10
  from pydantic import (
8
11
  Field as DefaultField,
@@ -34,3 +37,31 @@ def get_field_title(cls: type, name: str) -> str:
34
37
 
35
38
  """
36
39
  return cls.__pydantic_fields__[name].title or name # type: ignore[attr-defined]
40
+
41
+
42
+ def get_field_attribute(cls: type, name: str, attribute: str) -> Any:
43
+ """Возвращает атрибут поля pydantic-модели или pydantic-датакласса.
44
+
45
+ Ограничения (``max_length``, ``ge``, ``max_digits`` и т.п.) pydantic хранит не в самом поле,
46
+ а в его метаданных, поэтому атрибут ищется и там.
47
+
48
+ .. code-block:: python
49
+
50
+ @dataclass
51
+ class User:
52
+ username: str = Field(title='Логин', max_length=50)
53
+
54
+
55
+ get_field_attribute(User, 'username', 'max_length') == 50
56
+
57
+ Raises:
58
+ AttributeError: если атрибут у поля не задан.
59
+
60
+ """
61
+ field = cls.__pydantic_fields__[name] # type: ignore[attr-defined]
62
+ if (value := getattr(field, attribute, None)) is not None:
63
+ return value
64
+ for meta in field.metadata:
65
+ if (value := getattr(meta, attribute, None)) is not None:
66
+ return value
67
+ raise AttributeError(f'У поля {cls.__name__}.{name} не задан атрибут {attribute}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: explicit-python
3
- Version: 3.0.0
3
+ Version: 3.1.0
4
4
  Summary: Набор компонентов для построения многослойной архитектуры
5
5
  Author-email: BARS Group <bars@bars-open.ru>
6
6
  Project-URL: Homepage, https://stash.bars-open.ru/projects/EDUBASE/repos/explicit/browse
@@ -10,9 +10,9 @@ explicit/contrib/domain/model/__init__.py,sha256=Vx0Sw_2P0u-qprCjGvlqYg3vA6Jwfcr
10
10
  explicit/contrib/domain/model/fields.py,sha256=qrJ3E3IJAAjRnQN8tG7rEcD9UHQ2zHx8TV5J0N5Ufc4,931
11
11
  explicit/contrib/messagebus/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  explicit/contrib/messagebus/event_registry.py,sha256=ZF0q33bJfllkPT0Z0GoP_tdC5niZaoQQKsy3xOWg2yI,1593
13
- explicit/domain/__init__.py,sha256=Q4AIHGLnaguQ0jmRElpbWjbWT05frmjQuTVxKM_J8Y4,742
13
+ explicit/domain/__init__.py,sha256=0AbY_mASUjavRPCIZAOnf87UOz6V0c_VvwS2zDQXBOw,794
14
14
  explicit/domain/factories.py,sha256=T2yXg3FV3XHV4n1QYEI7pXfjAjWbb0P7LqG5k22qqPc,961
15
- explicit/domain/fields.py,sha256=0srE1HKz3kufCvNY9mermUZCj3GwufvreRWVjYzMgPM,894
15
+ explicit/domain/fields.py,sha256=Mb01LVfBicqLc14mgG2mVxh5gOk4pzi8THQabN2Aqcw,2022
16
16
  explicit/domain/model.py,sha256=nxsxCcFhKRLqxqDRNaAoBw66cbMVWYX_QnTj0YouBVI,4532
17
17
  explicit/domain/types.py,sha256=75C-eUfEwpx-G0uqO8aIOq2yKyLn5oanAhqMc2SY2a8,928
18
18
  explicit/domain/validation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -24,8 +24,8 @@ explicit/messagebus/events.py,sha256=4OgsiFceNGEIqo1KJnqzy0cWgc88jismplpd45CnmJQ
24
24
  explicit/messagebus/exceptions.py,sha256=avWn_ex665jJHu7Jj8EBjs79Tq2ZvY2rveZOA6aHB-s,375
25
25
  explicit/messagebus/messagebus.py,sha256=9XhP256iL9XvmEazkEnr5l52uUEKW_rNFl81HpHrHrQ,3593
26
26
  explicit/messagebus/queries.py,sha256=OpfJS4WNnFOYy1M-rIlkHT78Wkob5LDOjOZ9B3xCTt0,1567
27
- explicit_python-3.0.0.dist-info/licenses/LICENSE,sha256=CCIO8Y288mm2F53WG2U6QkY7qS7lthANGujcVt6fRlo,3455
28
- explicit_python-3.0.0.dist-info/METADATA,sha256=yyYcmf-BXoia7wp0Lz10YlQtBuSAIb60djHx_Idzgx0,14580
29
- explicit_python-3.0.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
30
- explicit_python-3.0.0.dist-info/top_level.txt,sha256=tt6T8l4Yji4ww87qZQcD4CbcwTIHy7NAPmU7QAfMcpY,9
31
- explicit_python-3.0.0.dist-info/RECORD,,
27
+ explicit_python-3.1.0.dist-info/licenses/LICENSE,sha256=CCIO8Y288mm2F53WG2U6QkY7qS7lthANGujcVt6fRlo,3455
28
+ explicit_python-3.1.0.dist-info/METADATA,sha256=H-PpDA1y4VKr0YFr9rEgYnJ-jK7_ojj8qVh8RwgJ3do,14580
29
+ explicit_python-3.1.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
30
+ explicit_python-3.1.0.dist-info/top_level.txt,sha256=tt6T8l4Yji4ww87qZQcD4CbcwTIHy7NAPmU7QAfMcpY,9
31
+ explicit_python-3.1.0.dist-info/RECORD,,