11import ast
22import 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
55from contextlib import contextmanager
66from re import Pattern
7- from typing import Any , ClassVar , Literal , TypeVar , overload
7+ from typing import Any , ClassVar , Final , Literal , TypeVar , overload
88from typing_extensions import Never , ParamSpec , TypeAlias
99
1010from 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 ]]
2635VALID_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
4453def convert_to_value (item : ast .Name ) -> VariableKey : ... # type: ignore[overload-overlap]
4554@overload
4655def 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
4958class 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
6978class 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
8796class 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
91100class Argument (Binding ): ...
92101class Assignment (Binding ): ...
102+ class NamedExprAssignment (Assignment ): ...
93103
94104class 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
130140TYPING_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
134144class AnnotationState :
135145 NONE : ClassVar [Literal [0 ]]
@@ -165,30 +175,34 @@ else:
165175
166176if 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
169181else :
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
174188class 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