python-checks 0.7.0__py3-none-any.whl → 0.9.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.
@@ -47,14 +47,14 @@ class Shape:
47
47
  # spelling.
48
48
  methods: tuple[str, ...]
49
49
 
50
- # Only as a decorator. For a route this is a must: its `methods` are `get`,
51
- # `post`, `delete`, the same names an HTTP client goes by, and a rule
52
- # reading every `.post(...)` would find a route in the first adapter that
53
- # talks to a neighbouring service. A subscription cannot be mistaken for
54
- # anything like that, and it is written both as a decorator and as a call:
55
- # it is kept in a variable and applied to the handler separately, because
56
- # its client is taken before the start.
57
- decorated: bool
50
+ # Recognised only as a decorator. For a route this is a must: its `methods`
51
+ # are `get`, `post`, `delete`, the same names an HTTP client goes by, and a
52
+ # rule reading every `.post(...)` would find a route in the first adapter
53
+ # that talks to a neighbouring service. A subscription cannot be mistaken
54
+ # for anything like that, so `False` takes it in both forms: as a decorator,
55
+ # `@router.subscriber(...)`, and as a call kept in a variable and applied to
56
+ # the handler separately, because its client is taken before the start.
57
+ decorator_only: bool
58
58
 
59
59
  # The word a message uses for the first argument.
60
60
  subject: str
@@ -73,7 +73,7 @@ class Shape:
73
73
  KNOWN: Final[dict[str, Shape]] = {
74
74
  Framework.FASTAPI: Shape(
75
75
  methods=("get", "post", "put", "patch", "delete", "head", "options", "trace"),
76
- decorated=True,
76
+ decorator_only=True,
77
77
  subject="path",
78
78
  named="path",
79
79
  body="response_model",
@@ -86,7 +86,7 @@ KNOWN: Final[dict[str, Shape]] = {
86
86
  ),
87
87
  Framework.FASTSTREAM: Shape(
88
88
  methods=("subscriber",),
89
- decorated=False,
89
+ decorator_only=False,
90
90
  subject="topic",
91
91
  named=None,
92
92
  ),
@@ -167,6 +167,13 @@ class EdgeDeclarations:
167
167
  An entrance taken out of the schema (`include_in_schema=False`) the rule
168
168
  leaves alone: the schema is what it protects, and such a route is not in it.
169
169
 
170
+ A keyword decided once for a whole router or broker counts for every
171
+ entrance on it: `router = KafkaRouter(parser=...)` declares the parser of
172
+ each `router.subscriber(...)`. Only when the object is built in the same
173
+ module, by a call the file shows; built elsewhere, it has nothing to read,
174
+ and the entrance answers for itself. A name assigned twice counts only
175
+ what both constructors passed.
176
+
170
177
  Settings: one block per framework, with `required` in it.
171
178
  """
172
179
 
@@ -188,6 +195,7 @@ class EdgeDeclarations:
188
195
  code=CODE,
189
196
  ).frameworks
190
197
  decorators = cls._decorators(tree=file.tree)
198
+ built = cls._built(tree=file.tree)
191
199
  for node in ast.walk(file.tree):
192
200
  if not isinstance(node, ast.Call):
193
201
  continue
@@ -198,13 +206,17 @@ class EdgeDeclarations:
198
206
  if found is None:
199
207
  continue
200
208
  shape, edge = found
201
- if shape.decorated and node not in decorators:
209
+ if shape.decorator_only and node not in decorators:
202
210
  continue
203
211
  yield from cls._judged(
204
212
  call=node,
205
213
  file=file,
206
214
  shape=shape,
207
215
  edge=edge,
216
+ inherited=cls._inherited(
217
+ call=node,
218
+ built=built,
219
+ ),
208
220
  )
209
221
 
210
222
  @staticmethod
@@ -218,6 +230,39 @@ class EdgeDeclarations:
218
230
  if isinstance(decorator, ast.Call)
219
231
  }
220
232
 
233
+ @staticmethod
234
+ def _built(*, tree: ast.Module) -> dict[str, frozenset[str]]:
235
+ """The keywords each name was built with in this module: `router = KafkaRouter(...)`.
236
+
237
+ A name assigned more than once keeps only what every constructor
238
+ passed: which of them the entrance hangs on, the file does not say.
239
+ """
240
+ found: dict[str, frozenset[str]] = {}
241
+ for node in ast.walk(tree):
242
+ match node:
243
+ case (
244
+ ast.Assign(targets=[ast.Name(id=name)], value=ast.Call() as call)
245
+ | ast.AnnAssign(target=ast.Name(id=name), value=ast.Call() as call)
246
+ ):
247
+ passed = frozenset(keyword.arg for keyword in call.keywords if keyword.arg)
248
+ found[name] = found[name] & passed if name in found else passed
249
+ case _:
250
+ continue
251
+ return found
252
+
253
+ @staticmethod
254
+ def _inherited(
255
+ *,
256
+ call: ast.Call,
257
+ built: dict[str, frozenset[str]],
258
+ ) -> frozenset[str]:
259
+ """What the router or broker the entrance hangs on already declared."""
260
+ match call.func:
261
+ case ast.Attribute(value=ast.Name(id=name)):
262
+ return built.get(name, frozenset())
263
+ case _:
264
+ return frozenset()
265
+
221
266
  @staticmethod
222
267
  def _matched(
223
268
  *,
@@ -241,6 +286,7 @@ class EdgeDeclarations:
241
286
  file: ParsedFile,
242
287
  shape: Shape,
243
288
  edge: Edge,
289
+ inherited: frozenset[str],
244
290
  ) -> Iterator[Violation]:
245
291
  if cls._unpublished(
246
292
  call=call,
@@ -251,7 +297,7 @@ class EdgeDeclarations:
251
297
  call=call,
252
298
  shape=shape,
253
299
  )
254
- declared = {keyword.arg for keyword in call.keywords}
300
+ declared = {keyword.arg for keyword in call.keywords} | inherited
255
301
  yield from cls._first(
256
302
  call=call,
257
303
  file=file,
@@ -21,6 +21,8 @@ CODE: Final = "model-columns"
21
21
  MAPPED: Final = "Mapped"
22
22
  AWARE: Final = "timezone"
23
23
  NULLABLE: Final = "nullable"
24
+ RELATIONSHIP: Final = "relationship"
25
+ LAZY: Final = "lazy"
24
26
 
25
27
 
26
28
  class ModelColumnsSettings(ZonedSettings):
@@ -31,12 +33,13 @@ class ModelColumnsSettings(ZonedSettings):
31
33
  skip: tuple[str, ...] = ()
32
34
  aware: tuple[str, ...] = ()
33
35
  nullable: bool = True
36
+ lazy: tuple[str, ...] = ()
34
37
 
35
38
 
36
39
  class ModelColumns:
37
40
  """Fails if a column is built out of the wrong material.
38
41
 
39
- Five rules on one table of settings.
42
+ Six rules on one table of settings.
40
43
 
41
44
  `instead` is the material that has no place in a column, and what to write
42
45
  instead. A bare `Enum` is a native Postgres type: every new member needs an
@@ -66,8 +69,15 @@ class ModelColumns:
66
69
  diverge, and then the annotation lies: pyright reasons by it, the database
67
70
  holds the keyword, and one of the two is wrong on every row.
68
71
 
72
+ `lazy` lists the loaders a `relationship()` may name. Under asyncio an
73
+ implicit load cannot run: touching an unloaded relationship raises
74
+ `MissingGreenlet` far from the query, and where it happens to work it is
75
+ one query per row. `lazy="raise"` makes the query say what it loads, with
76
+ `selectinload` or `joinedload`. A value the file does not show is reported
77
+ too: a loader nobody can read is not one anybody chose.
78
+
69
79
  Settings: `zones`, `factories`, `instead`, `wrappers`, `defaults`, `skip`,
70
- `aware`, `nullable`.
80
+ `aware`, `nullable`, `lazy`.
71
81
  """
72
82
 
73
83
  code: ClassVar[str] = CODE
@@ -134,6 +144,12 @@ class ModelColumns:
134
144
  f"{written} without timezone=True stores a naive timestamp; say timezone=True"
135
145
  ),
136
146
  )
147
+ if written == RELATIONSHIP and limits.lazy:
148
+ yield from cls._loaded(
149
+ file=file,
150
+ node=node,
151
+ allowed=limits.lazy,
152
+ )
137
153
  if written not in limits.factories:
138
154
  return
139
155
  for keyword in node.keywords:
@@ -147,6 +163,28 @@ class ModelColumns:
147
163
  ),
148
164
  )
149
165
 
166
+ @classmethod
167
+ def _loaded(
168
+ cls,
169
+ *,
170
+ file: ParsedFile,
171
+ node: ast.Call,
172
+ allowed: tuple[str, ...],
173
+ ) -> Iterator[Violation]:
174
+ """A relationship that loads behind the query's back."""
175
+ written = next((keyword.value for keyword in node.keywords if keyword.arg == LAZY), None)
176
+ if isinstance(written, ast.Constant) and written.value in allowed:
177
+ return
178
+ said = "without lazy=" if written is None else f"with lazy={ast.unparse(written)}"
179
+ yield cls._says(
180
+ file=file,
181
+ node=node,
182
+ message=(
183
+ f"relationship() {said} loads without the query saying so; "
184
+ f"say lazy={allowed[0]!r} and load it at the query"
185
+ ),
186
+ )
187
+
150
188
  @classmethod
151
189
  def _annotation(
152
190
  cls,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-checks
3
- Version: 0.7.0
3
+ Version: 0.9.0
4
4
  Summary: Проверки архитектурных соглашений проекта
5
5
  Author: Armontex
6
6
  Author-email: Armontex <windle1337@gmail.com>
@@ -5,7 +5,7 @@ py_checks/checks/_layout.py,sha256=ICpSL-akEMBzxHRdk71aWT92F6Gt8GGy-Aubnuh-kaQ,9
5
5
  py_checks/checks/_location.py,sha256=2Hzbsve6oO0ExTx03iraSOKu7aqM5R5uNXTZexrjhZM,5913
6
6
  py_checks/checks/_names.py,sha256=LrwKwl2g1Z7eZmNOSx-hQhpOjFL-L-TUqpWOFzjRC9A,3047
7
7
  py_checks/checks/api/__init__.py,sha256=NBgeG3O4Ctiy74AFvLOFitmHUOq7jsrUG0-eLKpvlkY,527
8
- py_checks/checks/api/_edge_declarations.py,sha256=zOYr-d8Ps_NSRMsuU11M4Fz-H5bLFDboqatUn5KMUak,13005
8
+ py_checks/checks/api/_edge_declarations.py,sha256=x7Vm_0RJWFd6mLDR8WPsnwvI5Y30jxvn96PNznSffC4,15029
9
9
  py_checks/checks/api/_marker.py,sha256=F64S2mLvWkJV6Lqoj8Hq2oyx61ENvWO6gat_3yaFZrQ,118
10
10
  py_checks/checks/calls/__init__.py,sha256=S2DYJ0Bj5nQR_4SnJ3SF08w1wMQ7WGgV7x4WKljMaCs,378
11
11
  py_checks/checks/calls/_confined_functions.py,sha256=2PYXxUycnGIUrM3G3gwyi3Cr-bYdUOhZnk3k6Vj-19k,3278
@@ -15,7 +15,7 @@ py_checks/checks/database/_bound_checks.py,sha256=-iCSRMBXSa1s29Z8nFwOBdUzGmXwVd
15
15
  py_checks/checks/database/_confined_calls.py,sha256=haBwvVvCNjQP1VmF8i0P3O_w2bnBuPKRWwD0OPY7DHA,3829
16
16
  py_checks/checks/database/_marker.py,sha256=KlqJEpGiu6rw4HWHi4t--KnScXykJZ3f66lsipSagKw,116
17
17
  py_checks/checks/database/_model_boundary.py,sha256=hPIp72YBECB0cSqEMtZx3Z5N7qIoLNS_-60tswq1BIM,8756
18
- py_checks/checks/database/_model_columns.py,sha256=ppPIsGZiT9e92GJF3k81U0UmUiYdSOV6nbGcV4Hwbe8,8031
18
+ py_checks/checks/database/_model_columns.py,sha256=Hzc6jR4aaBcODaR8oEYDa4ZuvwKiLCiNJsM99PrTolg,9545
19
19
  py_checks/checks/database/_raw_sql.py,sha256=MOM5vDBCsplTiazzWUKIEU3Tzvgdk6fjBWhdiZlHe9s,4183
20
20
  py_checks/checks/database/_schema_drift.py,sha256=bI9_aoD0AC_XeqOV0clvMfPkT3EwsLfzgjSQGjegPks,8701
21
21
  py_checks/checks/database/_statement_keys.py,sha256=ojaXelv8zQA28Xj9ovAQoLqXWqZ34jh-Z8ZcPQnPVco,6004
@@ -110,8 +110,8 @@ py_checks/mutation/_settings.py,sha256=HF9-6ICtsHAV8-1MRHDe1wEfj5dbCKux05_YHxl_X
110
110
  py_checks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
111
111
  py_checks/sync/__init__.py,sha256=l5yy0yACEYTnFzR7EXyF7GJ2eX6KZ_dyudxTdKrIUGs,696
112
112
  py_checks/sync/_sync.py,sha256=GF1BGkWR_1sP0Lq_XZJ6Lfe59Bm_ABbaWPoeuEWnNrM,1878
113
- python_checks-0.7.0.dist-info/licenses/LICENSE,sha256=omcAXq_cAQNMI5X3fRdH7UC6W2Zc8AC-G9xIZ2U1xF0,1065
114
- python_checks-0.7.0.dist-info/WHEEL,sha256=e4_1dyBeezi8ZjfxrZ3bnVOxFDa3ksqVqH0jTHkUZ3k,81
115
- python_checks-0.7.0.dist-info/entry_points.txt,sha256=TtWmUfXcevBejdpwhas4_nNHwVEOW4Qleq2OgafxwbE,1715
116
- python_checks-0.7.0.dist-info/METADATA,sha256=wsJiqgb9MrX-a2k5y7TF7B3BLXkyPxszLvje_ODQTHo,15647
117
- python_checks-0.7.0.dist-info/RECORD,,
113
+ python_checks-0.9.0.dist-info/licenses/LICENSE,sha256=omcAXq_cAQNMI5X3fRdH7UC6W2Zc8AC-G9xIZ2U1xF0,1065
114
+ python_checks-0.9.0.dist-info/WHEEL,sha256=766qEDcnZQDL36MOdWBQ0gowd8OjUWAOwMNC7Vgvxts,81
115
+ python_checks-0.9.0.dist-info/entry_points.txt,sha256=TtWmUfXcevBejdpwhas4_nNHwVEOW4Qleq2OgafxwbE,1715
116
+ python_checks-0.9.0.dist-info/METADATA,sha256=jDtF2NSWodmk3E65ZtKnZEQPTLyViP680JSvBL_qpFk,15647
117
+ python_checks-0.9.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.12.19
2
+ Generator: uv 0.12.20
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any