Skip to content

Complete pyflakes #13848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"stubs/psycopg2",
"stubs/pyasn1",
"stubs/pycurl",
"stubs/pyflakes",
"stubs/Pygments",
"stubs/PyMySQL",
"stubs/python-crontab",
Expand Down
4 changes: 4 additions & 0 deletions stubs/pyflakes/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pyflakes.messages.DuplicateArgument.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.MultiValueRepeatedKeyLiteral.message_args
Expand All @@ -24,3 +25,6 @@ pyflakes.messages.UnusedAnnotation.message_args
pyflakes.messages.UnusedImport.message_args
pyflakes.messages.UnusedIndirectAssignment.message_args
pyflakes.messages.UnusedVariable.message_args

# Tests are not included:
pyflakes.test.*
4 changes: 0 additions & 4 deletions stubs/pyflakes/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
version = "~=3.3.2"
upstream_repository = "https://github.com/PyCQA/pyflakes"
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
4 changes: 3 additions & 1 deletion stubs/pyflakes/pyflakes/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__: str
from typing import Final

__version__: Final[str]
1 change: 1 addition & 0 deletions stubs/pyflakes/pyflakes/__main__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pyflakes.api import main as main
15 changes: 8 additions & 7 deletions stubs/pyflakes/pyflakes/api.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from _typeshed import Incomplete
from _typeshed import GenericPath
from collections.abc import Iterable, Iterator, Sequence
from re import Pattern
from typing import Final, NoReturn

from pyflakes.reporter import Reporter

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

PYTHON_SHEBANG_REGEX: Pattern[bytes]
PYTHON_SHEBANG_REGEX: Final[Pattern[bytes]]

def check(codeString: str, filename: str, reporter: Reporter | None = None) -> int: ...
def checkPath(filename, reporter: Reporter | None = None) -> int: ...
def isPythonFile(filename) -> bool: ...
def iterSourceCode(paths: Iterable[Incomplete]) -> Iterator[Incomplete]: ...
def checkRecursive(paths: Iterable[Incomplete], reporter: Reporter) -> int: ...
def main(prog: str | None = None, args: Sequence[Incomplete] | None = None) -> None: ...
def checkPath(filename: str, reporter: Reporter | None = None) -> int: ...
def isPythonFile(filename: str) -> bool: ...
def iterSourceCode(paths: Iterable[GenericPath[str]]) -> Iterator[GenericPath[str]]: ...
def checkRecursive(paths: Iterable[GenericPath[str]], reporter: Reporter) -> int: ...
def main(prog: str | None = None, args: Sequence[str] | None = None) -> NoReturn: ...
73 changes: 47 additions & 26 deletions stubs/pyflakes/pyflakes/checker.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ast
import sys
from _typeshed import Incomplete
from collections.abc import Callable, Generator, Iterable, Iterator
from _typeshed import StrOrLiteralStr, Unused
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from contextlib import contextmanager
from re import Pattern
from typing import Any, ClassVar, Literal, TypeVar, overload
from typing import Any, ClassVar, Final, Literal, TypeVar, overload
from typing_extensions import Never, ParamSpec, TypeAlias

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

PYPY: bool
PYPY: Final[bool]
builtin_vars: Final[list[str]]

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

FOR_TYPES: tuple[type[ast.For], type[ast.AsyncFor]]
MAPPING_KEY_RE: Pattern[str]
CONVERSION_FLAG_RE: Pattern[str]
WIDTH_RE: Pattern[str]
PRECISION_RE: Pattern[str]
LENGTH_RE: Pattern[str]
if sys.version_info >= (3, 10):
def getAlternatives(n: ast.If | ast.Try | ast.Match) -> list[ast.AST]: ...

else:
def getAlternatives(n: ast.If | ast.Try) -> list[ast.AST]: ...

FOR_TYPES: Final[tuple[type[ast.For], type[ast.AsyncFor]]]
MAPPING_KEY_RE: Final[Pattern[str]]
CONVERSION_FLAG_RE: Final[Pattern[str]]
WIDTH_RE: Final[Pattern[str]]
PRECISION_RE: Final[Pattern[str]]
LENGTH_RE: Final[Pattern[str]]
VALID_CONVERSIONS: frozenset[str]

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

class Binding:
name: str
source: ast.AST | None
used: Literal[False] | tuple[Incomplete, ast.AST]
used: Literal[False] | tuple[Scope, ast.AST]
def __init__(self, name: str, source: ast.AST | None) -> None: ...
def redefines(self, other: Binding) -> bool: ...

Expand All @@ -68,7 +77,7 @@ class VariableKey:

class Importation(Definition):
fullName: str
redefined: list[Incomplete]
redefined: list[ast.AST]
def __init__(self, name: str, source: ast.AST | None, full_name: str | None = None) -> None: ...
@property
def source_statement(self) -> str: ...
Expand All @@ -85,11 +94,12 @@ class StarImportation(Importation):
def __init__(self, name: str, source: ast.AST) -> None: ...

class FutureImportation(ImportationFrom):
used: tuple[Incomplete, ast.AST]
def __init__(self, name: str, source: ast.AST, scope) -> None: ...
used: tuple[Scope, ast.AST]
def __init__(self, name: str, source: ast.AST, scope: Scope) -> None: ...

class Argument(Binding): ...
class Assignment(Binding): ...
class NamedExprAssignment(Assignment): ...

class Annotation(Binding):
def redefines(self, other: Binding) -> Literal[False]: ...
Expand All @@ -111,7 +121,7 @@ class FunctionScope(Scope):
usesLocals: bool
alwaysUsed: ClassVar[set[str]]
globals: set[str]
returnValue: Incomplete
returnValue: ast.expr | None
isGenerator: bool
def __init__(self) -> None: ...
def unused_assignments(self) -> Iterator[tuple[str, Binding]]: ...
Expand All @@ -129,7 +139,7 @@ def getNodeName(node: ast.AST) -> str: ...

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

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

class AnnotationState:
NONE: ClassVar[Literal[0]]
Expand Down Expand Up @@ -165,30 +175,34 @@ else:

if sys.version_info >= (3, 12):
_TypeVar: TypeAlias = ast.TypeVar
_ParamSpec: TypeAlias = ast.ParamSpec
_TypeVarTuple: TypeAlias = ast.TypeVarTuple
_TypeAlias: TypeAlias = ast.TypeAlias
else:
# The methods using these should never be called on Python < 3.12.
_TypeVar: TypeAlias = Never
_ParamSpec: TypeAlias = Never
_TypeVarTuple: TypeAlias = Never
_TypeAlias: TypeAlias = Never

class Checker:
nodeDepth: int
offset: tuple[int, int] | None
builtIns: set[str]
deadScopes: list[Incomplete]
messages: list[Incomplete]
deadScopes: list[Scope]
messages: list[Message]
filename: str
withDoctest: bool
scopeStack: list[Scope]
exceptHandlers: list[Incomplete]
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: tuple[Incomplete, ...] = (),
file_tokens: Unused = (),
) -> None: ...
def deferFunction(self, callable: _AnyFunction) -> None: ...
@property
Expand All @@ -211,15 +225,15 @@ class Checker:
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]): ...
def handleNodeLoad(self, node: ast.AST, parent: ast.AST) -> None: ...
def getNodeHandler(self, node_class: type[ast.AST]) -> Callable[[ast.AST], None]: ...
def handleNodeLoad(self, node: ast.AST, parent: ast.AST | None) -> None: ...
def handleNodeStore(self, node: ast.AST) -> None: ...
def handleNodeDelete(self, node: ast.AST) -> None: ...
def handleChildren(self, tree: ast.AST, omit: _OmitType = None) -> None: ...
def isLiteralTupleUnpacking(self, node: ast.AST) -> bool | None: ...
def isDocstring(self, node: ast.AST) -> bool: ...
def getDocstring(self, node: ast.AST) -> tuple[str, int] | tuple[None, None]: ...
def handleNode(self, node: ast.AST | None, parent) -> 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 handle_annotation_always_deferred(self, annotation: ast.AST, parent: ast.AST) -> None: ...
Expand Down Expand Up @@ -311,13 +325,18 @@ class Checker:
def LAMBDA(self, node: ast.Lambda) -> None: ...
def ARGUMENTS(self, node: ast.arguments) -> None: ...
def ARG(self, node: ast.arg) -> None: ...
def CLASSDEF(self, node: ast.ClassDef): ...
def CLASSDEF(self, node: ast.ClassDef) -> None: ...
def AUGASSIGN(self, node: ast.AugAssign) -> None: ...
def TUPLE(self, node: ast.Tuple) -> None: ...
def LIST(self, node: ast.List) -> None: ...
def IMPORT(self, node: ast.Import) -> None: ...
def IMPORTFROM(self, node: ast.ImportFrom) -> None: ...
def TRY(self, node: ast.Try) -> None: ...
if sys.version_info >= (3, 11):
def TRYSTAR(self, node: ast.TryStar) -> None: ...
else:
def TRYSTAR(self, node: ast.Try) -> None: ...

def EXCEPTHANDLER(self, node: ast.ExceptHandler) -> None: ...
def ANNASSIGN(self, node: ast.AnnAssign) -> None: ...
def COMPARE(self, node: ast.Compare) -> None: ...
Expand All @@ -332,4 +351,6 @@ class Checker:
def MATCHMAPPING(self, node: _MatchMapping) -> None: ...
def MATCHSTAR(self, node: _MatchStar) -> None: ...
def TYPEVAR(self, node: _TypeVar) -> None: ...
def PARAMSPEC(self, node: _ParamSpec) -> None: ...
def TYPEVARTUPLE(self, node: _TypeVarTuple) -> None: ...
def TYPEALIAS(self, node: _TypeAlias) -> None: ...
Loading