Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (pylint-dev#2642)
Browse files Browse the repository at this point in the history
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.4 → v0.8.0](astral-sh/ruff-pre-commit@v0.7.4...v0.8.0)
  • Loading branch information
pre-commit-ci[bot] authored Dec 1, 2024
1 parent 9efc827 commit 9705950
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: end-of-file-fixer
exclude: tests/testdata
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.4"
rev: "v0.8.0"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
23 changes: 12 additions & 11 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,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,11 +404,8 @@ def infer_special_alias(


def _looks_like_typing_cast(node: Call) -> bool:
return (
isinstance(node.func, Name)
and node.func.name == "cast"
or isinstance(node.func, Attribute)
and node.func.attrname == "cast"
return (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 @@ -37,13 +37,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 @@ -164,7 +164,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
12 changes: 7 additions & 5 deletions astroid/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,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 @@ -300,9 +300,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
18 changes: 9 additions & 9 deletions astroid/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@
)

__all__ = (
"CONST_CLS",
"SYNTHETIC_ROOT",
"AnnAssign",
"are_exclusive",
"Arguments",
"Assert",
"Assign",
Expand All @@ -219,20 +220,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 @@ -243,9 +241,7 @@
"For",
"FormattedValue",
"FunctionDef",
"function_to_method",
"GeneratorExp",
"get_wrapping_class",
"Global",
"If",
"IfExp",
Expand Down Expand Up @@ -277,7 +273,6 @@
"Position",
"Raise",
"Return",
"SYNTHETIC_ROOT",
"Set",
"SetComp",
"Slice",
Expand All @@ -291,9 +286,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 @@ -609,13 +609,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 @@ -571,7 +571,7 @@ def visit_while(self, node: nodes.While) -> str:
def visit_with(self, node: nodes.With) -> 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
6 changes: 2 additions & 4 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4791,10 +4791,8 @@ def _infer_with_values(
) -> Generator[InferenceResult, None, InferenceErrorInfo | None]:
uninferable_already_generated = False
for inferred in self._infer_from_values(self.values, context):
failed = (
inferred is util.Uninferable
or isinstance(inferred, Const)
and UNINFERABLE_VALUE in inferred.value
failed = inferred is util.Uninferable or (
isinstance(inferred, Const) and UNINFERABLE_VALUE in inferred.value
)
if failed:
if not uninferable_already_generated:
Expand Down
4 changes: 2 additions & 2 deletions astroid/nodes/scoped_nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from astroid.nodes.scoped_nodes.utils import builtin_lookup

__all__ = (
"SYNTHETIC_ROOT",
"AsyncFunctionDef",
"ClassDef",
"ComprehensionScope",
Expand All @@ -38,10 +39,9 @@
"ListComp",
"LocalsDictNodeNG",
"Module",
"SYNTHETIC_ROOT",
"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 @@ -2128,7 +2128,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
6 changes: 2 additions & 4 deletions script/test_bump_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
)
def test_get_next_version(version, version_type, expected_version, expected_versions):
assert get_next_version(version, version_type) == expected_version
if (
version_type == VersionType.PATCH
or version_type == VersionType.MINOR
and version.endswith(".0")
if version_type == VersionType.PATCH or (
version_type == VersionType.MINOR and version.endswith(".0")
):
assert get_next_versions(version, version_type) == expected_versions

Expand Down

0 comments on commit 9705950

Please sign in to comment.