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
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: .github/|tests/testdata
- id: end-of-file-fixer
exclude: tests/testdata
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.5"
rev: "v0.11.4"
hooks:
- id: ruff
exclude: tests/testdata
Expand All @@ -23,7 +23,7 @@ repos:
exclude: tests/testdata|setup.py
types: [python]
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.19.1
hooks:
- id: pyupgrade
exclude: tests/testdata
Expand All @@ -34,7 +34,7 @@ repos:
- id: black-disable-checker
exclude: tests/test_nodes_lineno.py
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 25.1.0
hooks:
- id: black
args: [--safe, --quiet]
Expand All @@ -55,7 +55,7 @@ repos:
]
exclude: tests/testdata|conf.py
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
rev: v1.15.0
hooks:
- id: mypy
name: mypy
Expand All @@ -66,8 +66,12 @@ repos:
require_serial: true
additional_dependencies: ["types-typed-ast"]
exclude: tests/testdata| # exclude everything, we're not ready
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.5.3
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.5.1"
hooks:
- id: pyproject-fmt
22 changes: 12 additions & 10 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,16 @@ def _looks_like_special_alias(node: Call) -> bool:
PY39: Callable = _CallableType(collections.abc.Callable, 2)
"""
return isinstance(node.func, Name) and (
node.func.name == "_TupleType"
and isinstance(node.args[0], Name)
and node.args[0].name == "tuple"
or node.func.name == "_CallableType"
and isinstance(node.args[0], Attribute)
and node.args[0].as_string() == "collections.abc.Callable"
(
node.func.name == "_TupleType"
and isinstance(node.args[0], Name)
and node.args[0].name == "tuple"
)
or (
node.func.name == "_CallableType"
and isinstance(node.args[0], Attribute)
and node.args[0].as_string() == "collections.abc.Callable"
)
)


Expand Down Expand Up @@ -400,10 +404,8 @@ def infer_special_alias(

def _looks_like_typing_cast(node: Call) -> bool:
return isinstance(node, Call) and (
isinstance(node.func, Name)
and node.func.name == "cast"
or isinstance(node.func, Attribute)
and node.func.attrname == "cast"
(isinstance(node.func, Name) and node.func.name == "cast")
or (isinstance(node.func, Attribute) and node.func.attrname == "cast")
)


Expand Down
12 changes: 6 additions & 6 deletions astroid/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class InferenceContext:
"""

__slots__ = (
"path",
"lookupname",
"callcontext",
"_nodes_inferred",
"boundnode",
"extra_context",
"callcontext",
"constraints",
"_nodes_inferred",
"extra_context",
"lookupname",
"path",
)

max_inferred = 100
Expand Down Expand Up @@ -163,7 +163,7 @@ def __str__(self) -> str:
class CallContext:
"""Holds information for a call site."""

__slots__ = ("args", "keywords", "callee")
__slots__ = ("args", "callee", "keywords")

def __init__(
self,
Expand Down
14 changes: 8 additions & 6 deletions astroid/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def wrapped(


def yes_if_nothing_inferred(
func: Callable[_P, Generator[InferenceResult]]
func: Callable[_P, Generator[InferenceResult]],
) -> Callable[_P, Generator[InferenceResult]]:
def inner(*args: _P.args, **kwargs: _P.kwargs) -> Generator[InferenceResult]:
generator = func(*args, **kwargs)
Expand Down Expand Up @@ -146,11 +146,13 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
# - len(args) needs to be long enough, if too short
# arg can't be in args either
# - args[index] should not be None
or arg not in kwargs
and (
index == -1
or len(args) <= index
or (len(args) > index and args[index] is None)
or (
arg not in kwargs
and (
index == -1
or len(args) <= index
or (len(args) > index and args[index] is None)
)
)
):
warnings.warn(
Expand Down
5 changes: 2 additions & 3 deletions astroid/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ def object_len(node, context: InferenceContext | None = None):
and result_of_len.pytype() == "builtins.int"
):
return result_of_len.value
if (
result_of_len is None
or isinstance(result_of_len, bases.Instance)
if result_of_len is None or (
isinstance(result_of_len, bases.Instance)
and result_of_len.is_subtype_of("builtins.int")
):
# Fake a result as we don't know the arguments of the instance call.
Expand Down
16 changes: 8 additions & 8 deletions astroid/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@
)

__all__ = (
"CONST_CLS",
"AnnAssign",
"are_exclusive",
"Arguments",
"Assert",
"Assign",
Expand All @@ -218,20 +218,17 @@
"BinOp",
"BoolOp",
"Break",
"builtin_lookup",
"Call",
"ClassDef",
"CONST_CLS",
"Compare",
"Comprehension",
"ComprehensionScope",
"Const",
"const_factory",
"Continue",
"Decorators",
"DelAttr",
"Delete",
"DelName",
"Delete",
"Dict",
"DictComp",
"DictUnpack",
Expand All @@ -242,9 +239,7 @@
"For",
"FormattedValue",
"FunctionDef",
"function_to_method",
"GeneratorExp",
"get_wrapping_class",
"Global",
"If",
"IfExp",
Expand Down Expand Up @@ -289,9 +284,14 @@
"TypeVarTuple",
"UnaryOp",
"Unknown",
"unpack_infer",
"While",
"With",
"Yield",
"YieldFrom",
"are_exclusive",
"builtin_lookup",
"const_factory",
"function_to_method",
"get_wrapping_class",
"unpack_infer",
)
6 changes: 2 additions & 4 deletions astroid/nodes/_base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,11 @@ def _get_binop_flow(
and op == "|"
and (
isinstance(left, (bases.UnionType, nodes.ClassDef))
or isinstance(left, nodes.Const)
and left.value is None
or (isinstance(left, nodes.Const) and left.value is None)
)
and (
isinstance(right, (bases.UnionType, nodes.ClassDef))
or isinstance(right, nodes.Const)
and right.value is None
or (isinstance(right, nodes.Const) and right.value is None)
)
):
methods.extend([partial(OperatorNode._bin_op_or_union_type, left, right)])
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/as_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def visit_while(self, node) -> str:
def visit_with(self, node) -> str: # 'with' without 'as' is possible
"""return an astroid.With node as string"""
items = ", ".join(
f"{expr.accept(self)}" + (v and f" as {v.accept(self)}" or "")
f"{expr.accept(self)}" + ((v and f" as {v.accept(self)}") or "")
for expr, v in node.items
)
return f"with {items}:\n{self._stmt_list(node.body)}"
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"LocalsDictNodeNG",
"Module",
"SetComp",
"_is_metaclass",
"builtin_lookup",
"function_to_method",
"get_wrapping_class",
"_is_metaclass",
)
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@ def scope_lookup(
)
if (
any(
node == base or base.parent_of(node) and not self.type_params
node == base or (base.parent_of(node) and not self.type_params)
for base in self.bases
)
or lookup_upper_frame
Expand Down
Loading