diff --git a/stubs/pyflakes/@tests/stubtest_allowlist.txt b/stubs/pyflakes/@tests/stubtest_allowlist.txt index 109ee305c802..0695e2014bc5 100644 --- a/stubs/pyflakes/@tests/stubtest_allowlist.txt +++ b/stubs/pyflakes/@tests/stubtest_allowlist.txt @@ -1,11 +1,13 @@ # These all have class-level defaults that differ from the instance attributes pyflakes.messages.DuplicateArgument.message_args +pyflakes.messages.EagerUseOfLazyImport.message_args pyflakes.messages.ForwardAnnotationSyntaxError.message_args pyflakes.messages.FutureFeatureNotDefined.message_args pyflakes.messages.ImportShadowedByLoopVar.message_args pyflakes.messages.ImportStarNotPermitted.message_args pyflakes.messages.ImportStarUsage.message_args pyflakes.messages.ImportStarUsed.message_args +pyflakes.messages.LazyImportStarNotPermitted.message_args pyflakes.messages.MultiValueRepeatedKeyLiteral.message_args pyflakes.messages.MultiValueRepeatedKeyVariable.message_args pyflakes.messages.PercentFormatExtraNamedArguments.message_args diff --git a/stubs/pyflakes/METADATA.toml b/stubs/pyflakes/METADATA.toml index 4619a579594b..6e2bee90ca0b 100644 --- a/stubs/pyflakes/METADATA.toml +++ b/stubs/pyflakes/METADATA.toml @@ -1,2 +1,2 @@ -version = "3.4.*" +version = "4.0.*" upstream-repository = "https://github.com/PyCQA/pyflakes" diff --git a/stubs/pyflakes/pyflakes/checker.pyi b/stubs/pyflakes/pyflakes/checker.pyi index 4e7bc16642cb..6855e809d7b0 100644 --- a/stubs/pyflakes/pyflakes/checker.pyi +++ b/stubs/pyflakes/pyflakes/checker.pyi @@ -1,6 +1,6 @@ import ast import sys -from _typeshed import StrOrLiteralStr, Unused +from _typeshed import StrOrLiteralStr from collections.abc import Callable, Generator, Iterable, Iterator, Sequence from contextlib import contextmanager from re import Pattern @@ -13,7 +13,7 @@ _F = TypeVar("_F", bound=Callable[..., Any]) _P = ParamSpec("_P") PYPY: Final[bool] -builtin_vars: Final[list[str]] +builtin_vars: Final[frozenset[str]] def parse_format_string( format_string: StrOrLiteralStr, @@ -33,12 +33,10 @@ _PercentFormat: TypeAlias = tuple[str, _FormatType | None] def parse_percent_format(s: str) -> tuple[_PercentFormat, ...]: ... -class _FieldsOrder(dict[type[ast.AST], tuple[str, ...]]): - def __missing__(self, node_class: type[ast.AST]) -> tuple[str, ...]: ... - _OmitType: TypeAlias = str | tuple[str, ...] | None -def iter_child_nodes(node: ast.AST, omit: _OmitType = None, _fields_order: _FieldsOrder = ...) -> Iterator[ast.AST]: ... +def iter_child_nodes(node: ast.AST, omit: _OmitType = None) -> Iterator[ast.AST]: ... +def iter_dict_children(node: ast.Dict) -> Iterable[tuple[ast.expr | None, ast.expr]]: ... @overload def convert_to_value(item: ast.Constant) -> Any: ... # type: ignore[overload-overlap] # See ast.Constant.value for possible return types @@ -74,17 +72,20 @@ class VariableKey: class Importation(Definition): fullName: str redefined: list[ast.AST] - def __init__(self, name: str, source: ast.AST | None, full_name: str | None = None) -> None: ... + is_lazy: int + def __init__(self, name: str, source: ast.AST | None, full_name: str | None = None, *, is_lazy: int) -> None: ... + @property + def imported_name(self) -> str: ... @property def source_statement(self) -> str: ... class SubmoduleImportation(Importation): - def __init__(self, name: str, source: ast.Import | None) -> None: ... + def __init__(self, name: str, source: ast.Import | None, *, is_lazy: int) -> None: ... class ImportationFrom(Importation): module: str real_name: str - def __init__(self, name: str, source: ast.AST, module: str, real_name: str | None = None) -> None: ... + def __init__(self, name: str, source: ast.AST, module: str, real_name: str | None = None, *, is_lazy: int) -> None: ... class StarImportation(Importation): def __init__(self, name: str, source: ast.AST) -> None: ... @@ -111,20 +112,20 @@ class Scope(dict[str, Binding]): importStarred: bool class ClassScope(Scope): + indirect_assignments: dict[str, ast.Global | ast.Nonlocal] def __init__(self) -> None: ... class FunctionScope(Scope): usesLocals: bool - alwaysUsed: ClassVar[set[str]] - globals: set[str] - returnValue: ast.expr | None - isGenerator: bool + always_used: ClassVar[frozenset[str]] + indirect_assignments: dict[str, ast.Global | ast.Nonlocal] def __init__(self) -> None: ... def unused_assignments(self) -> Iterator[tuple[str, Binding]]: ... def unused_annotations(self) -> Iterator[tuple[str, Annotation]]: ... class TypeScope(Scope): ... -class GeneratorScope(Scope): ... +class ComprehensionScope(Scope): ... +class GeneratorScope(ComprehensionScope): ... class ModuleScope(Scope): ... class DoctestScope(ModuleScope): ... @@ -141,6 +142,7 @@ class AnnotationState: NONE: ClassVar[Literal[0]] STRING: ClassVar[Literal[1]] BARE: ClassVar[Literal[2]] + STR_AS_TYPE: ClassVar[Literal[3]] def in_annotation(func: _F) -> _F: ... def in_string_annotation(func: _F) -> _F: ... @@ -170,7 +172,7 @@ else: class Checker: nodeDepth: int offset: tuple[int, int] | None - builtIns: set[str] + builtIns: frozenset[str] deadScopes: list[Scope] messages: list[Message] filename: str @@ -179,12 +181,7 @@ class Checker: exceptHandlers: list[tuple[()] | str] root: ast.AST def __init__( - self, - tree: ast.AST, - filename: str = "(none)", - builtins: Iterable[str] | None = None, - withDoctest: bool = False, - file_tokens: Unused = (), + self, tree: ast.AST, filename: str = "(none)", builtins: Iterable[str] | None = None, withDoctest: bool = False ) -> None: ... def deferFunction(self, callable: Callable[..., Any]) -> None: ... @@ -207,7 +204,6 @@ class Checker: def getParent(self, node: ast.AST) -> ast.AST: ... def getCommonAncestor(self, lnode: ast.AST, rnode: ast.AST, stop: ast.AST) -> ast.AST: ... def descendantOf(self, node: ast.AST, ancestors: ast.AST, stop: ast.AST) -> bool: ... - def getScopeNode(self, node: ast.AST) -> ast.AST | None: ... def differentForks(self, lnode: ast.AST, rnode: ast.AST) -> bool: ... def addBinding(self, node: ast.AST, value: Binding) -> None: ... def getNodeHandler(self, node_class: type[ast.AST]) -> Callable[[ast.AST], None]: ... @@ -220,19 +216,19 @@ class Checker: def getDocstring(self, node: ast.AST) -> tuple[str, int] | tuple[None, None]: ... def handleNode(self, node: ast.AST | None, parent: ast.AST | None) -> None: ... def handleDoctests(self, node: ast.AST) -> None: ... - def handleStringAnnotation(self, s: str, node: ast.AST, ref_lineno: int, ref_col_offset: int, err: type[Message]) -> None: ... + def handleStringAnnotation(self, s: str, node: ast.AST, ref_lineno: int, ref_col_offset: int) -> None: ... def handle_annotation_always_deferred(self, annotation: ast.AST, parent: ast.AST) -> None: ... def handleAnnotation(self, annotation: ast.AST, node: ast.AST) -> None: ... def ignore(self, node: ast.AST) -> None: ... def DELETE(self, tree: ast.Delete, omit: _OmitType = None) -> None: ... - def FOR(self, tree: ast.For, omit: _OmitType = None) -> None: ... - def ASYNCFOR(self, tree: ast.AsyncFor, omit: _OmitType = None) -> None: ... + def FOR(self, node: ast.For) -> None: ... + def ASYNCFOR(self, node: ast.AsyncFor) -> None: ... def WHILE(self, tree: ast.While, omit: _OmitType = None) -> None: ... def WITH(self, tree: ast.With, omit: _OmitType = None) -> None: ... def WITHITEM(self, tree: ast.AST, omit: _OmitType = None) -> None: ... def ASYNCWITH(self, tree: ast.AsyncWith, omit: _OmitType = None) -> None: ... def EXPR(self, tree: ast.AST, omit: _OmitType = None) -> None: ... - def ASSIGN(self, tree: ast.Assign, omit: _OmitType = None) -> None: ... + def ASSIGN(self, node: ast.Assign) -> None: ... def PASS(self, node: ast.AST) -> None: ... def BOOLOP(self, tree: ast.BoolOp, omit: _OmitType = None) -> None: ... def UNARYOP(self, tree: ast.UnaryOp, omit: _OmitType = None) -> None: ... @@ -240,7 +236,7 @@ class Checker: def ATTRIBUTE(self, tree: ast.Attribute, omit: _OmitType = None) -> None: ... def STARRED(self, tree: ast.Starred, omit: _OmitType = None) -> None: ... def NAMECONSTANT(self, tree: _NameConstant, omit: _OmitType = None) -> None: ... - def NAMEDEXPR(self, tree: ast.NamedExpr, omit: _OmitType = None) -> None: ... + def NAMEDEXPR(self, node: ast.NamedExpr) -> None: ... def SUBSCRIPT(self, node: ast.Subscript) -> None: ... def CALL(self, node: ast.Call) -> None: ... def BINOP(self, node: ast.BinOp) -> None: ... @@ -284,7 +280,7 @@ class Checker: def NOTIN(self, node: ast.NotIn) -> None: ... def MATMULT(self, node: ast.MatMult) -> None: ... def RAISE(self, node: ast.Raise) -> None: ... - def COMPREHENSION(self, tree: ast.comprehension, omit: _OmitType = None) -> None: ... + def COMPREHENSION(self, node: ast.comprehension) -> None: ... def KEYWORD(self, tree: ast.keyword, omit: _OmitType = None) -> None: ... def FORMATTEDVALUE(self, tree: ast.FormattedValue, omit: _OmitType = None) -> None: ... def JOINEDSTR(self, node: ast.AST) -> None: ... diff --git a/stubs/pyflakes/pyflakes/messages.pyi b/stubs/pyflakes/pyflakes/messages.pyi index 4db703f30c7c..eef8197f6570 100644 --- a/stubs/pyflakes/pyflakes/messages.pyi +++ b/stubs/pyflakes/pyflakes/messages.pyi @@ -39,7 +39,7 @@ class UndefinedName(Message): class DoctestSyntaxError(Message): message_args: tuple[()] - def __init__(self, filename: str, loc: ast.AST, position: tuple[int, int] | None = None) -> None: ... + def __init__(self, filename: str, loc: ast.AST, position: tuple[int, int]) -> None: ... class UndefinedExport(Message): message_args: tuple[str] @@ -146,3 +146,13 @@ class PercentFormatMissingArgument(Message): class PercentFormatExpectedMapping(Message): ... class PercentFormatExpectedSequence(Message): ... class PercentFormatStarRequiresSequence(Message): ... + +class EagerUseOfLazyImport(Message): + message_args: tuple[str, int] + def __init__(self, filename: str, loc: ast.AST, name: str, orig_loc: ast.AST) -> None: ... + +class LazyImportStarNotPermitted(Message): + message_args: tuple[str] + def __init__(self, filename: str, loc: ast.AST, modname: str) -> None: ... + +class LazyImportNotAtModuleScope(Message): ...