]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/flake8/plugins/pyflakes.py
1 """Plugin built-in to Flake8 to treat pyflakes as a plugin."""
2 from __future__
import annotations
9 from typing
import Generator
11 import pyflakes
.checker
13 from flake8
import utils
14 from flake8
.options
.manager
import OptionManager
16 LOG
= logging
.getLogger(__name__
)
18 FLAKE8_PYFLAKES_CODES
= {
19 "UnusedImport": "F401",
20 "ImportShadowedByLoopVar": "F402",
21 "ImportStarUsed": "F403",
22 "LateFutureImport": "F404",
23 "ImportStarUsage": "F405",
24 "ImportStarNotPermitted": "F406",
25 "FutureFeatureNotDefined": "F407",
26 "PercentFormatInvalidFormat": "F501",
27 "PercentFormatExpectedMapping": "F502",
28 "PercentFormatExpectedSequence": "F503",
29 "PercentFormatExtraNamedArguments": "F504",
30 "PercentFormatMissingArgument": "F505",
31 "PercentFormatMixedPositionalAndNamed": "F506",
32 "PercentFormatPositionalCountMismatch": "F507",
33 "PercentFormatStarRequiresSequence": "F508",
34 "PercentFormatUnsupportedFormatCharacter": "F509",
35 "StringDotFormatInvalidFormat": "F521",
36 "StringDotFormatExtraNamedArguments": "F522",
37 "StringDotFormatExtraPositionalArguments": "F523",
38 "StringDotFormatMissingArgument": "F524",
39 "StringDotFormatMixingAutomatic": "F525",
40 "FStringMissingPlaceholders": "F541",
41 "MultiValueRepeatedKeyLiteral": "F601",
42 "MultiValueRepeatedKeyVariable": "F602",
43 "TooManyExpressionsInStarredAssignment": "F621",
44 "TwoStarredExpressions": "F622",
45 "AssertTuple": "F631",
47 "InvalidPrintSyntax": "F633",
49 "BreakOutsideLoop": "F701",
50 "ContinueOutsideLoop": "F702",
51 "YieldOutsideFunction": "F704",
52 "ReturnOutsideFunction": "F706",
53 "DefaultExceptNotLast": "F707",
54 "DoctestSyntaxError": "F721",
55 "ForwardAnnotationSyntaxError": "F722",
56 "RedefinedWhileUnused": "F811",
57 "UndefinedName": "F821",
58 "UndefinedExport": "F822",
59 "UndefinedLocal": "F823",
60 "DuplicateArgument": "F831",
61 "UnusedVariable": "F841",
62 "UnusedAnnotation": "F842",
63 "RaiseNotImplemented": "F901",
67 class FlakesChecker(pyflakes
.checker
.Checker
):
68 """Subclass the Pyflakes checker to conform with the flake8 API."""
71 include_in_doctest
: list[str] = []
72 exclude_from_doctest
: list[str] = []
74 def __init__(self
, tree
: ast
.AST
, filename
: str) -> None:
75 """Initialize the PyFlakes plugin with an AST tree and filename."""
76 filename
= utils
.normalize_path(filename
)
77 with_doctest
= self
.with_doctest
80 for include
in self
.include_in_doctest
81 if include
!= "" and filename
.startswith(include
)
86 for exclude
in self
.exclude_from_doctest
:
87 if exclude
!= "" and filename
.startswith(exclude
):
91 for include
in included_by
92 if include
.startswith(exclude
)
98 super().__init
__(tree
, filename
=filename
, withDoctest
=with_doctest
)
101 def add_options(cls
, parser
: OptionManager
) -> None:
102 """Register options for PyFlakes on the Flake8 OptionManager."""
105 parse_from_config
=True,
106 comma_separated_list
=True,
107 help="define more built-ins, comma separated",
113 parse_from_config
=True,
114 help="also check syntax of the doctests",
117 "--include-in-doctest",
119 dest
="include_in_doctest",
120 parse_from_config
=True,
121 comma_separated_list
=True,
122 normalize_paths
=True,
123 help="Run doctests only on these files",
126 "--exclude-from-doctest",
128 dest
="exclude_from_doctest",
129 parse_from_config
=True,
130 comma_separated_list
=True,
131 normalize_paths
=True,
132 help="Skip these files when running doctests",
136 def parse_options(cls
, options
: argparse
.Namespace
) -> None:
137 """Parse option values from Flake8's OptionManager."""
139 cls
.builtIns
= cls
.builtIns
.union(options
.builtins
)
140 cls
.with_doctest
= options
.doctests
142 if options
.include_in_doctest
or options
.exclude_from_doctest
:
144 "--include-in-doctest / --exclude-from-doctest will be "
145 "removed in a future version. see PyCQA/flake8#1747"
149 for included_file
in options
.include_in_doctest
:
150 if included_file
== "":
152 if not included_file
.startswith((os
.sep
, "./", "~/")):
153 included_files
.append(f
"./{included_file}")
155 included_files
.append(included_file
)
156 cls
.include_in_doctest
= utils
.normalize_paths(included_files
)
159 for excluded_file
in options
.exclude_from_doctest
:
160 if excluded_file
== "":
162 if not excluded_file
.startswith((os
.sep
, "./", "~/")):
163 excluded_files
.append(f
"./{excluded_file}")
165 excluded_files
.append(excluded_file
)
166 cls
.exclude_from_doctest
= utils
.normalize_paths(excluded_files
)
168 inc_exc
= set(cls
.include_in_doctest
).intersection(
169 cls
.exclude_from_doctest
173 f
"{inc_exc!r} was specified in both the "
174 f
"include-in-doctest and exclude-from-doctest "
175 f
"options. You are not allowed to specify it in "
176 f
"both for doctesting."
179 def run(self
) -> Generator
[tuple[int, int, str, type[Any
]], None, None]:
180 """Run the plugin."""
181 for message
in self
.messages
:
182 col
= getattr(message
, "col", 0)
187 FLAKE8_PYFLAKES_CODES
.get(type(message
).__name
__, "F999"),
188 message
.message
% message
.message_args
,