Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stubs/flake8-bugbear/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ bugbear.NamedExprFinder.__gt__
bugbear.NamedExprFinder.__le__
bugbear.NamedExprFinder.__lt__
bugbear.NamedExprFinder.__match_args__
bugbear.B020AttributeFinder.__ge__
bugbear.B020AttributeFinder.__gt__
bugbear.B020AttributeFinder.__le__
bugbear.B020AttributeFinder.__lt__
bugbear.B020AttributeFinder.__match_args__
# == Python 3.13
bugbear.B040CaughtException.__replace__
bugbear.B041VariableKeyType.__replace__
bugbear.BugBearChecker.__replace__
bugbear.BugBearVisitor.__replace__
bugbear.NameFinder.__replace__
bugbear.NamedExprFinder.__replace__
bugbear.B020AttributeFinder.__replace__
2 changes: 1 addition & 1 deletion stubs/flake8-bugbear/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "25.11.29"
version = "26.9.9"
upstream-repository = "https://github.com/PyCQA/flake8-bugbear"
54 changes: 35 additions & 19 deletions stubs/flake8-bugbear/bugbear.pyi
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import argparse
import ast
import sys
from _typeshed import Incomplete
from collections.abc import Generator, Iterable, Sequence
from functools import partial
from logging import Logger
from typing import Any, ClassVar, Final, Literal, NamedTuple, Protocol, overload

__version__: Final[str]
LOG: Logger
CONTEXTFUL_NODES: Final[tuple[type[ast.AST], ...]]
FUNCTION_NODES: Final[tuple[type[ast.AST], ...]]
FUNCTIONS_WITHOUT_SIDE_EFFECTS: Final[tuple[str, ...]]
B908_pytest_functions: Final[set[str]]
B908_unittest_methods: Final[set[str]]
B902_default_decorators: Final[set[str]]

class Context(NamedTuple):
node: ast.AST
stack: list[str]
stack: list[ast.AST]

class BugBearChecker:
name: ClassVar[str]
Expand Down Expand Up @@ -45,16 +44,15 @@ class BugBearChecker:
) -> None: ...
def should_warn(self, code: str) -> bool: ...

def names_from_assignments(assign_target: ast.AST) -> Generator[str]: ...
def names_from_assignments(assign_target: ast.expr) -> Generator[str]: ...
def children_in_scope(node: ast.AST) -> Generator[ast.AST]: ...
def walk_list(nodes: Iterable[ast.AST]) -> Generator[ast.AST]: ...

class ExceptBaseExceptionVisitor(ast.NodeVisitor):
root: ast.ExceptHandler
def __init__(self, except_node: ast.ExceptHandler) -> None: ...
def re_raised(self) -> bool: ...
def visit_Raise(self, node: ast.Raise) -> Incomplete | None: ...
def visit_ExceptHandler(self, node: ast.ExceptHandler) -> Incomplete | None: ...
def visit_Raise(self, node: ast.Raise) -> None: ...
def visit_ExceptHandler(self, node: ast.ExceptHandler) -> None: ...

class B040CaughtException:
name: str
Expand Down Expand Up @@ -96,7 +94,7 @@ class BugBearVisitor(ast.NodeVisitor):
) -> None: ...
def add_error(self, code: str, node: AstPositionNode, *vars: object) -> None: ...
@property
def node_stack(self) -> list[Context]: ...
def node_stack(self) -> list[ast.AST]: ...
def in_class_init(self) -> bool: ...
def visit_Return(self, node: ast.Return) -> None: ...
def visit_Yield(self, node: ast.Yield) -> None: ...
Expand All @@ -118,10 +116,11 @@ class BugBearVisitor(ast.NodeVisitor):
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None: ...
def visit_FunctionDef(self, node: ast.FunctionDef) -> None: ...
def visit_ClassDef(self, node: ast.ClassDef) -> None: ...
def visit_Try(self, node: ast.Try) -> None: ...
if sys.version_info >= (3, 11):
def visit_Try(self, node: ast.Try | ast.TryStar) -> None: ...
def visit_TryStar(self, node: ast.TryStar) -> None: ...
else:
def visit_Try(self, node: ast.Try) -> None: ...
def visit_TryStar(self, node: ast.Try) -> None: ...

def visit_Compare(self, node: ast.Compare) -> None: ...
Expand Down Expand Up @@ -158,11 +157,11 @@ class BugBearVisitor(ast.NodeVisitor):
def check_for_b031(self, loop_node: ast.For | ast.AsyncFor) -> None: ...
def check_for_b035(self, node: ast.DictComp) -> None: ...
def check_for_b040_add_note(self, node: ast.Attribute) -> bool: ...
def check_for_b040_usage(self, node: ast.expr | None) -> None: ...
def check_for_b040_usage(self, node: ast.expr | list[ast.expr] | list[ast.keyword] | None) -> None: ...
def check_for_b904(self, node: ast.Raise) -> None: ...
def walk_function_body(
self, node: ast.FunctionDef | ast.AsyncFunctionDef
) -> tuple[ast.FunctionDef | ast.AsyncFunctionDef, ast.stmt]: ...
) -> Generator[tuple[ast.FunctionDef | ast.AsyncFunctionDef, ast.stmt]]: ...
def check_for_b901(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None: ...

@overload
Expand All @@ -174,20 +173,26 @@ class BugBearVisitor(ast.NodeVisitor):

def check_for_b902(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None: ...
def check_for_b903(self, node: ast.ClassDef) -> None: ...
def check_for_b018(self, node: ast.Expr) -> None: ...
def check_for_b018(self, node: ast.AST) -> None: ...
def check_for_b021(self, node: ast.AsyncFunctionDef | ast.FunctionDef | ast.ClassDef | ast.Module) -> None: ...
def check_for_b022(self, node: ast.With | ast.AsyncWith) -> None: ...
def check_for_b908(self, node: ast.With) -> None: ...
def check_for_b025(self, node: ast.Try) -> None: ...
if sys.version_info >= (3, 11):
def check_for_b025(self, node: ast.Try | ast.TryStar) -> None: ...
else:
def check_for_b025(self, node: ast.Try) -> None: ...

def check_for_b905(self, node: ast.Call) -> None: ...
def check_for_b912(self, node: ast.Call) -> None: ...
def check_for_b913(self, node: ast.For) -> None: ...
def check_for_b906(self, node: ast.FunctionDef) -> None: ...
def check_for_b907(self, node: ast.JoinedStr) -> None: ...
def check_for_b028(self, node: ast.Call) -> None: ...
def check_for_b032(self, node: ast.AnnAssign) -> None: ...
def check_for_b033(self, node: ast.Set | ast.List | ast.Tuple) -> None: ...
def check_for_b033(self, node: ast.Set) -> None: ...
def check_for_b034(self, node: ast.Call) -> None: ...
def check_for_b042(self, node: ast.ClassDef) -> None: ...
def check_for_b044(self, node: ast.Assert) -> None: ...
def check_for_b909(self, node: ast.For) -> None: ...
def check_for_b910(self, node: ast.Call) -> None: ...
def check_for_b911(self, node: ast.Call) -> None: ...
Expand All @@ -206,14 +211,22 @@ class B909Checker(ast.NodeVisitor):
def visit_Delete(self, node: ast.Delete) -> None: ...
def visit_Call(self, node: ast.Call) -> None: ...
def visit_If(self, node: ast.If) -> None: ...
def visit(self, node: ast.AST | list[ast.AST]) -> Any: ...
def visit(self, node: ast.AST | list[ast.stmt]) -> Any: ...

class NameFinder(ast.NodeVisitor):
names: dict[str, list[ast.Name]]
def __init__(self, names: dict[str, list[ast.Name]] = ...) -> None: ...
def visit_Name(self, node: ast.Name) -> None: ...
def visit(self, node: ast.AST | list[ast.AST]) -> Any: ...

class B913UsageFinder(NameFinder):
def visit_Name(self, node: ast.Name) -> None: ...
def visit_GeneratorExp(self, node: ast.GeneratorExp) -> None: ...
def visit_ListComp(self, node: ast.ListComp) -> None: ...
def visit_SetComp(self, node: ast.SetComp) -> None: ...
def visit_DictComp(self, node: ast.DictComp) -> None: ...
def visit_AugAssign(self, node: ast.AugAssign) -> None: ...

class NamedExprFinder(ast.NodeVisitor):
names: dict[str, list[ast.Name]]
def __init__(self, names: dict[str, list[ast.Name]] = ...) -> None: ...
Expand All @@ -222,10 +235,7 @@ class NamedExprFinder(ast.NodeVisitor):

class FunctionDefDefaultsVisitor(ast.NodeVisitor):
def __init__(
self,
error_code_calls: partial[error],
error_code_literals: partial[error],
b008_b039_extend_immutable_calls: set[str] | None = None,
self, error_code_calls: Error, error_code_literals: Error, b008_b039_extend_immutable_calls: set[str] | None = None
) -> None: ...
def visit_mutable_literal_or_comprehension(
self, node: ast.List | ast.Dict | ast.Set | ast.ListComp | ast.DictComp | ast.SetComp
Expand All @@ -241,6 +251,12 @@ class B020NameFinder(NameFinder):
def visit_comprehension(self, node: ast.comprehension) -> None: ...
def visit_Lambda(self, node: ast.Lambda) -> None: ...

class B020AttributeFinder(B020NameFinder):
paths: set[str]
def __init__(self, names: dict[str, list[ast.Name]] = ..., paths: set[str] = ...) -> None: ...
def visit_Attribute(self, node: ast.Attribute) -> None: ...
def visit_Lambda(self, node: ast.Lambda) -> None: ...

B005_METHODS: Final[set[str]]
B006_MUTABLE_LITERALS: Final[tuple[Literal["Dict"], Literal["List"], Literal["Set"]]]
B006_MUTABLE_COMPREHENSIONS: Final[tuple[Literal["ListComp"], Literal["DictComp"], Literal["SetComp"]]]
Expand Down