python-checks 0.10.0__tar.gz → 0.12.0__tar.gz
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.
- {python_checks-0.10.0 → python_checks-0.12.0}/PKG-INFO +2 -1
- {python_checks-0.10.0 → python_checks-0.12.0}/pyproject.toml +3 -1
- {python_checks-0.10.0 → python_checks-0.12.0}/pyproject.toml.orig +9 -1
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/_kind.py +43 -1
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/_layout.py +4 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_model_columns.py +42 -40
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_statement_keys.py +8 -2
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_operation_shape.py +17 -25
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_required_class.py +22 -29
- python_checks-0.12.0/src/py_checks/checks/signatures/_callers.py +484 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_function_length.py +6 -2
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_functions.py +0 -5
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_keyword_only.py +118 -18
- python_checks-0.12.0/src/py_checks/checks/signatures/_stops.py +173 -0
- python_checks-0.12.0/src/py_checks/checks/signatures/_targets.py +265 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/_annotation_shapes.py +6 -18
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/_constant_annotations.py +3 -10
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_doctor.py +8 -2
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_mutation.py +23 -1
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_run.py +16 -3
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/__init__.py +4 -1
- python_checks-0.12.0/src/py_checks/core/_fixer.py +172 -0
- python_checks-0.12.0/src/py_checks/mutation/_cache.py +250 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_gate.py +113 -6
- python_checks-0.12.0/src/py_checks/mutation/_mutmut.py +230 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_process.py +9 -3
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_scope.py +5 -8
- python_checks-0.10.0/src/py_checks/core/_fixer.py +0 -55
- python_checks-0.10.0/src/py_checks/mutation/_mutmut.py +0 -162
- {python_checks-0.10.0 → python_checks-0.12.0}/LICENSE +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/README.md +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/_location.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/_names.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/api/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/api/_edge_declarations.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/api/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/calls/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/calls/_confined_functions.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/calls/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_bound_checks.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_confined_calls.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_model_boundary.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_raw_sql.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_schema_drift.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/effects/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/effects/_determinism.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/effects/_log_events.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/effects/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/errors/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/errors/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/errors/_refusals.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/hygiene/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/hygiene/_dependency_bounds.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/hygiene/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/hygiene/_translations.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/imports/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/imports/_confined.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/imports/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/imports/_sealed.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/imports/_statements.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_class_modules.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_class_placement.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_module_length.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_nesting.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/signatures/_signature_layout.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/_config_fields.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/_confined_types.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/_frozen_dataclasses.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/types/_marker.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/_app.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/_protocols.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_explain.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_list.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_summary.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_sync.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/cli/commands/_translations.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/_base.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/_config.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/_constants.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/_errors.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/_loader.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/config/_toml.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/contracts/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/contracts/_constants.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/contracts/_layout.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/contracts/_render.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/contracts/_settings.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_constants.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_discovery.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_edit.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_errors.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_format.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_markers.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_paths.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_protocols.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_registry.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_report.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_runner.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_settings.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_source.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/core/_violation.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/environment/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/environment/_constants.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/environment/_render.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/environment/_settings.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_baseline.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_constants.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_errors.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/mutation/_settings.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/py.typed +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/sync/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/sync/_sync.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/translations/__init__.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/translations/_constants.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/translations/_errors.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/translations/_settings.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/translations/_stamp.py +0 -0
- {python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/translations/_tree.py +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-checks
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Проверки архитектурных соглашений проекта
|
|
5
5
|
Author: Armontex
|
|
6
6
|
Author-email: Armontex <windle1337@gmail.com>
|
|
7
7
|
License-Expression: MIT
|
|
8
8
|
License-File: LICENSE
|
|
9
|
+
Requires-Dist: jedi>=0.19.2,<0.21
|
|
9
10
|
Requires-Dist: libcst>=1.9,<2
|
|
10
11
|
Requires-Dist: pathspec>=1.1,<2
|
|
11
12
|
Requires-Dist: pydantic>=2.13.5,<3
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "python-checks"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.0"
|
|
4
4
|
description = "Проверки архитектурных соглашений проекта"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
7
7
|
license-files = ["LICENSE"]
|
|
8
8
|
requires-python = ">=3.14"
|
|
9
9
|
dependencies = [
|
|
10
|
+
"jedi>=0.19.2,<0.21",
|
|
10
11
|
"libcst>=1.9,<2",
|
|
11
12
|
"pathspec>=1.1,<2",
|
|
12
13
|
"pydantic>=2.13.5,<3",
|
|
@@ -76,6 +77,7 @@ dev = [
|
|
|
76
77
|
"actionlint-py>=1.7.12,<2",
|
|
77
78
|
"commitizen>=4.10,<5",
|
|
78
79
|
"import-linter>=2.15,<3",
|
|
80
|
+
"jscpd>=5.4.2,<6",
|
|
79
81
|
"pre-commit>=4.6.2,<5",
|
|
80
82
|
"pyright>=1.1.414,<2",
|
|
81
83
|
"pytest>=9.1.1,<10",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "python-checks"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.0"
|
|
4
4
|
description = "Проверки архитектурных соглашений проекта"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -8,6 +8,10 @@ license-files = ["LICENSE"]
|
|
|
8
8
|
authors = [{ name = "Armontex", email = "windle1337@gmail.com" }]
|
|
9
9
|
requires-python = ">=3.14"
|
|
10
10
|
dependencies = [
|
|
11
|
+
# `--fix` у keyword-only-arguments: чей это вызов — наш, чужой или ничей.
|
|
12
|
+
# Без вывода типов `self._repo.get(x)` не отличить от `dict.get`, а вызов,
|
|
13
|
+
# который не разрешился, останавливает правку, а не ломает его.
|
|
14
|
+
"jedi>=0.19.2,<0.21",
|
|
11
15
|
"libcst>=1.9,<2",
|
|
12
16
|
# gitignore-шаблоны `[translations].files`: `**`, ведущий `/`, директории и
|
|
13
17
|
# отрицание — краёв столько, что самописный разбор ошибся бы на части из них.
|
|
@@ -88,6 +92,10 @@ dev = [
|
|
|
88
92
|
"actionlint-py>=1.7.12,<2",
|
|
89
93
|
"commitizen>=4.10,<5",
|
|
90
94
|
"import-linter>=2.15,<3",
|
|
95
|
+
# Бинарник Rust в колесе, Node.js не нужен. Пол на версии, на которой
|
|
96
|
+
# режим проверен: до 5.4.0 включительно `similarity = 1` выключал поиск,
|
|
97
|
+
# а не требовал ту же структуру.
|
|
98
|
+
"jscpd>=5.4.2,<6",
|
|
91
99
|
"pre-commit>=4.6.2,<5",
|
|
92
100
|
"pyright>=1.1.414,<2",
|
|
93
101
|
"pytest>=9.1.1,<10",
|
|
@@ -15,7 +15,7 @@ from typing import TYPE_CHECKING, Final
|
|
|
15
15
|
from py_checks.checks._names import name, names
|
|
16
16
|
|
|
17
17
|
if TYPE_CHECKING:
|
|
18
|
-
from collections.abc import Iterator
|
|
18
|
+
from collections.abc import Iterator, Sequence
|
|
19
19
|
|
|
20
20
|
ABSTRACT: Final[frozenset[str]] = frozenset({"Protocol", "ABC"})
|
|
21
21
|
ABSTRACT_METACLASS: Final = "ABCMeta"
|
|
@@ -118,6 +118,12 @@ def declarations(*, tree: ast.Module) -> Iterator[Declaration]:
|
|
|
118
118
|
kind=Kind.FUNCTION,
|
|
119
119
|
node=node,
|
|
120
120
|
)
|
|
121
|
+
case ast.TypeAlias(name=ast.Name(id=name)):
|
|
122
|
+
yield Declaration(
|
|
123
|
+
name=name,
|
|
124
|
+
kind=Kind.ALIAS,
|
|
125
|
+
node=node,
|
|
126
|
+
)
|
|
121
127
|
case ast.AnnAssign(target=ast.Name(id=name)) | ast.Assign(targets=[ast.Name(id=name)]):
|
|
122
128
|
if _alias(node=node):
|
|
123
129
|
yield Declaration(
|
|
@@ -129,6 +135,25 @@ def declarations(*, tree: ast.Module) -> Iterator[Declaration]:
|
|
|
129
135
|
continue
|
|
130
136
|
|
|
131
137
|
|
|
138
|
+
def enums(*, tree: ast.Module) -> frozenset[str]:
|
|
139
|
+
"""The module's classes that are enums: on an `Enum` base, or on one of these.
|
|
140
|
+
|
|
141
|
+
`class OrderStatus(WireStatus)` is an enum when `WireStatus(StrEnum)` is
|
|
142
|
+
declared in the same file — a shared `_missing_` or `__str__` on a base
|
|
143
|
+
enum. A base imported from another module cannot be read from here.
|
|
144
|
+
"""
|
|
145
|
+
classes = [node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
|
|
146
|
+
found: set[str] = set()
|
|
147
|
+
grown = True
|
|
148
|
+
while grown:
|
|
149
|
+
grown = False
|
|
150
|
+
for node in classes:
|
|
151
|
+
if node.name not in found and frozenset(names(nodes=node.bases)) & (ENUMS | found):
|
|
152
|
+
found.add(node.name)
|
|
153
|
+
grown = True
|
|
154
|
+
return frozenset(found)
|
|
155
|
+
|
|
156
|
+
|
|
132
157
|
def _class(*, node: ast.ClassDef) -> Kind | None:
|
|
133
158
|
"""The class's kind; `None` if one file does not show it.
|
|
134
159
|
|
|
@@ -184,3 +209,20 @@ def _alias(*, node: ast.AnnAssign | ast.Assign) -> bool:
|
|
|
184
209
|
return True
|
|
185
210
|
case _:
|
|
186
211
|
return False
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def signature_end(
|
|
215
|
+
*,
|
|
216
|
+
node: ast.FunctionDef | ast.AsyncFunctionDef,
|
|
217
|
+
lines: Sequence[str],
|
|
218
|
+
) -> int:
|
|
219
|
+
"""The last line of the signature: the mark goes there when the signature is in a column.
|
|
220
|
+
|
|
221
|
+
The body usually starts on the line after the `:`. A stub may share that
|
|
222
|
+
line — ruff writes `) -> None: ...` — and then it is the signature's end.
|
|
223
|
+
"""
|
|
224
|
+
first = node.body[0]
|
|
225
|
+
# `col_offset` counts utf-8 bytes, so the line is cut as bytes.
|
|
226
|
+
if lines[first.lineno - 1].encode("utf-8")[: first.col_offset].strip():
|
|
227
|
+
return first.lineno
|
|
228
|
+
return max(first.lineno - 1, node.lineno)
|
|
@@ -114,6 +114,9 @@ class Directory(CheckSettings):
|
|
|
114
114
|
`operation` — the shape of an operation, if operations are kept here.
|
|
115
115
|
`orm` — what the directory is to an ORM model: its home or where it is built.
|
|
116
116
|
`base` — the base class by which a model is recognised in the models' home.
|
|
117
|
+
`optional` — the directory may not exist yet: the block says where code
|
|
118
|
+
goes, not where it already is, and `doctor` does not ask the tree for it.
|
|
119
|
+
The rules judge it as soon as a file turns up there.
|
|
117
120
|
"""
|
|
118
121
|
|
|
119
122
|
only: tuple[Kind, ...] = ()
|
|
@@ -125,6 +128,7 @@ class Directory(CheckSettings):
|
|
|
125
128
|
operation: Operation | None = None
|
|
126
129
|
orm: Orm | None = None
|
|
127
130
|
base: str | None = None
|
|
131
|
+
optional: bool = False
|
|
128
132
|
|
|
129
133
|
@property
|
|
130
134
|
def restricted(self) -> bool:
|
{python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_model_columns.py
RENAMED
|
@@ -6,7 +6,7 @@ import ast
|
|
|
6
6
|
from typing import TYPE_CHECKING, ClassVar, Final
|
|
7
7
|
|
|
8
8
|
from py_checks.checks._location import ZonedSettings, zoned
|
|
9
|
-
from py_checks.checks._names import name
|
|
9
|
+
from py_checks.checks._names import name, walked
|
|
10
10
|
from py_checks.checks.database._marker import MARKER
|
|
11
11
|
from py_checks.core import Scope, Violation, settings_as
|
|
12
12
|
|
|
@@ -23,6 +23,8 @@ AWARE: Final = "timezone"
|
|
|
23
23
|
NULLABLE: Final = "nullable"
|
|
24
24
|
RELATIONSHIP: Final = "relationship"
|
|
25
25
|
LAZY: Final = "lazy"
|
|
26
|
+
OPTIONAL: Final = "Optional"
|
|
27
|
+
UNION: Final = "Union"
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
class ModelColumnsSettings(ZonedSettings):
|
|
@@ -128,18 +130,20 @@ class ModelColumns:
|
|
|
128
130
|
"""The material, and whatever the column fills itself in with."""
|
|
129
131
|
written = name(node=node.func)
|
|
130
132
|
if written in limits.instead and limits.wrappers.get(written) != file.path.stem:
|
|
131
|
-
yield
|
|
132
|
-
file=file,
|
|
133
|
+
yield Violation.from_node(
|
|
133
134
|
node=node,
|
|
135
|
+
path=file.path,
|
|
136
|
+
code=CODE,
|
|
134
137
|
message=limits.instead[written],
|
|
135
138
|
)
|
|
136
139
|
if written in limits.aware and not cls._said(
|
|
137
140
|
node=node,
|
|
138
141
|
named=AWARE,
|
|
139
142
|
):
|
|
140
|
-
yield
|
|
141
|
-
file=file,
|
|
143
|
+
yield Violation.from_node(
|
|
142
144
|
node=node,
|
|
145
|
+
path=file.path,
|
|
146
|
+
code=CODE,
|
|
143
147
|
message=(
|
|
144
148
|
f"{written} without timezone=True stores a naive timestamp; say timezone=True"
|
|
145
149
|
),
|
|
@@ -154,9 +158,10 @@ class ModelColumns:
|
|
|
154
158
|
return
|
|
155
159
|
for keyword in node.keywords:
|
|
156
160
|
if keyword.arg in limits.defaults:
|
|
157
|
-
yield
|
|
158
|
-
file=file,
|
|
161
|
+
yield Violation.from_node(
|
|
159
162
|
node=node,
|
|
163
|
+
path=file.path,
|
|
164
|
+
code=CODE,
|
|
160
165
|
message=(
|
|
161
166
|
f"{keyword.arg}= fills the column in for a writer who did not write it; "
|
|
162
167
|
f"pass the value in the statement"
|
|
@@ -176,9 +181,10 @@ class ModelColumns:
|
|
|
176
181
|
if isinstance(written, ast.Constant) and written.value in allowed:
|
|
177
182
|
return
|
|
178
183
|
said = "without lazy=" if written is None else f"with lazy={ast.unparse(written)}"
|
|
179
|
-
yield
|
|
180
|
-
file=file,
|
|
184
|
+
yield Violation.from_node(
|
|
181
185
|
node=node,
|
|
186
|
+
path=file.path,
|
|
187
|
+
code=CODE,
|
|
182
188
|
message=(
|
|
183
189
|
f"relationship() {said} loads without the query saying so; "
|
|
184
190
|
f"say lazy={allowed[0]!r} and load it at the query"
|
|
@@ -197,8 +203,8 @@ class ModelColumns:
|
|
|
197
203
|
inner = cls._mapped(node=node.annotation)
|
|
198
204
|
if inner is None:
|
|
199
205
|
return
|
|
200
|
-
written
|
|
201
|
-
if written
|
|
206
|
+
written = next((one for one in walked(node=inner) if one in limits.skip), None)
|
|
207
|
+
if written is not None:
|
|
202
208
|
yield Violation.from_node(
|
|
203
209
|
node=node,
|
|
204
210
|
path=file.path,
|
|
@@ -211,7 +217,7 @@ class ModelColumns:
|
|
|
211
217
|
node=node.value,
|
|
212
218
|
limits=limits,
|
|
213
219
|
)
|
|
214
|
-
if said is not None and said !=
|
|
220
|
+
if said is not None and said != cls._optional(node=inner):
|
|
215
221
|
yield Violation.from_node(
|
|
216
222
|
node=node,
|
|
217
223
|
path=file.path,
|
|
@@ -236,22 +242,29 @@ class ModelColumns:
|
|
|
236
242
|
return bool(keyword.value.value)
|
|
237
243
|
return None
|
|
238
244
|
|
|
239
|
-
@
|
|
240
|
-
def _mapped(
|
|
241
|
-
"""
|
|
245
|
+
@staticmethod
|
|
246
|
+
def _mapped(*, node: ast.expr) -> ast.expr | None:
|
|
247
|
+
"""What is inside `Mapped[...]`."""
|
|
242
248
|
if not isinstance(node, ast.Subscript) or name(node=node.value) != MAPPED:
|
|
243
249
|
return None
|
|
244
|
-
|
|
245
|
-
case ast.Name(id=inside) | ast.Attribute(attr=inside):
|
|
246
|
-
return inside, False
|
|
247
|
-
case ast.BinOp(left=ast.Name(id=inside), op=ast.BitOr(), right=right):
|
|
248
|
-
return inside, cls._none(node=right)
|
|
249
|
-
case _:
|
|
250
|
-
return None
|
|
250
|
+
return node.slice
|
|
251
251
|
|
|
252
|
-
@
|
|
253
|
-
def
|
|
254
|
-
|
|
252
|
+
@classmethod
|
|
253
|
+
def _optional(cls, *, node: ast.expr) -> bool:
|
|
254
|
+
"""Whether the type allows `None`: `X | None`, `None | X`, `Optional[X]`, `Union[...]`."""
|
|
255
|
+
match node:
|
|
256
|
+
case ast.Constant(value=None):
|
|
257
|
+
return True
|
|
258
|
+
case ast.BinOp(left=left, op=ast.BitOr(), right=right):
|
|
259
|
+
return cls._optional(node=left) or cls._optional(node=right)
|
|
260
|
+
case ast.Subscript(value=outer) if name(node=outer) == OPTIONAL:
|
|
261
|
+
return True
|
|
262
|
+
case ast.Subscript(value=outer, slice=ast.Tuple(elts=arms)) if (
|
|
263
|
+
name(node=outer) == UNION
|
|
264
|
+
):
|
|
265
|
+
return any(cls._optional(node=arm) for arm in arms)
|
|
266
|
+
case _:
|
|
267
|
+
return False
|
|
255
268
|
|
|
256
269
|
@staticmethod
|
|
257
270
|
def _said(
|
|
@@ -259,21 +272,10 @@ class ModelColumns:
|
|
|
259
272
|
node: ast.Call,
|
|
260
273
|
named: str,
|
|
261
274
|
) -> bool:
|
|
275
|
+
"""Whether the keyword is the literal `True`: nothing short of it says what is stored."""
|
|
262
276
|
return any(
|
|
263
|
-
keyword.arg == named
|
|
277
|
+
keyword.arg == named
|
|
278
|
+
and isinstance(keyword.value, ast.Constant)
|
|
279
|
+
and keyword.value.value is True
|
|
264
280
|
for keyword in node.keywords
|
|
265
281
|
)
|
|
266
|
-
|
|
267
|
-
@staticmethod
|
|
268
|
-
def _says(
|
|
269
|
-
*,
|
|
270
|
-
file: ParsedFile,
|
|
271
|
-
node: ast.Call,
|
|
272
|
-
message: str,
|
|
273
|
-
) -> Violation:
|
|
274
|
-
return Violation.from_node(
|
|
275
|
-
node=node,
|
|
276
|
-
path=file.path,
|
|
277
|
-
code=CODE,
|
|
278
|
-
message=message,
|
|
279
|
-
)
|
{python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/database/_statement_keys.py
RENAMED
|
@@ -125,8 +125,14 @@ class StatementKeys:
|
|
|
125
125
|
node: ast.For | ast.AsyncFor | ast.While,
|
|
126
126
|
limits: StatementKeysSettings,
|
|
127
127
|
) -> Iterator[Violation]:
|
|
128
|
-
"""A trip to the database on every iteration.
|
|
129
|
-
|
|
128
|
+
"""A trip to the database on every iteration.
|
|
129
|
+
|
|
130
|
+
Only what runs on every iteration counts: the body, and a `while`'s
|
|
131
|
+
test. A `for`'s iterable is evaluated once, before the first one, and
|
|
132
|
+
its `else` once, after the last.
|
|
133
|
+
"""
|
|
134
|
+
repeated = [*node.body, *([node.test] if isinstance(node, ast.While) else [])]
|
|
135
|
+
for child in (inner for part in repeated for inner in ast.walk(part)):
|
|
130
136
|
if not isinstance(child, ast.Call) or name(node=child.func) not in limits.loops:
|
|
131
137
|
continue
|
|
132
138
|
yield Violation.from_node(
|
{python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_operation_shape.py
RENAMED
|
@@ -6,7 +6,7 @@ import ast
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from typing import TYPE_CHECKING, ClassVar, Final
|
|
8
8
|
|
|
9
|
-
from py_checks.checks._kind import Kind, declarations
|
|
9
|
+
from py_checks.checks._kind import Kind, declarations, signature_end
|
|
10
10
|
from py_checks.checks._layout import SECTION, Layout, innermost
|
|
11
11
|
from py_checks.checks._location import place
|
|
12
12
|
from py_checks.checks.placement._marker import MARKER
|
|
@@ -223,18 +223,20 @@ class OperationShape:
|
|
|
223
223
|
if one.kind is Kind.ALIAS or one is subject:
|
|
224
224
|
continue
|
|
225
225
|
if one.kind is Kind.FUNCTION:
|
|
226
|
-
yield
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
yield Violation.from_node(
|
|
227
|
+
node=one.node,
|
|
228
|
+
path=file.path,
|
|
229
|
+
code=CODE,
|
|
229
230
|
message=(
|
|
230
231
|
f"{one.name}() stands beside the operation; a helper it needs is "
|
|
231
232
|
f"a private method, one that two need is shared code"
|
|
232
233
|
),
|
|
233
234
|
)
|
|
234
235
|
continue
|
|
235
|
-
yield
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
yield Violation.from_node(
|
|
237
|
+
node=one.node,
|
|
238
|
+
path=file.path,
|
|
239
|
+
code=CODE,
|
|
238
240
|
message=(
|
|
239
241
|
f"{one.name} stands beside the operation; in {rule.address} a module "
|
|
240
242
|
f"declares one class and nothing else"
|
|
@@ -258,9 +260,10 @@ class OperationShape:
|
|
|
258
260
|
if names == [rule.method]:
|
|
259
261
|
return
|
|
260
262
|
if not public:
|
|
261
|
-
yield
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
yield Violation.from_node(
|
|
264
|
+
node=subject.node,
|
|
265
|
+
path=file.path,
|
|
266
|
+
code=CODE,
|
|
264
267
|
message=(
|
|
265
268
|
f"{subject.name} has no public method; an operation is asked "
|
|
266
269
|
f"through one, and it is called {rule.method}()"
|
|
@@ -303,7 +306,10 @@ class OperationShape:
|
|
|
303
306
|
f"{rule.max_arguments}; pass a command, a query or a DTO"
|
|
304
307
|
),
|
|
305
308
|
# The mark is accepted on any line of the signature.
|
|
306
|
-
end_line=
|
|
309
|
+
end_line=signature_end(
|
|
310
|
+
node=method,
|
|
311
|
+
lines=file.lines,
|
|
312
|
+
),
|
|
307
313
|
)
|
|
308
314
|
|
|
309
315
|
@classmethod
|
|
@@ -427,17 +433,3 @@ class OperationShape:
|
|
|
427
433
|
yield text
|
|
428
434
|
case _:
|
|
429
435
|
continue
|
|
430
|
-
|
|
431
|
-
@staticmethod
|
|
432
|
-
def _says(
|
|
433
|
-
*,
|
|
434
|
-
file: ParsedFile,
|
|
435
|
-
declared: Declaration,
|
|
436
|
-
message: str,
|
|
437
|
-
) -> Violation:
|
|
438
|
-
return Violation.from_node(
|
|
439
|
-
node=declared.node,
|
|
440
|
-
path=file.path,
|
|
441
|
-
code=CODE,
|
|
442
|
-
message=message,
|
|
443
|
-
)
|
{python_checks-0.10.0 → python_checks-0.12.0}/src/py_checks/checks/placement/_required_class.py
RENAMED
|
@@ -47,8 +47,9 @@ class RequiredClass:
|
|
|
47
47
|
With `named`, the directory keeps many classes of one kind rather than
|
|
48
48
|
one per module, and each of them carries the suffix: a `Price` among the
|
|
49
49
|
`...Value` classes is the one nobody will look for under that name. A
|
|
50
|
-
class
|
|
51
|
-
|
|
50
|
+
class built on a base from another module carries it too: one file does
|
|
51
|
+
not show its kind, but it is in the directory. A class with a leading
|
|
52
|
+
underscore is the module's machinery and is left alone.
|
|
52
53
|
|
|
53
54
|
`__init__.py` re-exports rather than declares; an empty module has not
|
|
54
55
|
promised anything yet; a module with a leading underscore (`_base.py`)
|
|
@@ -117,9 +118,10 @@ class RequiredClass:
|
|
|
117
118
|
) -> Iterator[Violation]:
|
|
118
119
|
required = [one for one in declared if one.name.endswith(suffix)]
|
|
119
120
|
if not required:
|
|
120
|
-
yield
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
yield Violation.from_node(
|
|
122
|
+
node=declared[0].node,
|
|
123
|
+
path=file.path,
|
|
124
|
+
code=CODE,
|
|
123
125
|
message=(
|
|
124
126
|
f"the module declares {cls._listed(declared=declared)}, "
|
|
125
127
|
f"but a module in this directory declares a ...{suffix} class"
|
|
@@ -127,9 +129,10 @@ class RequiredClass:
|
|
|
127
129
|
)
|
|
128
130
|
return
|
|
129
131
|
if len(required) > 1:
|
|
130
|
-
yield
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
yield Violation.from_node(
|
|
133
|
+
node=required[1].node,
|
|
134
|
+
path=file.path,
|
|
135
|
+
code=CODE,
|
|
133
136
|
message=(
|
|
134
137
|
f"the module holds {cls._listed(declared=required)}; "
|
|
135
138
|
f"one ...{suffix} per module, and the module is named after it"
|
|
@@ -141,9 +144,10 @@ class RequiredClass:
|
|
|
141
144
|
suffix=suffix,
|
|
142
145
|
)
|
|
143
146
|
if ahead is not None:
|
|
144
|
-
yield
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
yield Violation.from_node(
|
|
148
|
+
node=ahead.node,
|
|
149
|
+
path=file.path,
|
|
150
|
+
code=CODE,
|
|
147
151
|
message=(
|
|
148
152
|
f"{ahead.name} is declared above the ...{suffix} the module "
|
|
149
153
|
f"exists for; helpers belong below it"
|
|
@@ -164,13 +168,16 @@ class RequiredClass:
|
|
|
164
168
|
for one in declared:
|
|
165
169
|
if not isinstance(one.node, ast.ClassDef) or one.name.startswith("_"):
|
|
166
170
|
continue
|
|
167
|
-
|
|
171
|
+
# A kind no file shows — a base from another module — is still this
|
|
172
|
+
# directory's class: only a kind known to be foreign is let off.
|
|
173
|
+
if directory.only and one.kind is not None and one.kind not in directory.only:
|
|
168
174
|
continue
|
|
169
175
|
if one.name.endswith(suffix):
|
|
170
176
|
continue
|
|
171
|
-
yield
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
yield Violation.from_node(
|
|
178
|
+
node=one.node,
|
|
179
|
+
path=file.path,
|
|
180
|
+
code=CODE,
|
|
174
181
|
message=f"{one.name} does not end with {suffix}; in {address} every class does",
|
|
175
182
|
)
|
|
176
183
|
|
|
@@ -188,20 +195,6 @@ class RequiredClass:
|
|
|
188
195
|
return one
|
|
189
196
|
return None
|
|
190
197
|
|
|
191
|
-
@staticmethod
|
|
192
|
-
def _says(
|
|
193
|
-
*,
|
|
194
|
-
file: ParsedFile,
|
|
195
|
-
node: Declaration,
|
|
196
|
-
message: str,
|
|
197
|
-
) -> Violation:
|
|
198
|
-
return Violation.from_node(
|
|
199
|
-
node=node.node,
|
|
200
|
-
path=file.path,
|
|
201
|
-
code=CODE,
|
|
202
|
-
message=message,
|
|
203
|
-
)
|
|
204
|
-
|
|
205
198
|
@staticmethod
|
|
206
199
|
def _listed(*, declared: list[Declaration]) -> str:
|
|
207
200
|
return ", ".join(one.name for one in declared)
|