python-constricter 0.2.5__tar.gz → 0.2.8__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_constricter-0.2.5 → python_constricter-0.2.8}/PKG-INFO +11 -8
- {python_constricter-0.2.5 → python_constricter-0.2.8}/README.md +10 -7
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/__init__.py +1 -1
- python_constricter-0.2.8/constricter/cli/collecting.py +47 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/command.py +188 -257
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/config.py +8 -15
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/hints.py +60 -127
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/options.py +36 -2
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/paths.py +31 -0
- python_constricter-0.2.8/constricter/cli/protocol.py +167 -0
- python_constricter-0.2.8/constricter/cli/runs.py +43 -0
- python_constricter-0.2.8/constricter/cli/schedule.py +224 -0
- python_constricter-0.2.8/constricter/cli/workers.py +154 -0
- python_constricter-0.2.8/constricter/fix/callers.py +153 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/doubts.py +124 -22
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/fills.py +47 -45
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/fixes.py +60 -20
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/guesses.py +74 -11
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/imports.py +90 -26
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/inference.py +122 -77
- python_constricter-0.2.8/constricter/fix/installed.py +237 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/known.py +122 -6
- python_constricter-0.2.8/constricter/fix/library.py +101 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/members.py +19 -2
- python_constricter-0.2.8/constricter/fix/modules.py +339 -0
- python_constricter-0.2.8/constricter/fix/narrowed.py +164 -0
- python_constricter-0.2.8/constricter/fix/order.py +145 -0
- python_constricter-0.2.8/constricter/fix/overloads.py +514 -0
- python_constricter-0.2.8/constricter/fix/project.py +734 -0
- python_constricter-0.2.8/constricter/fix/returned.py +703 -0
- python_constricter-0.2.8/constricter/fix/stdlib.py +410 -0
- python_constricter-0.2.8/constricter/fix/tables/aliases.json +147 -0
- python_constricter-0.2.8/constricter/fix/tables/attributes.json +675 -0
- python_constricter-0.2.8/constricter/fix/tables/bases.json +888 -0
- python_constricter-0.2.8/constricter/fix/tables/classes.json +1939 -0
- python_constricter-0.2.8/constricter/fix/tables/generic_attributes.json +55 -0
- python_constricter-0.2.8/constricter/fix/tables/method_overloads.json +353 -0
- python_constricter-0.2.8/constricter/fix/tables/method_signatures.json +655 -0
- python_constricter-0.2.8/constricter/fix/tables/methods.json +857 -0
- python_constricter-0.2.8/constricter/fix/tables/overloads.json +499 -0
- python_constricter-0.2.8/constricter/fix/tables/returns.json +1328 -0
- python_constricter-0.2.8/constricter/fix/tables/source.json +4 -0
- python_constricter-0.2.8/constricter/fix/tables/subscriptable.json +76 -0
- python_constricter-0.2.8/constricter/fix/tables/type_parameters.json +175 -0
- python_constricter-0.2.8/constricter/fix/tables/variables.json +2938 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/offences.py +7 -1
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/annotations.py +55 -1
- python_constricter-0.2.8/constricter/rules/binding.py +251 -0
- python_constricter-0.2.8/constricter/rules/calls.py +211 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/checker.py +266 -334
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/flow.py +2 -0
- python_constricter-0.2.8/constricter/rules/late.py +289 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/narrowing.py +48 -1
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/parsed.py +18 -11
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/redundant.py +2 -8
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/scope.py +139 -231
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/syntax.py +98 -3
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/walked.py +59 -7
- {python_constricter-0.2.5 → python_constricter-0.2.8}/pyproject.toml +8 -2
- python_constricter-0.2.5/constricter/fix/project.py +0 -491
- python_constricter-0.2.5/constricter/fix/returned.py +0 -384
- python_constricter-0.2.5/constricter/fix/stdlib.json +0 -15351
- python_constricter-0.2.5/constricter/fix/stdlib.py +0 -186
- {python_constricter-0.2.5 → python_constricter-0.2.8}/LICENSE.md +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/__main__.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/__init__.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/baseline.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/explain.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/guard.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/report.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/__init__.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/hinted.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/opened.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/returns.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/targets.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/jsonc.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/noqa.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/notebook.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/plugins/__init__.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/plugins/flake8.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/plugins/pylint.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/py.typed +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/__init__.py +0 -0
- {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/rebinding.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-constricter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8
|
|
4
4
|
Summary: Lint rules: every local variable is typed where it's first bound. A flake8 plugin, a pylint plugin and a standalone CLI.
|
|
5
5
|
Author: Ivy Duggan
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -173,6 +173,8 @@ Options:
|
|
|
173
173
|
| Option | CLI | `[tool.constricter]` | flake8 (CLI or config) | pylint |
|
|
174
174
|
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------- | --------------------------------- |
|
|
175
175
|
| level | `--level` | `level` | `--constricter-level` | `constricter-level` |
|
|
176
|
+
| strictest | `--max`: `--level=suffocate` for every path, `--all-scopes`, and the opt-in `LVA012` | — | — | — |
|
|
177
|
+
| every fix | `--max-fix`: `--max`, `--fix --unsafe-fixes`, and `--infer-with` each of basedpyright and ty that's installed and runs | — | — | — |
|
|
176
178
|
| type comments | `--type-comments` | `type-comments` | `--constricter-type-comments` | `constricter-type-comments = yes` |
|
|
177
179
|
| all scopes | `--all-scopes` | `all-scopes` | `--constricter-all-scopes` | `constricter-all-scopes = yes` |
|
|
178
180
|
| nesting | `--nesting N` | `nesting` | `--constricter-nesting` | `constricter-nesting` |
|
|
@@ -231,12 +233,13 @@ ignore = ["LVA003"]
|
|
|
231
233
|
|
|
232
234
|
`--fix` adds the annotation where the value decides it: a literal (`count = 0` becomes
|
|
233
235
|
`count: int = 0`), a container whose elements agree, a constructor or a function that declares its
|
|
234
|
-
return type (in another checked file too), a copy, subscript, attribute or
|
|
235
|
-
whose type is known, and values computed from those; a loop's target or an
|
|
236
|
-
declaration on the line before. `--unsafe-fixes` adds guesses, and
|
|
237
|
-
how its value decided it. `--infer-with basedpyright` (or `ty`, or
|
|
238
|
-
alongside) asks those type checkers for what `--fix` can't type itself,
|
|
239
|
-
|
|
236
|
+
return type or whose `return`s agree (in another checked file too), a copy, subscript, attribute or
|
|
237
|
+
method call of a local whose type is known, and values computed from those; a loop's target or an
|
|
238
|
+
unpacking's names get a declaration on the line before. `--unsafe-fixes` adds guesses, and
|
|
239
|
+
`--show-fixes` lists each fix and how its value decided it. `--infer-with basedpyright` (or `ty`, or
|
|
240
|
+
`basedpyright,ty`, installed alongside) asks those type checkers for what `--fix` can't type itself,
|
|
241
|
+
as guesses. The full list is in
|
|
242
|
+
[docs/FIXES.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/FIXES.md).
|
|
240
243
|
|
|
241
244
|
### Installing and running
|
|
242
245
|
|
|
@@ -261,7 +264,7 @@ pre-commit, after ruff's hooks (or `constricter-fix`, which runs `--fix` first):
|
|
|
261
264
|
|
|
262
265
|
```yaml
|
|
263
266
|
- repo: https://github.com/ivylikethevine/python-constricter
|
|
264
|
-
rev: v0.2.
|
|
267
|
+
rev: v0.2.8
|
|
265
268
|
hooks:
|
|
266
269
|
- id: constricter
|
|
267
270
|
```
|
|
@@ -146,6 +146,8 @@ Options:
|
|
|
146
146
|
| Option | CLI | `[tool.constricter]` | flake8 (CLI or config) | pylint |
|
|
147
147
|
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------- | --------------------------------- |
|
|
148
148
|
| level | `--level` | `level` | `--constricter-level` | `constricter-level` |
|
|
149
|
+
| strictest | `--max`: `--level=suffocate` for every path, `--all-scopes`, and the opt-in `LVA012` | — | — | — |
|
|
150
|
+
| every fix | `--max-fix`: `--max`, `--fix --unsafe-fixes`, and `--infer-with` each of basedpyright and ty that's installed and runs | — | — | — |
|
|
149
151
|
| type comments | `--type-comments` | `type-comments` | `--constricter-type-comments` | `constricter-type-comments = yes` |
|
|
150
152
|
| all scopes | `--all-scopes` | `all-scopes` | `--constricter-all-scopes` | `constricter-all-scopes = yes` |
|
|
151
153
|
| nesting | `--nesting N` | `nesting` | `--constricter-nesting` | `constricter-nesting` |
|
|
@@ -204,12 +206,13 @@ ignore = ["LVA003"]
|
|
|
204
206
|
|
|
205
207
|
`--fix` adds the annotation where the value decides it: a literal (`count = 0` becomes
|
|
206
208
|
`count: int = 0`), a container whose elements agree, a constructor or a function that declares its
|
|
207
|
-
return type (in another checked file too), a copy, subscript, attribute or
|
|
208
|
-
whose type is known, and values computed from those; a loop's target or an
|
|
209
|
-
declaration on the line before. `--unsafe-fixes` adds guesses, and
|
|
210
|
-
how its value decided it. `--infer-with basedpyright` (or `ty`, or
|
|
211
|
-
alongside) asks those type checkers for what `--fix` can't type itself,
|
|
212
|
-
|
|
209
|
+
return type or whose `return`s agree (in another checked file too), a copy, subscript, attribute or
|
|
210
|
+
method call of a local whose type is known, and values computed from those; a loop's target or an
|
|
211
|
+
unpacking's names get a declaration on the line before. `--unsafe-fixes` adds guesses, and
|
|
212
|
+
`--show-fixes` lists each fix and how its value decided it. `--infer-with basedpyright` (or `ty`, or
|
|
213
|
+
`basedpyright,ty`, installed alongside) asks those type checkers for what `--fix` can't type itself,
|
|
214
|
+
as guesses. The full list is in
|
|
215
|
+
[docs/FIXES.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/FIXES.md).
|
|
213
216
|
|
|
214
217
|
### Installing and running
|
|
215
218
|
|
|
@@ -234,7 +237,7 @@ pre-commit, after ruff's hooks (or `constricter-fix`, which runs `--fix` first):
|
|
|
234
237
|
|
|
235
238
|
```yaml
|
|
236
239
|
- repo: https://github.com/ivylikethevine/python-constricter
|
|
237
|
-
rev: v0.2.
|
|
240
|
+
rev: v0.2.8
|
|
238
241
|
hooks:
|
|
239
242
|
- id: constricter
|
|
240
243
|
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
"""The garbage collector, as the command runs it: by hand, once per file checked.
|
|
3
|
+
|
|
4
|
+
A check keeps every file's tree (see `parsed`), and allocates a great deal for each file, little of it
|
|
5
|
+
cyclic. Left to itself, the collector looked through the kept trees again and again as the check
|
|
6
|
+
allocated: a third of the standard library's check (34s, 21s without). So while the command runs,
|
|
7
|
+
it's off: what indexing built is frozen (never looked through again), and after each file, only
|
|
8
|
+
what's been allocated since (the young generations) is collected, which bounds what a cycle can hold.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import contextlib
|
|
12
|
+
import gc
|
|
13
|
+
from collections.abc import Generator
|
|
14
|
+
from typing import Final
|
|
15
|
+
|
|
16
|
+
_YOUNG: Final = 1 # the generations collected after each file: 0 and 1, never the frozen or the old
|
|
17
|
+
_FREEZES: Final = hasattr(gc, "freeze") # PyPy's collector has no freezing
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@contextlib.contextmanager
|
|
21
|
+
def by_hand() -> Generator[None]:
|
|
22
|
+
"""Turn automatic collection off for the command's run, and back as it was after.
|
|
23
|
+
|
|
24
|
+
Yields:
|
|
25
|
+
Nothing: the run.
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
was: bool = gc.isenabled()
|
|
29
|
+
gc.disable()
|
|
30
|
+
try:
|
|
31
|
+
yield
|
|
32
|
+
finally:
|
|
33
|
+
if _FREEZES:
|
|
34
|
+
gc.unfreeze()
|
|
35
|
+
if was:
|
|
36
|
+
gc.enable()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def indexed() -> None:
|
|
40
|
+
"""Freeze what indexing built (the kept trees, the index): it lives until the check takes it."""
|
|
41
|
+
if _FREEZES:
|
|
42
|
+
gc.freeze()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def sweep() -> None:
|
|
46
|
+
"""Collect what the file just checked left behind (see the module docstring)."""
|
|
47
|
+
_ = gc.collect(_YOUNG)
|