Skip to content

Commit 232c31c

Browse files
authored
Complete pyflakes (#13848)
1 parent 4ba81e8 commit 232c31c

9 files changed

Lines changed: 119 additions & 92 deletions

File tree

pyrightconfig.stricter.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
"stubs/psycopg2",
7575
"stubs/pyasn1",
7676
"stubs/pycurl",
77-
"stubs/pyflakes",
7877
"stubs/Pygments",
7978
"stubs/PyMySQL",
8079
"stubs/python-crontab",

stubs/pyflakes/@tests/stubtest_allowlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pyflakes.messages.DuplicateArgument.message_args
33
pyflakes.messages.ForwardAnnotationSyntaxError.message_args
44
pyflakes.messages.FutureFeatureNotDefined.message_args
55
pyflakes.messages.ImportShadowedByLoopVar.message_args
6+
pyflakes.messages.ImportStarNotPermitted.message_args
67
pyflakes.messages.ImportStarUsage.message_args
78
pyflakes.messages.ImportStarUsed.message_args
89
pyflakes.messages.MultiValueRepeatedKeyLiteral.message_args
@@ -24,3 +25,6 @@ pyflakes.messages.UnusedAnnotation.message_args
2425
pyflakes.messages.UnusedImport.message_args
2526
pyflakes.messages.UnusedIndirectAssignment.message_args
2627
pyflakes.messages.UnusedVariable.message_args
28+
29+
# Tests are not included:
30+
pyflakes.test.*

stubs/pyflakes/METADATA.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
version = "~=3.3.2"
22
upstream_repository = "https://github.com/PyCQA/pyflakes"
3-
partial_stub = true
4-
5-
[tool.stubtest]
6-
ignore_missing_stub = true
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
__version__: str
1+
from typing import Final
2+
3+
__version__: Final[str]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from pyflakes.api import main as main

stubs/pyflakes/pyflakes/api.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import GenericPath
22
from collections.abc import Iterable, Iterator, Sequence
33
from re import Pattern
4+
from typing import Final, NoReturn
45

56
from pyflakes.reporter import Reporter
67

78
__all__ = ["check", "checkPath", "checkRecursive", "iterSourceCode", "main"]
89

9-
PYTHON_SHEBANG_REGEX: Pattern[bytes]
10+
PYTHON_SHEBANG_REGEX: Final[Pattern[bytes]]
1011

1112
def check(codeString: str, filename: str, reporter: Reporter | None = None) -> int: ...
12-
def checkPath(filename, reporter: Reporter | None = None) -> int: ...
13-
def isPythonFile(filename) -> bool: ...
14-
def iterSourceCode(paths: Iterable[Incomplete]) -> Iterator[Incomplete]: ...
15-
def checkRecursive(paths: Iterable[Incomplete], reporter: Reporter) -> int: ...
16-
def main(prog: str | None = None, args: Sequence[Incomplete] | None = None) -> None: ...
13+
def checkPath(filename: str, reporter: Reporter | None = None) -> int: ...
14+
def isPythonFile(filename: str) -> bool: ...
15+
def iterSourceCode(paths: Iterable[GenericPath[str]]) -> Iterator[GenericPath[str]]: ...
16+
def checkRecursive(paths: Iterable[GenericPath[str]], reporter: Reporter) -> int: ...
17+
def main(prog: str | None = None, args: Sequence[str] | None = None) -> NoReturn: ...

stubs/pyflakes/pyflakes/checker.pyi

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import ast
22
import sys
3-
from _typeshed import Incomplete
4-
from collections.abc import Callable, Generator, Iterable, Iterator
3+
from _typeshed import StrOrLiteralStr, Unused
4+
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
55
from contextlib import contextmanager
66
from re import Pattern
7-
from typing import Any, ClassVar, Literal, TypeVar, overload
7+
from typing import Any, ClassVar, Final, Literal, TypeVar, overload
88
from typing_extensions import Never, ParamSpec, TypeAlias
99

1010
from pyflakes.messages import Message
@@ -13,16 +13,25 @@ _AnyFunction: TypeAlias = Callable[..., Any]
1313
_F = TypeVar("_F", bound=_AnyFunction)
1414
_P = ParamSpec("_P")
1515

16-
PYPY: bool
16+
PYPY: Final[bool]
17+
builtin_vars: Final[list[str]]
1718

18-
def getAlternatives(n: ast.If | ast.Try) -> list[ast.AST]: ...
19+
def parse_format_string(
20+
format_string: StrOrLiteralStr,
21+
) -> Iterable[tuple[StrOrLiteralStr, StrOrLiteralStr | None, StrOrLiteralStr | None, StrOrLiteralStr | None]]: ...
1922

20-
FOR_TYPES: tuple[type[ast.For], type[ast.AsyncFor]]
21-
MAPPING_KEY_RE: Pattern[str]
22-
CONVERSION_FLAG_RE: Pattern[str]
23-
WIDTH_RE: Pattern[str]
24-
PRECISION_RE: Pattern[str]
25-
LENGTH_RE: Pattern[str]
23+
if sys.version_info >= (3, 10):
24+
def getAlternatives(n: ast.If | ast.Try | ast.Match) -> list[ast.AST]: ...
25+
26+
else:
27+
def getAlternatives(n: ast.If | ast.Try) -> list[ast.AST]: ...
28+
29+
FOR_TYPES: Final[tuple[type[ast.For], type[ast.AsyncFor]]]
30+
MAPPING_KEY_RE: Final[Pattern[str]]
31+
CONVERSION_FLAG_RE: Final[Pattern[str]]
32+
WIDTH_RE: Final[Pattern[str]]
33+
PRECISION_RE: Final[Pattern[str]]
34+
LENGTH_RE: Final[Pattern[str]]
2635
VALID_CONVERSIONS: frozenset[str]
2736

2837
_FormatType: TypeAlias = tuple[str | None, str | None, str | None, str | None, str]
@@ -44,12 +53,12 @@ def convert_to_value(item: ast.Tuple) -> tuple[Any, ...]: ... # type: ignore[ov
4453
def convert_to_value(item: ast.Name) -> VariableKey: ... # type: ignore[overload-overlap]
4554
@overload
4655
def convert_to_value(item: ast.AST) -> UnhandledKeyType: ...
47-
def is_notimplemented_name_node(node: object) -> bool: ...
56+
def is_notimplemented_name_node(node: ast.AST) -> bool: ...
4857

4958
class Binding:
5059
name: str
5160
source: ast.AST | None
52-
used: Literal[False] | tuple[Incomplete, ast.AST]
61+
used: Literal[False] | tuple[Scope, ast.AST]
5362
def __init__(self, name: str, source: ast.AST | None) -> None: ...
5463
def redefines(self, other: Binding) -> bool: ...
5564

@@ -68,7 +77,7 @@ class VariableKey:
6877

6978
class Importation(Definition):
7079
fullName: str
71-
redefined: list[Incomplete]
80+
redefined: list[ast.AST]
7281
def __init__(self, name: str, source: ast.AST | None, full_name: str | None = None) -> None: ...
7382
@property
7483
def source_statement(self) -> str: ...
@@ -85,11 +94,12 @@ class StarImportation(Importation):
8594
def __init__(self, name: str, source: ast.AST) -> None: ...
8695

8796
class FutureImportation(ImportationFrom):
88-
used: tuple[Incomplete, ast.AST]
89-
def __init__(self, name: str, source: ast.AST, scope) -> None: ...
97+
used: tuple[Scope, ast.AST]
98+
def __init__(self, name: str, source: ast.AST, scope: Scope) -> None: ...
9099

91100
class Argument(Binding): ...
92101
class Assignment(Binding): ...
102+
class NamedExprAssignment(Assignment): ...
93103

94104
class Annotation(Binding):
95105
def redefines(self, other: Binding) -> Literal[False]: ...
@@ -111,7 +121,7 @@ class FunctionScope(Scope):
111121
usesLocals: bool
112122
alwaysUsed: ClassVar[set[str]]
113123
globals: set[str]
114-
returnValue: Incomplete
124+
returnValue: ast.expr | None
115125
isGenerator: bool
116126
def __init__(self) -> None: ...
117127
def unused_assignments(self) -> Iterator[tuple[str, Binding]]: ...
@@ -129,7 +139,7 @@ def getNodeName(node: ast.AST) -> str: ...
129139

130140
TYPING_MODULES: frozenset[Literal["typing", "typing_extensions"]]
131141

132-
def is_typing_overload(value: Binding, scope_stack) -> bool: ...
142+
def is_typing_overload(value: Binding, scope_stack: Sequence[Scope]) -> bool: ...
133143

134144
class AnnotationState:
135145
NONE: ClassVar[Literal[0]]
@@ -165,30 +175,34 @@ else:
165175

166176
if sys.version_info >= (3, 12):
167177
_TypeVar: TypeAlias = ast.TypeVar
178+
_ParamSpec: TypeAlias = ast.ParamSpec
179+
_TypeVarTuple: TypeAlias = ast.TypeVarTuple
168180
_TypeAlias: TypeAlias = ast.TypeAlias
169181
else:
170182
# The methods using these should never be called on Python < 3.12.
171183
_TypeVar: TypeAlias = Never
184+
_ParamSpec: TypeAlias = Never
185+
_TypeVarTuple: TypeAlias = Never
172186
_TypeAlias: TypeAlias = Never
173187

174188
class Checker:
175189
nodeDepth: int
176190
offset: tuple[int, int] | None
177191
builtIns: set[str]
178-
deadScopes: list[Incomplete]
179-
messages: list[Incomplete]
192+
deadScopes: list[Scope]
193+
messages: list[Message]
180194
filename: str
181195
withDoctest: bool
182196
scopeStack: list[Scope]
183-
exceptHandlers: list[Incomplete]
197+
exceptHandlers: list[tuple[()] | str]
184198
root: ast.AST
185199
def __init__(
186200
self,
187201
tree: ast.AST,
188202
filename: str = "(none)",
189203
builtins: Iterable[str] | None = None,
190204
withDoctest: bool = False,
191-
file_tokens: tuple[Incomplete, ...] = (),
205+
file_tokens: Unused = (),
192206
) -> None: ...
193207
def deferFunction(self, callable: _AnyFunction) -> None: ...
194208
@property
@@ -211,15 +225,15 @@ class Checker:
211225
def getScopeNode(self, node: ast.AST) -> ast.AST | None: ...
212226
def differentForks(self, lnode: ast.AST, rnode: ast.AST) -> bool: ...
213227
def addBinding(self, node: ast.AST, value: Binding) -> None: ...
214-
def getNodeHandler(self, node_class: type[ast.AST]): ...
215-
def handleNodeLoad(self, node: ast.AST, parent: ast.AST) -> None: ...
228+
def getNodeHandler(self, node_class: type[ast.AST]) -> Callable[[ast.AST], None]: ...
229+
def handleNodeLoad(self, node: ast.AST, parent: ast.AST | None) -> None: ...
216230
def handleNodeStore(self, node: ast.AST) -> None: ...
217231
def handleNodeDelete(self, node: ast.AST) -> None: ...
218232
def handleChildren(self, tree: ast.AST, omit: _OmitType = None) -> None: ...
219233
def isLiteralTupleUnpacking(self, node: ast.AST) -> bool | None: ...
220234
def isDocstring(self, node: ast.AST) -> bool: ...
221235
def getDocstring(self, node: ast.AST) -> tuple[str, int] | tuple[None, None]: ...
222-
def handleNode(self, node: ast.AST | None, parent) -> None: ...
236+
def handleNode(self, node: ast.AST | None, parent: ast.AST | None) -> None: ...
223237
def handleDoctests(self, node: ast.AST) -> None: ...
224238
def handleStringAnnotation(self, s: str, node: ast.AST, ref_lineno: int, ref_col_offset: int, err: type[Message]) -> None: ...
225239
def handle_annotation_always_deferred(self, annotation: ast.AST, parent: ast.AST) -> None: ...
@@ -311,13 +325,18 @@ class Checker:
311325
def LAMBDA(self, node: ast.Lambda) -> None: ...
312326
def ARGUMENTS(self, node: ast.arguments) -> None: ...
313327
def ARG(self, node: ast.arg) -> None: ...
314-
def CLASSDEF(self, node: ast.ClassDef): ...
328+
def CLASSDEF(self, node: ast.ClassDef) -> None: ...
315329
def AUGASSIGN(self, node: ast.AugAssign) -> None: ...
316330
def TUPLE(self, node: ast.Tuple) -> None: ...
317331
def LIST(self, node: ast.List) -> None: ...
318332
def IMPORT(self, node: ast.Import) -> None: ...
319333
def IMPORTFROM(self, node: ast.ImportFrom) -> None: ...
320334
def TRY(self, node: ast.Try) -> None: ...
335+
if sys.version_info >= (3, 11):
336+
def TRYSTAR(self, node: ast.TryStar) -> None: ...
337+
else:
338+
def TRYSTAR(self, node: ast.Try) -> None: ...
339+
321340
def EXCEPTHANDLER(self, node: ast.ExceptHandler) -> None: ...
322341
def ANNASSIGN(self, node: ast.AnnAssign) -> None: ...
323342
def COMPARE(self, node: ast.Compare) -> None: ...
@@ -332,4 +351,6 @@ class Checker:
332351
def MATCHMAPPING(self, node: _MatchMapping) -> None: ...
333352
def MATCHSTAR(self, node: _MatchStar) -> None: ...
334353
def TYPEVAR(self, node: _TypeVar) -> None: ...
354+
def PARAMSPEC(self, node: _ParamSpec) -> None: ...
355+
def TYPEVARTUPLE(self, node: _TypeVarTuple) -> None: ...
335356
def TYPEALIAS(self, node: _TypeAlias) -> None: ...

0 commit comments

Comments
 (0)