Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 25, 2024
1 parent 0f800ca commit 789e7ec
Show file tree
Hide file tree
Showing 28 changed files with 186 additions and 164 deletions.
4 changes: 2 additions & 2 deletions pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

__all__ = [
"__version__",
"version",
"modify_sys_path",
"run_pylint",
"run_symilar",
"run_pyreverse",
"run_symilar",
"version",
]

import os
Expand Down
4 changes: 2 additions & 2 deletions pylint/checkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def initialize(linter: PyLinter) -> None:

__all__ = [
"BaseChecker",
"BaseTokenChecker",
"BaseRawFileChecker",
"initialize",
"BaseTokenChecker",
"DeprecatedMixin",
"initialize",
"register_plugins",
]
8 changes: 4 additions & 4 deletions pylint/checkers/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from __future__ import annotations

__all__ = [
"KNOWN_NAME_TYPES_WITH_STYLE",
"AnyStyle",
"CamelCaseStyle",
"NameChecker",
"NamingStyle",
"KNOWN_NAME_TYPES_WITH_STYLE",
"PascalCaseStyle",
"SnakeCaseStyle",
"CamelCaseStyle",
"UpperCaseStyle",
"PascalCaseStyle",
"AnyStyle",
]

from typing import TYPE_CHECKING
Expand Down
3 changes: 1 addition & 2 deletions pylint/checkers/base/basic_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,7 @@ def _has_variadic_argument(
args: list[nodes.Starred | nodes.Keyword], variadic_name: str
) -> bool:
return not args or any(
isinstance(a.value, nodes.Name)
and a.value.name != variadic_name
(isinstance(a.value, nodes.Name) and a.value.name != variadic_name)
or not isinstance(a.value, nodes.Name)
for a in args
)
Expand Down
4 changes: 3 additions & 1 deletion pylint/checkers/base/basic_error_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
if not redefined_by_decorator(
node
) and not utils.is_registered_in_singledispatch_function(node):
self._check_redefinition(node.is_method() and "method" or "function", node)
self._check_redefinition(
(node.is_method() and "method") or "function", node
)
# checks for max returns, branch, return in __init__
returns = node.nodes_of_class(
nodes.Return, skip_klass=(nodes.FunctionDef, nodes.ClassDef)
Expand Down
8 changes: 4 additions & 4 deletions pylint/checkers/base/name_checker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt

__all__ = [
"KNOWN_NAME_TYPES_WITH_STYLE",
"AnyStyle",
"CamelCaseStyle",
"NameChecker",
"NamingStyle",
"KNOWN_NAME_TYPES_WITH_STYLE",
"PascalCaseStyle",
"SnakeCaseStyle",
"CamelCaseStyle",
"UpperCaseStyle",
"PascalCaseStyle",
"AnyStyle",
]

from pylint.checkers.base.name_checker.checker import NameChecker
Expand Down
4 changes: 3 additions & 1 deletion pylint/checkers/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def check_deprecated_attribute(self, node: astroid.Attribute) -> None:
def check_deprecated_module(self, node: nodes.Import, mod_path: str | None) -> None:
"""Checks if the module is deprecated."""
for mod_name in self.deprecated_modules():
if mod_path == mod_name or mod_path and mod_path.startswith(mod_name + "."):
if mod_path == mod_name or (
mod_path and mod_path.startswith(mod_name + ".")
):
self.add_message("deprecated-module", node=node, args=mod_path)

def check_deprecated_method(self, node: nodes.Call, inferred: nodes.NodeNG) -> None:
Expand Down
3 changes: 1 addition & 2 deletions pylint/checkers/dunder_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def within_dunder_or_lambda_def(node: nodes.NodeNG) -> bool:
isinstance(parent, nodes.FunctionDef)
and parent.name.startswith("__")
and parent.name.endswith("__")
or DunderCallChecker.is_lambda_rule_exception(parent, node)
):
) or DunderCallChecker.is_lambda_rule_exception(parent, node):
return True
parent = parent.parent
return False
Expand Down
6 changes: 3 additions & 3 deletions pylint/checkers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ def _check_raise_missing_from(self, node: nodes.Raise) -> None:
confidence=HIGH,
)
elif (
isinstance(node.exc, nodes.Call)
and isinstance(node.exc.func, nodes.Name)
or isinstance(node.exc, nodes.Name)
isinstance(node.exc, nodes.Call) and isinstance(node.exc.func, nodes.Name)
) or (
isinstance(node.exc, nodes.Name)
and node.exc.name != containing_except_node.name.name
):
# We have a `raise SomeException(whatever)` or a `raise SomeException`
Expand Down
6 changes: 2 additions & 4 deletions pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@


def _last_token_on_line_is(tokens: TokenWrapper, line_end: int, token: str) -> bool:
return (
line_end > 0
and tokens.token(line_end - 1) == token
or line_end > 1
return (line_end > 0 and tokens.token(line_end - 1) == token) or (
line_end > 1
and tokens.token(line_end - 2) == token
and tokens.type(line_end - 1) == tokenize.COMMENT
)
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ def _filter_dependencies_graph(self, internal: bool) -> defaultdict[str, set[str
for importer in importers:
package = self._module_pkg.get(importer, importer)
is_inside = importee.startswith(package)
if is_inside and internal or not is_inside and not internal:
if (is_inside and internal) or (not is_inside and not internal):
graph[importee].add(importer)
return graph

Expand Down
20 changes: 12 additions & 8 deletions pylint/checkers/refactoring/recommendation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ def _check_consider_iterating_dictionary(self, node: nodes.Call) -> None:
return

comp_ancestor = utils.get_node_first_ancestor_of_type(node, nodes.Compare)
if (
isinstance(node.parent, (nodes.For, nodes.Comprehension))
or comp_ancestor
if isinstance(node.parent, (nodes.For, nodes.Comprehension)) or (
comp_ancestor
and any(
op
for op, comparator in comp_ancestor.ops
Expand Down Expand Up @@ -257,10 +256,14 @@ def _check_consider_using_enumerate(self, node: nodes.For) -> None:
# name for the iterating object was used.
continue
if value.name == node.target.name and (
isinstance(subscript.value, nodes.Name)
and iterating_object.name == subscript.value.name
or isinstance(subscript.value, nodes.Attribute)
and iterating_object.attrname == subscript.value.attrname
(
isinstance(subscript.value, nodes.Name)
and iterating_object.name == subscript.value.name
)
or (
isinstance(subscript.value, nodes.Attribute)
and iterating_object.attrname == subscript.value.attrname
)
):
self.add_message("consider-using-enumerate", node=node)
return
Expand Down Expand Up @@ -301,7 +304,8 @@ def _check_consider_using_dict_items(self, node: nodes.For) -> None:
if (
isinstance(subscript.parent, nodes.Assign)
and subscript in subscript.parent.targets
or isinstance(subscript.parent, nodes.AugAssign)
) or (
isinstance(subscript.parent, nodes.AugAssign)
and subscript == subscript.parent.target
):
# Ignore this subscript if it is the target of an assignment
Expand Down
9 changes: 3 additions & 6 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2099,9 +2099,7 @@ def _is_function_def_never_returning(
return (
isinstance(returns, nodes.Attribute)
and returns.attrname in {"NoReturn", "Never"}
or isinstance(returns, nodes.Name)
and returns.name in {"NoReturn", "Never"}
)
) or (isinstance(returns, nodes.Name) and returns.name in {"NoReturn", "Never"})

def _check_return_at_the_end(self, node: nodes.FunctionDef) -> None:
"""Check for presence of a *single* return statement at the end of a
Expand Down Expand Up @@ -2452,9 +2450,8 @@ def _enumerate_with_start(
return False, confidence

def _get_start_value(self, node: nodes.NodeNG) -> tuple[int | None, Confidence]:
if (
isinstance(node, (nodes.Name, nodes.Call, nodes.Attribute))
or isinstance(node, nodes.UnaryOp)
if isinstance(node, (nodes.Name, nodes.Call, nodes.Attribute)) or (
isinstance(node, nodes.UnaryOp)
and isinstance(node.operand, (nodes.Attribute, nodes.Name))
):
inferred = utils.safe_infer(node)
Expand Down
5 changes: 2 additions & 3 deletions pylint/checkers/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,8 @@ def _check_open_call(
confidence=confidence,
)

if (
not mode_arg
or isinstance(mode_arg, nodes.Const)
if not mode_arg or (
isinstance(mode_arg, nodes.Const)
and (not mode_arg.value or "b" not in str(mode_arg.value))
):
confidence = HIGH
Expand Down
6 changes: 3 additions & 3 deletions pylint/checkers/symilar.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CplSuccessiveLinesLimits:
of common lines between both stripped lines collections extracted from both files.
"""

__slots__ = ("first_file", "second_file", "effective_cmn_lines_nb")
__slots__ = ("effective_cmn_lines_nb", "first_file", "second_file")

def __init__(
self,
Expand All @@ -110,7 +110,7 @@ class LinesChunk:
lines of a lineset.
"""

__slots__ = ("_fileid", "_index", "_hash")
__slots__ = ("_fileid", "_hash", "_index")

def __init__(self, fileid: str, num_line: int, *lines: Iterable[str]) -> None:
self._fileid: str = fileid
Expand Down Expand Up @@ -150,7 +150,7 @@ class SuccessiveLinesLimits:
:note: Only the end line number can be updated.
"""

__slots__ = ("_start", "_end")
__slots__ = ("_end", "_start")

def __init__(self, start: LineNumber, end: LineNumber) -> None:
self._start: LineNumber = start
Expand Down
30 changes: 16 additions & 14 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,8 @@ def _emit_no_member(
isinstance(inferred, nodes.Const)
and inferred.bool_value() is False
and (
isinstance(parent, nodes.If)
and node_origin in parent.body
or isinstance(parent, nodes.IfExp)
and node_origin == parent.body
(isinstance(parent, nodes.If) and node_origin in parent.body)
or (isinstance(parent, nodes.IfExp) and node_origin == parent.body)
)
):
return False
Expand Down Expand Up @@ -675,10 +673,8 @@ def _no_context_variadic_keywords(node: nodes.Call, scope: nodes.Lambda) -> bool
variadics = []

if (
isinstance(scope, nodes.Lambda)
and not isinstance(scope, nodes.FunctionDef)
or isinstance(statement, nodes.With)
):
isinstance(scope, nodes.Lambda) and not isinstance(scope, nodes.FunctionDef)
) or isinstance(statement, nodes.With):
variadics = list(node.keywords or []) + node.kwargs
elif isinstance(statement, (nodes.Return, nodes.Expr, nodes.Assign)) and isinstance(
statement.value, nodes.Call
Expand Down Expand Up @@ -1276,8 +1272,10 @@ def _check_assignment_from_function_call(self, node: nodes.Assign) -> None:
else:
for ret_node in return_nodes:
if not (
isinstance(ret_node.value, nodes.Const)
and ret_node.value.value is None
(
isinstance(ret_node.value, nodes.Const)
and ret_node.value.value is None
)
or ret_node.value is None
):
break
Expand Down Expand Up @@ -1862,10 +1860,14 @@ def _check_invalid_slice_index(self, node: nodes.Slice) -> None:
)
if not (
isinstance(inferred, known_objects)
or isinstance(inferred, nodes.Const)
and inferred.pytype() in {"builtins.str", "builtins.bytes"}
or isinstance(inferred, astroid.bases.Instance)
and inferred.pytype() == "builtins.range"
or (
isinstance(inferred, nodes.Const)
and inferred.pytype() in {"builtins.str", "builtins.bytes"}
)
or (
isinstance(inferred, astroid.bases.Instance)
and inferred.pytype() == "builtins.range"
)
):
# Might be an instance that knows how to handle this slice object
return
Expand Down
40 changes: 21 additions & 19 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,19 +1621,25 @@ def is_node_in_type_annotation_context(node: nodes.NodeNG) -> bool:
current_node, parent_node = node, node.parent
while True:
if (
isinstance(parent_node, nodes.AnnAssign)
and parent_node.annotation == current_node
or isinstance(parent_node, nodes.Arguments)
and current_node
in (
*parent_node.annotations,
*parent_node.posonlyargs_annotations,
*parent_node.kwonlyargs_annotations,
parent_node.varargannotation,
parent_node.kwargannotation,
(
isinstance(parent_node, nodes.AnnAssign)
and parent_node.annotation == current_node
)
or (
isinstance(parent_node, nodes.Arguments)
and current_node
in (
*parent_node.annotations,
*parent_node.posonlyargs_annotations,
*parent_node.kwonlyargs_annotations,
parent_node.varargannotation,
parent_node.kwargannotation,
)
)
or (
isinstance(parent_node, nodes.FunctionDef)
and parent_node.returns == current_node
)
or isinstance(parent_node, nodes.FunctionDef)
and parent_node.returns == current_node
):
return True
current_node, parent_node = parent_node, parent_node.parent
Expand Down Expand Up @@ -1762,11 +1768,8 @@ def is_assign_name_annotated_with(node: nodes.AssignName, typing_name: str) -> b
annotation = node.parent.annotation
if isinstance(annotation, nodes.Subscript):
annotation = annotation.value
if (
isinstance(annotation, nodes.Name)
and annotation.name == typing_name
or isinstance(annotation, nodes.Attribute)
and annotation.attrname == typing_name
if (isinstance(annotation, nodes.Name) and annotation.name == typing_name) or (
isinstance(annotation, nodes.Attribute) and annotation.attrname == typing_name
):
return True
return False
Expand Down Expand Up @@ -2181,8 +2184,7 @@ def is_terminating_func(node: nodes.Call) -> bool:
if (
not isinstance(node.func, nodes.Attribute)
and not (isinstance(node.func, nodes.Name))
or isinstance(node.parent, nodes.Lambda)
):
) or isinstance(node.parent, nodes.Lambda):
return False

try:
Expand Down
Loading

0 comments on commit 789e7ec

Please sign in to comment.