python-constricter 0.2.5__py3-none-any.whl → 0.2.8__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.
Files changed (63) hide show
  1. constricter/__init__.py +1 -1
  2. constricter/cli/collecting.py +47 -0
  3. constricter/cli/command.py +188 -257
  4. constricter/cli/config.py +8 -15
  5. constricter/cli/hints.py +60 -127
  6. constricter/cli/options.py +36 -2
  7. constricter/cli/paths.py +31 -0
  8. constricter/cli/protocol.py +167 -0
  9. constricter/cli/runs.py +43 -0
  10. constricter/cli/schedule.py +224 -0
  11. constricter/cli/workers.py +154 -0
  12. constricter/fix/callers.py +153 -0
  13. constricter/fix/doubts.py +124 -22
  14. constricter/fix/fills.py +47 -45
  15. constricter/fix/fixes.py +60 -20
  16. constricter/fix/guesses.py +74 -11
  17. constricter/fix/imports.py +90 -26
  18. constricter/fix/inference.py +122 -77
  19. constricter/fix/installed.py +237 -0
  20. constricter/fix/known.py +122 -6
  21. constricter/fix/library.py +101 -0
  22. constricter/fix/members.py +19 -2
  23. constricter/fix/modules.py +339 -0
  24. constricter/fix/narrowed.py +164 -0
  25. constricter/fix/order.py +145 -0
  26. constricter/fix/overloads.py +514 -0
  27. constricter/fix/project.py +518 -275
  28. constricter/fix/returned.py +399 -80
  29. constricter/fix/stdlib.py +276 -52
  30. constricter/fix/tables/aliases.json +147 -0
  31. constricter/fix/tables/attributes.json +675 -0
  32. constricter/fix/tables/bases.json +888 -0
  33. constricter/fix/tables/classes.json +1939 -0
  34. constricter/fix/tables/generic_attributes.json +55 -0
  35. constricter/fix/tables/method_overloads.json +353 -0
  36. constricter/fix/tables/method_signatures.json +655 -0
  37. constricter/fix/tables/methods.json +857 -0
  38. constricter/fix/tables/overloads.json +499 -0
  39. constricter/fix/tables/returns.json +1328 -0
  40. constricter/fix/tables/source.json +4 -0
  41. constricter/fix/tables/subscriptable.json +76 -0
  42. constricter/fix/tables/type_parameters.json +175 -0
  43. constricter/fix/tables/variables.json +2938 -0
  44. constricter/offences.py +7 -1
  45. constricter/rules/annotations.py +55 -1
  46. constricter/rules/binding.py +251 -0
  47. constricter/rules/calls.py +211 -0
  48. constricter/rules/checker.py +266 -334
  49. constricter/rules/flow.py +2 -0
  50. constricter/rules/late.py +289 -0
  51. constricter/rules/narrowing.py +48 -1
  52. constricter/rules/parsed.py +18 -11
  53. constricter/rules/redundant.py +2 -8
  54. constricter/rules/scope.py +139 -231
  55. constricter/rules/syntax.py +98 -3
  56. constricter/rules/walked.py +59 -7
  57. {python_constricter-0.2.5.dist-info → python_constricter-0.2.8.dist-info}/METADATA +11 -8
  58. python_constricter-0.2.8.dist-info/RECORD +81 -0
  59. constricter/fix/stdlib.json +0 -15351
  60. python_constricter-0.2.5.dist-info/RECORD +0 -53
  61. {python_constricter-0.2.5.dist-info → python_constricter-0.2.8.dist-info}/WHEEL +0 -0
  62. {python_constricter-0.2.5.dist-info → python_constricter-0.2.8.dist-info}/entry_points.txt +0 -0
  63. {python_constricter-0.2.5.dist-info → python_constricter-0.2.8.dist-info}/licenses/LICENSE.md +0 -0
constricter/__init__.py CHANGED
@@ -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)