python-constricter 0.4.1__tar.gz → 0.4.3__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.4.1 → python_constricter-0.4.3}/.gitignore +0 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/PKG-INFO +28 -11
- {python_constricter-0.4.1 → python_constricter-0.4.3}/README.md +27 -10
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/__main__.py +3 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/_version.py +1 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/baseline.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/collecting.py +6 -4
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/command.py +22 -8
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/config.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/explain.py +13 -1
- python_constricter-0.4.3/constricter/cli/lsp/__init__.py +1 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/connection.py +14 -12
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/edits.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/guard.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/hints.py +151 -44
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/protocol.py +14 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/remembered.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/lsp/stored.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/options.py +15 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/paths.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/reading.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/report.py +1 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/rounds.py +14 -9
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/runs.py +33 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/schedule.py +30 -7
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/traced.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/cli/workers.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/empty.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/asked.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/fixes.py +11 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/imports.py +27 -11
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/inherited.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/known.py +20 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/core/signatures.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/__init__.py +0 -1
- python_constricter-0.4.3/constricter/fix/index/annotated.py +83 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/awaits.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/beyond.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/callers.py +0 -1
- python_constricter-0.4.3/constricter/fix/index/consistent.py +142 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/crossed.py +27 -7
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/decorated.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/fixtures.py +15 -8
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/linked.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/loose.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/managed.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/modules.py +25 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/offers.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/order.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/origins.py +2 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/own_methods.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/own_overloads.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/own_types.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/params.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/plain.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/project.py +80 -12
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/sides.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/strings.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/atoms.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/chained.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/classnames.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/declared.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/installed.py +45 -19
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/names.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/read.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/signatures.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/stubs/stubbed.py +4 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/taken.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/index/tuples.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/__init__.py +0 -1
- python_constricter-0.4.3/constricter/fix/libraries/generics.py +50 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/library.py +50 -12
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/opened.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/overloads.py +93 -63
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/receivers.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/stdlib.py +32 -4
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/libraries/walks.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/source.json +1 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/aliased.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/bodies.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/callables.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/called.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/classvars.py +10 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/decided.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/displays.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/doubts.py +25 -4
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/entered.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/fills.py +158 -13
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/guesses.py +13 -7
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/hinted.py +174 -34
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/inference.py +20 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/loops.py +2 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/members.py +152 -15
- python_constricter-0.4.3/constricter/fix/values/narrowed.py +481 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/operated.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/ordered.py +0 -1
- python_constricter-0.4.3/constricter/fix/values/reads.py +356 -0
- python_constricter-0.4.3/constricter/fix/values/refused.py +87 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/returned.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/returns.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/shapes.py +20 -9
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/stored.py +40 -13
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/targets.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/values/unchecked.py +25 -12
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/jsonc.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/noqa.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/notebook.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/offences.py +18 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/overrides.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/plugins/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/plugins/flake8.py +19 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/plugins/pylint.py +7 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/recording.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/annotations.py +0 -1
- python_constricter-0.4.3/constricter/rules/attributes.py +259 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/binding.py +119 -35
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/calls.py +62 -7
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/checker.py +36 -7
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/declarations.py +161 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/decorators.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/flow.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/keys.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/late.py +32 -13
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/narrowing.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/parsed.py +1 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/quoted.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/rebinding.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/recorded.py +6 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/redundant.py +0 -1
- python_constricter-0.4.3/constricter/rules/returning.py +231 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/scope.py +180 -32
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/scoped.py +7 -2
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/scoping.py +2 -4
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/settings.py +35 -4
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/syntax.py +63 -18
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/tables.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/walked.py +17 -11
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/rules/widened.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/trace.py +94 -28
- {python_constricter-0.4.1 → python_constricter-0.4.3}/hatch_build.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/mypyc.txt +3 -3
- {python_constricter-0.4.1 → python_constricter-0.4.3}/pyproject.toml +12 -12
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/__init__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/__main__.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/accepting.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/configured.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/elements.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/forms.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/generate.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/overloads.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/reading.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/shed.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/stubs.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/templates.py +0 -1
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/written.py +0 -1
- python_constricter-0.4.1/constricter/cli/lsp/__init__.py +0 -2
- python_constricter-0.4.1/constricter/fix/values/narrowed.py +0 -220
- {python_constricter-0.4.1 → python_constricter-0.4.3}/LICENSE.md +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/aliases.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/attributes.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/awaited.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/awaited_overloads.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/bases.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/classes.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/elements.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/functions.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/generic_attributes.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/method_overloads.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/method_signatures.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/methods.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/overloads.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/platform.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/returns.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/scalar_members.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/scalars.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/subscriptable.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/type_parameters.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/fix/tables/variables.json +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/constricter/py.typed +0 -0
- {python_constricter-0.4.1 → python_constricter-0.4.3}/stdlib_tables/partial.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-constricter
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
4
4
|
Import-Name: constricter
|
|
5
5
|
Summary: Lint rules: every local variable is typed where it's first bound. A flake8 plugin, a pylint plugin and a standalone CLI.
|
|
6
6
|
Author: Ivy Duggan
|
|
@@ -105,6 +105,8 @@ class bodies too. Statements are read in source order, and only a name's first b
|
|
|
105
105
|
| `LVA010` | with every value known: a union member no value is | drop the member |
|
|
106
106
|
| `LVA011` | an annotation listing a fixed-length tuple of more than `max-length` types (4 by default) | name the fields (a `NamedTuple`, a dataclass) |
|
|
107
107
|
| `LVA012` | opt-in: a local bound once, outside any loop, and never rebound | `name: Final = ...` |
|
|
108
|
+
| `LVA013` | opt-in: an instance attribute a plain class's method first stores, declared nowhere in it | `self.x: T = ...` |
|
|
109
|
+
| `LVA014` | opt-in: a plain function that declares no return type | `def f(...) -> T:` |
|
|
108
110
|
|
|
109
111
|
Exempt: comprehensions, `except ... as`, imports, `def`/`class`, `type` aliases, parameters,
|
|
110
112
|
`global`/`nonlocal`, and `_`; in module and class bodies, dunder names (`__all__`, `__slots__`) and
|
|
@@ -117,7 +119,8 @@ type checker: `T = TypeVar("T")`, a `ParamSpec`, a `TypeVarTuple`, a `NewType`,
|
|
|
117
119
|
A `# type:` comment (`x = 1 # type: int`, `with f() as x: # type: T`) counts as an annotation with
|
|
118
120
|
`type-comments`, or automatically in a module written to run on Python 2: one that imports
|
|
119
121
|
`print_function`, `unicode_literals`, `absolute_import`, `division`, `with_statement`, `generators`
|
|
120
|
-
or `nested_scopes` from `__future__`.
|
|
122
|
+
or `nested_scopes` from `__future__`. Otherwise it's `LVA001`, and `--fix` writes the comment's type
|
|
123
|
+
as the annotation and drops the comment.
|
|
121
124
|
|
|
122
125
|
`LVA007` compares a block on its own: an `if`'s body and its `orelse`, a `try`'s body and its
|
|
123
126
|
`except`s, and the like, are different blocks, since they don't both run in the same pass.
|
|
@@ -154,29 +157,41 @@ or SARIF `warning` in those formats) but exits 0; flake8 and pylint report error
|
|
|
154
157
|
at every level, and an error only at `suffocate`: on the corpus, 45–70% of every codebase's first
|
|
155
158
|
bindings qualify, so it suits a codebase that wants `Final` everywhere it can go, not a default.
|
|
156
159
|
|
|
160
|
+
`LVA013` is opt-in the same way (pylint's `enable = unannotated-instance-attribute`), and an error
|
|
161
|
+
from `strict`, as `LVA001` is. It reports an instance attribute a plain class's method stores
|
|
162
|
+
(`self.count = 0`) that no annotation in the class declares, at its first plain `self.x = value`:
|
|
163
|
+
a class the module defines once, with no keyword (a metaclass), on no base but `object` or another
|
|
164
|
+
such class, since another file's base may declare the attribute itself. Dunders, stores in a
|
|
165
|
+
nested function, and names the class's body or a base of the module's binds are left out.
|
|
166
|
+
|
|
167
|
+
`LVA014` is opt-in too (pylint's `enable = missing-return-type`), an error from `strict`. It
|
|
168
|
+
reports a plain function or method (not decorated) with no return annotation, as ruff's `ANN201`
|
|
169
|
+
does; its fix is what the function's own `return`s give (`-> int`, a method's a guess), or `-> None`
|
|
170
|
+
for one that returns nothing, where the type names only what the module already binds.
|
|
171
|
+
|
|
157
172
|
Python 3.11+, no runtime dependencies.
|
|
158
173
|
|
|
159
174
|
## Use
|
|
160
175
|
|
|
161
176
|
| Tool | Setup | Reports | Suppress |
|
|
162
177
|
| ------ | ----------------------------------------------------- | ------------------------------- | ------------------------------------------------ |
|
|
163
|
-
| CLI | `constricter [PATH...] [--level L] [--format F] [-q]` | `LVA001`–`
|
|
164
|
-
| flake8 | install it (on by default) | `LVA001`–`
|
|
165
|
-
| pylint | `load-plugins = ["constricter.plugins.pylint"]` | `C9101`–`
|
|
166
|
-
| ruff | run the CLI after ruff; set `lint.external = ["LVA"]` | `LVA001`–`
|
|
178
|
+
| CLI | `constricter [PATH...] [--level L] [--format F] [-q]` | `LVA001`–`LVA014` | `# noqa: LVA001` |
|
|
179
|
+
| flake8 | install it (on by default) | `LVA001`–`LVA014` | `# noqa: LVA001` |
|
|
180
|
+
| pylint | `load-plugins = ["constricter.plugins.pylint"]` | `C9101`–`C9114` (symbols below) | `# noqa: LVA001` or `# pylint: disable=<symbol>` |
|
|
181
|
+
| ruff | run the CLI after ruff; set `lint.external = ["LVA"]` | `LVA001`–`LVA014` | `# noqa: LVA001` |
|
|
167
182
|
|
|
168
183
|
pylint symbols: `unannotated-local-variable`, `untyped-for-or-match-variable`,
|
|
169
184
|
`comment-typed-for-variable`, `unannotated-module-or-class-variable`, `vague-annotation`,
|
|
170
185
|
`deeply-nested-annotation`, `redundant-annotation`, `narrowable-annotation`,
|
|
171
|
-
`mismatched-value-type`, `unused-union-member`, `long-tuple-annotation`,
|
|
172
|
-
|
|
186
|
+
`mismatched-value-type`, `unused-union-member`, `long-tuple-annotation`, and, off until enabled,
|
|
187
|
+
`could-be-final`, `unannotated-instance-attribute` and `missing-return-type`.
|
|
173
188
|
|
|
174
189
|
Options:
|
|
175
190
|
|
|
176
191
|
| Option | CLI | `[tool.constricter]` | flake8 (CLI or config) | pylint |
|
|
177
192
|
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------- | --------------------------------- |
|
|
178
193
|
| level | `--level` | `level` | `--constricter-level` | `constricter-level` |
|
|
179
|
-
| strictest | `--max`: `--level=suffocate` for every path, `--all-scopes`, and the opt-in `LVA012`
|
|
194
|
+
| strictest | `--max`: `--level=suffocate` for every path, `--all-scopes`, and the opt-in `LVA012` and `LVA013` | — | — | — |
|
|
180
195
|
| every fix | `--max-fix`: `--max`, `--fix --unsafe-fixes`, and `--infer-with` each of basedpyright, ty and pyrefly that's installed and runs | — | — | — |
|
|
181
196
|
| type comments | `--type-comments` | `type-comments` | `--constricter-type-comments` | `constricter-type-comments = yes` |
|
|
182
197
|
| all scopes | `--all-scopes` | `all-scopes` | `--constricter-all-scopes` | `constricter-all-scopes = yes` |
|
|
@@ -369,7 +384,7 @@ it to code scanning (the job needs `security-events: write`; the
|
|
|
369
384
|
```yaml
|
|
370
385
|
- run: constricter --format=sarif src > constricter.sarif
|
|
371
386
|
- if: ${{ !cancelled() }} # upload the findings even when the step above failed on them
|
|
372
|
-
uses: github/codeql-action/upload-sarif@
|
|
387
|
+
uses: github/codeql-action/upload-sarif@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0
|
|
373
388
|
with:
|
|
374
389
|
sarif_file: constricter.sarif
|
|
375
390
|
category: constricter
|
|
@@ -386,8 +401,10 @@ are in
|
|
|
386
401
|
|
|
387
402
|
## Roadmap
|
|
388
403
|
|
|
389
|
-
What's
|
|
404
|
+
What's next, by size:
|
|
390
405
|
[docs/ROADMAP.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/ROADMAP.md).
|
|
406
|
+
What's done, by scope:
|
|
407
|
+
[docs/COMPLETED.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/COMPLETED.md).
|
|
391
408
|
|
|
392
409
|
## AI usage
|
|
393
410
|
|
|
@@ -78,6 +78,8 @@ class bodies too. Statements are read in source order, and only a name's first b
|
|
|
78
78
|
| `LVA010` | with every value known: a union member no value is | drop the member |
|
|
79
79
|
| `LVA011` | an annotation listing a fixed-length tuple of more than `max-length` types (4 by default) | name the fields (a `NamedTuple`, a dataclass) |
|
|
80
80
|
| `LVA012` | opt-in: a local bound once, outside any loop, and never rebound | `name: Final = ...` |
|
|
81
|
+
| `LVA013` | opt-in: an instance attribute a plain class's method first stores, declared nowhere in it | `self.x: T = ...` |
|
|
82
|
+
| `LVA014` | opt-in: a plain function that declares no return type | `def f(...) -> T:` |
|
|
81
83
|
|
|
82
84
|
Exempt: comprehensions, `except ... as`, imports, `def`/`class`, `type` aliases, parameters,
|
|
83
85
|
`global`/`nonlocal`, and `_`; in module and class bodies, dunder names (`__all__`, `__slots__`) and
|
|
@@ -90,7 +92,8 @@ type checker: `T = TypeVar("T")`, a `ParamSpec`, a `TypeVarTuple`, a `NewType`,
|
|
|
90
92
|
A `# type:` comment (`x = 1 # type: int`, `with f() as x: # type: T`) counts as an annotation with
|
|
91
93
|
`type-comments`, or automatically in a module written to run on Python 2: one that imports
|
|
92
94
|
`print_function`, `unicode_literals`, `absolute_import`, `division`, `with_statement`, `generators`
|
|
93
|
-
or `nested_scopes` from `__future__`.
|
|
95
|
+
or `nested_scopes` from `__future__`. Otherwise it's `LVA001`, and `--fix` writes the comment's type
|
|
96
|
+
as the annotation and drops the comment.
|
|
94
97
|
|
|
95
98
|
`LVA007` compares a block on its own: an `if`'s body and its `orelse`, a `try`'s body and its
|
|
96
99
|
`except`s, and the like, are different blocks, since they don't both run in the same pass.
|
|
@@ -127,29 +130,41 @@ or SARIF `warning` in those formats) but exits 0; flake8 and pylint report error
|
|
|
127
130
|
at every level, and an error only at `suffocate`: on the corpus, 45–70% of every codebase's first
|
|
128
131
|
bindings qualify, so it suits a codebase that wants `Final` everywhere it can go, not a default.
|
|
129
132
|
|
|
133
|
+
`LVA013` is opt-in the same way (pylint's `enable = unannotated-instance-attribute`), and an error
|
|
134
|
+
from `strict`, as `LVA001` is. It reports an instance attribute a plain class's method stores
|
|
135
|
+
(`self.count = 0`) that no annotation in the class declares, at its first plain `self.x = value`:
|
|
136
|
+
a class the module defines once, with no keyword (a metaclass), on no base but `object` or another
|
|
137
|
+
such class, since another file's base may declare the attribute itself. Dunders, stores in a
|
|
138
|
+
nested function, and names the class's body or a base of the module's binds are left out.
|
|
139
|
+
|
|
140
|
+
`LVA014` is opt-in too (pylint's `enable = missing-return-type`), an error from `strict`. It
|
|
141
|
+
reports a plain function or method (not decorated) with no return annotation, as ruff's `ANN201`
|
|
142
|
+
does; its fix is what the function's own `return`s give (`-> int`, a method's a guess), or `-> None`
|
|
143
|
+
for one that returns nothing, where the type names only what the module already binds.
|
|
144
|
+
|
|
130
145
|
Python 3.11+, no runtime dependencies.
|
|
131
146
|
|
|
132
147
|
## Use
|
|
133
148
|
|
|
134
149
|
| Tool | Setup | Reports | Suppress |
|
|
135
150
|
| ------ | ----------------------------------------------------- | ------------------------------- | ------------------------------------------------ |
|
|
136
|
-
| CLI | `constricter [PATH...] [--level L] [--format F] [-q]` | `LVA001`–`
|
|
137
|
-
| flake8 | install it (on by default) | `LVA001`–`
|
|
138
|
-
| pylint | `load-plugins = ["constricter.plugins.pylint"]` | `C9101`–`
|
|
139
|
-
| ruff | run the CLI after ruff; set `lint.external = ["LVA"]` | `LVA001`–`
|
|
151
|
+
| CLI | `constricter [PATH...] [--level L] [--format F] [-q]` | `LVA001`–`LVA014` | `# noqa: LVA001` |
|
|
152
|
+
| flake8 | install it (on by default) | `LVA001`–`LVA014` | `# noqa: LVA001` |
|
|
153
|
+
| pylint | `load-plugins = ["constricter.plugins.pylint"]` | `C9101`–`C9114` (symbols below) | `# noqa: LVA001` or `# pylint: disable=<symbol>` |
|
|
154
|
+
| ruff | run the CLI after ruff; set `lint.external = ["LVA"]` | `LVA001`–`LVA014` | `# noqa: LVA001` |
|
|
140
155
|
|
|
141
156
|
pylint symbols: `unannotated-local-variable`, `untyped-for-or-match-variable`,
|
|
142
157
|
`comment-typed-for-variable`, `unannotated-module-or-class-variable`, `vague-annotation`,
|
|
143
158
|
`deeply-nested-annotation`, `redundant-annotation`, `narrowable-annotation`,
|
|
144
|
-
`mismatched-value-type`, `unused-union-member`, `long-tuple-annotation`,
|
|
145
|
-
|
|
159
|
+
`mismatched-value-type`, `unused-union-member`, `long-tuple-annotation`, and, off until enabled,
|
|
160
|
+
`could-be-final`, `unannotated-instance-attribute` and `missing-return-type`.
|
|
146
161
|
|
|
147
162
|
Options:
|
|
148
163
|
|
|
149
164
|
| Option | CLI | `[tool.constricter]` | flake8 (CLI or config) | pylint |
|
|
150
165
|
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------- | --------------------------------- |
|
|
151
166
|
| level | `--level` | `level` | `--constricter-level` | `constricter-level` |
|
|
152
|
-
| strictest | `--max`: `--level=suffocate` for every path, `--all-scopes`, and the opt-in `LVA012`
|
|
167
|
+
| strictest | `--max`: `--level=suffocate` for every path, `--all-scopes`, and the opt-in `LVA012` and `LVA013` | — | — | — |
|
|
153
168
|
| every fix | `--max-fix`: `--max`, `--fix --unsafe-fixes`, and `--infer-with` each of basedpyright, ty and pyrefly that's installed and runs | — | — | — |
|
|
154
169
|
| type comments | `--type-comments` | `type-comments` | `--constricter-type-comments` | `constricter-type-comments = yes` |
|
|
155
170
|
| all scopes | `--all-scopes` | `all-scopes` | `--constricter-all-scopes` | `constricter-all-scopes = yes` |
|
|
@@ -342,7 +357,7 @@ it to code scanning (the job needs `security-events: write`; the
|
|
|
342
357
|
```yaml
|
|
343
358
|
- run: constricter --format=sarif src > constricter.sarif
|
|
344
359
|
- if: ${{ !cancelled() }} # upload the findings even when the step above failed on them
|
|
345
|
-
uses: github/codeql-action/upload-sarif@
|
|
360
|
+
uses: github/codeql-action/upload-sarif@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0
|
|
346
361
|
with:
|
|
347
362
|
sarif_file: constricter.sarif
|
|
348
363
|
category: constricter
|
|
@@ -359,8 +374,10 @@ are in
|
|
|
359
374
|
|
|
360
375
|
## Roadmap
|
|
361
376
|
|
|
362
|
-
What's
|
|
377
|
+
What's next, by size:
|
|
363
378
|
[docs/ROADMAP.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/ROADMAP.md).
|
|
379
|
+
What's done, by scope:
|
|
380
|
+
[docs/COMPLETED.md](https://github.com/ivylikethevine/python-constricter/blob/main/docs/COMPLETED.md).
|
|
364
381
|
|
|
365
382
|
## AI usage
|
|
366
383
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MIT
|
|
2
1
|
"""`python -m constricter`, and the `constricter` script."""
|
|
3
2
|
|
|
4
3
|
import contextlib
|
|
@@ -13,9 +12,10 @@ def run() -> None:
|
|
|
13
12
|
|
|
14
13
|
Not by the interpreter's own exit, which frees every parsed file and the index an object at a
|
|
15
14
|
time: a fifth of a check of a thousand files. What the command wrote is flushed first; nothing
|
|
16
|
-
else waits on the exit (its workers have ended, its output file is closed).
|
|
15
|
+
else waits on the exit (its workers have ended, its output file is closed). Nor is the collector
|
|
16
|
+
turned on again for it (`leaving`).
|
|
17
17
|
"""
|
|
18
|
-
status: int = main()
|
|
18
|
+
status: int = main(leaving=True)
|
|
19
19
|
with contextlib.suppress(OSError, ValueError): # a reader that left, a stream closed already
|
|
20
20
|
_ = sys.stdout.flush()
|
|
21
21
|
_ = sys.stderr.flush()
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MIT
|
|
2
1
|
"""The garbage collector, as the command runs it: by hand, once per file checked.
|
|
3
2
|
|
|
4
3
|
A check keeps every file's tree (see `parsed`), and allocates a great deal for each file, little of it
|
|
@@ -24,9 +23,12 @@ _YOUNGER: Final = not sysconfig.get_config_var("Py_GIL_DISABLED")
|
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
@contextlib.contextmanager
|
|
27
|
-
def by_hand() -> Generator[None]:
|
|
26
|
+
def by_hand(*, leaving: bool = False) -> Generator[None]:
|
|
28
27
|
"""Turn automatic collection off for the command's run, and back as it was after.
|
|
29
28
|
|
|
29
|
+
Not for a process that leaves once the run's done (`leaving`): turned on again, the collector
|
|
30
|
+
looked through all the run left alive, at once (a check of pandas: 3.4s, for nothing).
|
|
31
|
+
|
|
30
32
|
Yields:
|
|
31
33
|
Nothing: the run.
|
|
32
34
|
|
|
@@ -36,9 +38,9 @@ def by_hand() -> Generator[None]:
|
|
|
36
38
|
try:
|
|
37
39
|
yield
|
|
38
40
|
finally:
|
|
39
|
-
if _FREEZES:
|
|
41
|
+
if _FREEZES and not leaving:
|
|
40
42
|
gc.unfreeze()
|
|
41
|
-
if was:
|
|
43
|
+
if was and not leaving:
|
|
42
44
|
gc.enable()
|
|
43
45
|
|
|
44
46
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MIT
|
|
2
1
|
"""The `constricter` command (see README)."""
|
|
3
2
|
|
|
4
3
|
import codecs
|
|
@@ -36,6 +35,8 @@ from constricter.rules import parsed
|
|
|
36
35
|
from constricter.rules.checker import Checked, Coverage, annotation_coverage, checked_source
|
|
37
36
|
|
|
38
37
|
if TYPE_CHECKING: # slow to import, and only needed for `--infer-with`
|
|
38
|
+
from types import ModuleType
|
|
39
|
+
|
|
39
40
|
from constricter.cli.lsp import hints
|
|
40
41
|
|
|
41
42
|
EXIT_CLEAN: Final = 0
|
|
@@ -370,12 +371,17 @@ def _check_rounds(options: Options) -> tuple[list[Path], list[FileRun]]:
|
|
|
370
371
|
return names, settled(paths, check, options, None)
|
|
371
372
|
session: hints.Session
|
|
372
373
|
# Imported only for `--infer-with`: it's slow to import, for every run's start.
|
|
373
|
-
|
|
374
|
+
hinting: ModuleType = importlib.import_module("constricter.cli.lsp.hints")
|
|
375
|
+
asking: hints.Asking = cast("type[hints.Asking]", hinting.Asking)(
|
|
376
|
+
kept=not options.infer_fresh,
|
|
377
|
+
in_turn=options.infer_in_turn,
|
|
378
|
+
)
|
|
379
|
+
with cast("type[hints.Session]", hinting.Session)(
|
|
374
380
|
options.infer_with,
|
|
375
381
|
Path.cwd(),
|
|
376
382
|
options.jobs,
|
|
377
383
|
options.infer_memory,
|
|
378
|
-
|
|
384
|
+
asking,
|
|
379
385
|
) as session:
|
|
380
386
|
runs: list[FileRun] = settled(paths, check, options, session)
|
|
381
387
|
checker: str
|
|
@@ -383,6 +389,11 @@ def _check_rounds(options: Options) -> tuple[list[Path], list[FileRun]]:
|
|
|
383
389
|
for checker, path in session.abandoned:
|
|
384
390
|
name: Path = options.input.name(path)
|
|
385
391
|
_ = sys.stderr.write(f"constricter: warning: {checker} hung on {name} twice: no hints for it\n")
|
|
392
|
+
read: int
|
|
393
|
+
rounds: int
|
|
394
|
+
for checker, read, rounds in session.reused:
|
|
395
|
+
told: str = f"{checker}'s hints for {read} of {rounds} rounds were read from the store"
|
|
396
|
+
_ = sys.stderr.write(f"constricter: note: {told} (`--infer-fresh` asks again)\n")
|
|
386
397
|
return names, runs
|
|
387
398
|
|
|
388
399
|
|
|
@@ -485,8 +496,8 @@ def _typed(found: Coverage) -> str:
|
|
|
485
496
|
return f"{found.typed}/{found.total} typed ({found.percent:.1f}%){wider}"
|
|
486
497
|
|
|
487
498
|
|
|
488
|
-
def _run(options: Options) -> int:
|
|
489
|
-
"""Check, fix, diff, count or baseline, printing what that finds.
|
|
499
|
+
def _run(options: Options, *, leaving: bool) -> int:
|
|
500
|
+
"""Check, fix, diff, count or baseline, printing what that finds (`leaving`: see `main`).
|
|
490
501
|
|
|
491
502
|
Returns:
|
|
492
503
|
The exit status.
|
|
@@ -494,7 +505,7 @@ def _run(options: Options) -> int:
|
|
|
494
505
|
"""
|
|
495
506
|
names: list[Path]
|
|
496
507
|
runs: list[FileRun]
|
|
497
|
-
with collecting.by_hand():
|
|
508
|
+
with collecting.by_hand(leaving=leaving):
|
|
498
509
|
try:
|
|
499
510
|
names, runs = _check_all(options)
|
|
500
511
|
except HintError as error:
|
|
@@ -527,9 +538,12 @@ def _run(options: Options) -> int:
|
|
|
527
538
|
return EXIT_ERROR if failed else status
|
|
528
539
|
|
|
529
540
|
|
|
530
|
-
def main(argv: Sequence[str] | None = None) -> int:
|
|
541
|
+
def main(argv: Sequence[str] | None = None, *, leaving: bool = False) -> int:
|
|
531
542
|
"""Run the command.
|
|
532
543
|
|
|
544
|
+
`leaving`: the process leaves once it's done (`constricter.__main__.run`), its collector as the
|
|
545
|
+
run left it (see `collecting.by_hand`).
|
|
546
|
+
|
|
533
547
|
Returns:
|
|
534
548
|
Its exit status.
|
|
535
549
|
|
|
@@ -543,5 +557,5 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
543
557
|
else contextlib.nullcontext(sys.stdout) as stream,
|
|
544
558
|
contextlib.redirect_stdout(stream),
|
|
545
559
|
):
|
|
546
|
-
status: int = _run(options)
|
|
560
|
+
status: int = _run(options, leaving=leaving)
|
|
547
561
|
return EXIT_CLEAN if options.output.exit_zero and status == EXIT_FOUND else status
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MIT
|
|
2
1
|
"""Each code's rationale and fix, for `constricter --explain`."""
|
|
3
2
|
|
|
4
3
|
from typing import Final
|
|
@@ -14,7 +13,9 @@ from constricter.offences import (
|
|
|
14
13
|
OPT_IN,
|
|
15
14
|
REDUNDANT_TYPE,
|
|
16
15
|
UNANNOTATED,
|
|
16
|
+
UNANNOTATED_ATTRIBUTE,
|
|
17
17
|
UNANNOTATED_MEMBER,
|
|
18
|
+
UNANNOTATED_RETURN,
|
|
18
19
|
UNTYPED_TARGET,
|
|
19
20
|
UNUSED_UNION_MEMBER,
|
|
20
21
|
VAGUE_TYPE,
|
|
@@ -83,6 +84,17 @@ _WHY: Final = {
|
|
|
83
84
|
"(not from a nested function either) could say so: `limit: Final = 10`. Off unless selected\n"
|
|
84
85
|
"by its full code (`--extend-select LVA012`): most locals are bound once."
|
|
85
86
|
),
|
|
87
|
+
UNANNOTATED_ATTRIBUTE: (
|
|
88
|
+
"An instance attribute a plain class's method first stores (`self.count = 0`), declared\n"
|
|
89
|
+
"nowhere in the class, is typed by whatever a type checker infers from that store. Annotate\n"
|
|
90
|
+
"it there: `self.count: int = 0`. Off unless selected by its full code (`--extend-select LVA013`)."
|
|
91
|
+
),
|
|
92
|
+
UNANNOTATED_RETURN: (
|
|
93
|
+
"A plain function with no return annotation leaves its callers to whatever a type checker\n"
|
|
94
|
+
"infers. `--fix` writes what its own `return`s give (`-> int`), or `-> None` for one that\n"
|
|
95
|
+
"returns nothing. Off unless selected by its full code (`--extend-select LVA014`): ruff's ANN201\n"
|
|
96
|
+
"reports it too; this is for the fix."
|
|
97
|
+
),
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""constricter.cli.lsp."""
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MIT
|
|
2
1
|
"""A running language server, and the JSON-RPC conversation with it (`Connection`), for `hints`.
|
|
3
2
|
|
|
4
3
|
The files it has open, the hint requests sent and not yet answered, and what it has said.
|
|
@@ -22,7 +21,7 @@ from pathlib import Path
|
|
|
22
21
|
from typing import IO, Final, NamedTuple, TypeAlias, cast
|
|
23
22
|
|
|
24
23
|
from constricter.cli.lsp import edits, guard, protocol
|
|
25
|
-
from constricter.cli.lsp.protocol import HintError, HungError
|
|
24
|
+
from constricter.cli.lsp.protocol import ExitedError, HintError, HungError
|
|
26
25
|
from constricter.fix.core.known import Offered
|
|
27
26
|
|
|
28
27
|
_Json: TypeAlias = protocol.Json
|
|
@@ -79,22 +78,24 @@ class _Documents:
|
|
|
79
78
|
texts: dict[str, str] = field(default_factory=dict[str, str])
|
|
80
79
|
|
|
81
80
|
|
|
82
|
-
class
|
|
81
|
+
class Asked(NamedTuple):
|
|
83
82
|
"""Hint requests sent, not yet answered: each request's file, and each file's lines."""
|
|
84
83
|
|
|
85
84
|
numbers: dict[int, Path]
|
|
86
85
|
lines: dict[Path, list[str]]
|
|
87
86
|
|
|
88
87
|
|
|
89
|
-
Sent: TypeAlias = tuple[dict[Path, str],
|
|
88
|
+
Sent: TypeAlias = tuple[dict[Path, str], Asked] # a batch of files, and its hint requests
|
|
90
89
|
|
|
91
90
|
|
|
92
91
|
class Connection:
|
|
93
92
|
"""A running language server, and the JSON-RPC conversation with it."""
|
|
94
93
|
|
|
95
|
-
def __init__(self, argv: Sequence[str], root: Path) -> None:
|
|
94
|
+
def __init__(self, argv: Sequence[str], root: Path, environment: Mapping[str, str] | None = None) -> None:
|
|
96
95
|
"""Start the server (`argv`) and initialize it, with `root` as its one workspace folder.
|
|
97
96
|
|
|
97
|
+
In `environment`, or else this process's.
|
|
98
|
+
|
|
98
99
|
Raises:
|
|
99
100
|
HintError: It can't be started, or fails to initialize.
|
|
100
101
|
|
|
@@ -115,6 +116,7 @@ class Connection:
|
|
|
115
116
|
stdout=subprocess.PIPE,
|
|
116
117
|
stderr=subprocess.DEVNULL,
|
|
117
118
|
cwd=root,
|
|
119
|
+
env=environment,
|
|
118
120
|
),
|
|
119
121
|
)
|
|
120
122
|
self.inbox: _Inbox = _Inbox()
|
|
@@ -188,7 +190,7 @@ class Connection:
|
|
|
188
190
|
return False
|
|
189
191
|
return True
|
|
190
192
|
|
|
191
|
-
def ask(self, files: Mapping[Path, str]) -> "
|
|
193
|
+
def ask(self, files: Mapping[Path, str]) -> "Asked":
|
|
192
194
|
"""Open each file (or send its new text), and ask for its hints over the whole of it.
|
|
193
195
|
|
|
194
196
|
It doesn't wait for them. Each file is left open: basedpyright (1.40) fails the next file's
|
|
@@ -204,7 +206,7 @@ class Connection:
|
|
|
204
206
|
text: str
|
|
205
207
|
for path, text in files.items():
|
|
206
208
|
self._opened(path.resolve().as_uri(), text)
|
|
207
|
-
return
|
|
209
|
+
return Asked({self._ask_hints(path, lines[path]): path for path in files}, lines)
|
|
208
210
|
|
|
209
211
|
def _ask_hints(self, path: Path, lines: Sequence[str]) -> int:
|
|
210
212
|
"""Ask for an open file's hints over the whole of it, without waiting for them.
|
|
@@ -221,7 +223,7 @@ class Connection:
|
|
|
221
223
|
},
|
|
222
224
|
)
|
|
223
225
|
|
|
224
|
-
def answers(self, asked: "
|
|
226
|
+
def answers(self, asked: "Asked") -> Found:
|
|
225
227
|
"""Wait for the answers to hint requests `ask` sent, asking again for those the server dropped.
|
|
226
228
|
|
|
227
229
|
Returns:
|
|
@@ -391,7 +393,7 @@ class Connection:
|
|
|
391
393
|
It.
|
|
392
394
|
|
|
393
395
|
Raises:
|
|
394
|
-
|
|
396
|
+
ExitedError: The server exited (`_waited` raises `HungError` where it took too long).
|
|
395
397
|
|
|
396
398
|
"""
|
|
397
399
|
# `_waited` raises rather than end: there is always a next message, or an error.
|
|
@@ -400,7 +402,7 @@ class Connection:
|
|
|
400
402
|
)
|
|
401
403
|
if message is None:
|
|
402
404
|
error: str = f"{self.name} exited while answering `{method}`"
|
|
403
|
-
raise
|
|
405
|
+
raise ExitedError(error)
|
|
404
406
|
return message
|
|
405
407
|
|
|
406
408
|
def _waited(self, method: str) -> _Object | None:
|
|
@@ -460,7 +462,7 @@ class Connection:
|
|
|
460
462
|
"""Frame and send one message.
|
|
461
463
|
|
|
462
464
|
Raises:
|
|
463
|
-
|
|
465
|
+
ExitedError: The server has exited.
|
|
464
466
|
|
|
465
467
|
"""
|
|
466
468
|
body: bytes = json.dumps(message).encode()
|
|
@@ -472,4 +474,4 @@ class Connection:
|
|
|
472
474
|
)
|
|
473
475
|
except (OSError, ValueError) as error: # it has gone, or its input was closed to stop it
|
|
474
476
|
failure: str = f"{self.name} exited: {error}"
|
|
475
|
-
raise
|
|
477
|
+
raise ExitedError(failure) from error
|