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.
Files changed (84) hide show
  1. {python_constricter-0.2.5 → python_constricter-0.2.8}/PKG-INFO +11 -8
  2. {python_constricter-0.2.5 → python_constricter-0.2.8}/README.md +10 -7
  3. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/__init__.py +1 -1
  4. python_constricter-0.2.8/constricter/cli/collecting.py +47 -0
  5. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/command.py +188 -257
  6. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/config.py +8 -15
  7. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/hints.py +60 -127
  8. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/options.py +36 -2
  9. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/paths.py +31 -0
  10. python_constricter-0.2.8/constricter/cli/protocol.py +167 -0
  11. python_constricter-0.2.8/constricter/cli/runs.py +43 -0
  12. python_constricter-0.2.8/constricter/cli/schedule.py +224 -0
  13. python_constricter-0.2.8/constricter/cli/workers.py +154 -0
  14. python_constricter-0.2.8/constricter/fix/callers.py +153 -0
  15. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/doubts.py +124 -22
  16. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/fills.py +47 -45
  17. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/fixes.py +60 -20
  18. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/guesses.py +74 -11
  19. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/imports.py +90 -26
  20. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/inference.py +122 -77
  21. python_constricter-0.2.8/constricter/fix/installed.py +237 -0
  22. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/known.py +122 -6
  23. python_constricter-0.2.8/constricter/fix/library.py +101 -0
  24. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/members.py +19 -2
  25. python_constricter-0.2.8/constricter/fix/modules.py +339 -0
  26. python_constricter-0.2.8/constricter/fix/narrowed.py +164 -0
  27. python_constricter-0.2.8/constricter/fix/order.py +145 -0
  28. python_constricter-0.2.8/constricter/fix/overloads.py +514 -0
  29. python_constricter-0.2.8/constricter/fix/project.py +734 -0
  30. python_constricter-0.2.8/constricter/fix/returned.py +703 -0
  31. python_constricter-0.2.8/constricter/fix/stdlib.py +410 -0
  32. python_constricter-0.2.8/constricter/fix/tables/aliases.json +147 -0
  33. python_constricter-0.2.8/constricter/fix/tables/attributes.json +675 -0
  34. python_constricter-0.2.8/constricter/fix/tables/bases.json +888 -0
  35. python_constricter-0.2.8/constricter/fix/tables/classes.json +1939 -0
  36. python_constricter-0.2.8/constricter/fix/tables/generic_attributes.json +55 -0
  37. python_constricter-0.2.8/constricter/fix/tables/method_overloads.json +353 -0
  38. python_constricter-0.2.8/constricter/fix/tables/method_signatures.json +655 -0
  39. python_constricter-0.2.8/constricter/fix/tables/methods.json +857 -0
  40. python_constricter-0.2.8/constricter/fix/tables/overloads.json +499 -0
  41. python_constricter-0.2.8/constricter/fix/tables/returns.json +1328 -0
  42. python_constricter-0.2.8/constricter/fix/tables/source.json +4 -0
  43. python_constricter-0.2.8/constricter/fix/tables/subscriptable.json +76 -0
  44. python_constricter-0.2.8/constricter/fix/tables/type_parameters.json +175 -0
  45. python_constricter-0.2.8/constricter/fix/tables/variables.json +2938 -0
  46. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/offences.py +7 -1
  47. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/annotations.py +55 -1
  48. python_constricter-0.2.8/constricter/rules/binding.py +251 -0
  49. python_constricter-0.2.8/constricter/rules/calls.py +211 -0
  50. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/checker.py +266 -334
  51. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/flow.py +2 -0
  52. python_constricter-0.2.8/constricter/rules/late.py +289 -0
  53. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/narrowing.py +48 -1
  54. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/parsed.py +18 -11
  55. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/redundant.py +2 -8
  56. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/scope.py +139 -231
  57. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/syntax.py +98 -3
  58. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/walked.py +59 -7
  59. {python_constricter-0.2.5 → python_constricter-0.2.8}/pyproject.toml +8 -2
  60. python_constricter-0.2.5/constricter/fix/project.py +0 -491
  61. python_constricter-0.2.5/constricter/fix/returned.py +0 -384
  62. python_constricter-0.2.5/constricter/fix/stdlib.json +0 -15351
  63. python_constricter-0.2.5/constricter/fix/stdlib.py +0 -186
  64. {python_constricter-0.2.5 → python_constricter-0.2.8}/LICENSE.md +0 -0
  65. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/__main__.py +0 -0
  66. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/__init__.py +0 -0
  67. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/baseline.py +0 -0
  68. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/explain.py +0 -0
  69. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/guard.py +0 -0
  70. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/cli/report.py +0 -0
  71. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/__init__.py +0 -0
  72. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/hinted.py +0 -0
  73. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/opened.py +0 -0
  74. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/returns.py +0 -0
  75. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/fix/targets.py +0 -0
  76. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/jsonc.py +0 -0
  77. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/noqa.py +0 -0
  78. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/notebook.py +0 -0
  79. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/plugins/__init__.py +0 -0
  80. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/plugins/flake8.py +0 -0
  81. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/plugins/pylint.py +0 -0
  82. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/py.typed +0 -0
  83. {python_constricter-0.2.5 → python_constricter-0.2.8}/constricter/rules/__init__.py +0 -0
  84. {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.5
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 method call of a local
235
- whose type is known, and values computed from those; a loop's target or an unpacking's names get a
236
- declaration on the line before. `--unsafe-fixes` adds guesses, and `--show-fixes` lists each fix and
237
- how its value decided it. `--infer-with basedpyright` (or `ty`, or `basedpyright,ty`, installed
238
- alongside) asks those type checkers for what `--fix` can't type itself, as guesses. The full list is
239
- in [docs/FIXES.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/FIXES.md).
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.3
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 method call of a local
208
- whose type is known, and values computed from those; a loop's target or an unpacking's names get a
209
- declaration on the line before. `--unsafe-fixes` adds guesses, and `--show-fixes` lists each fix and
210
- how its value decided it. `--infer-with basedpyright` (or `ty`, or `basedpyright,ty`, installed
211
- alongside) asks those type checkers for what `--fix` can't type itself, as guesses. The full list is
212
- in [docs/FIXES.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/FIXES.md).
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.3
240
+ rev: v0.2.8
238
241
  hooks:
239
242
  - id: constricter
240
243
  ```
@@ -25,7 +25,7 @@ from constricter.offences import (
25
25
  )
26
26
  from constricter.rules.checker import Coverage, annotation_coverage, check_source, check_tree
27
27
 
28
- __version__ = "0.2.5"
28
+ __version__ = "0.2.8"
29
29
  __all__ = [
30
30
  "COMMENT_TYPED_TARGET",
31
31
  "DEFAULT_CHECKS",
@@ -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)