Skip to content

Commit b0dd52e

Browse files
authored
Update astroid nodes import (#10592)
1 parent 68ab16f commit b0dd52e

21 files changed

+61
-69
lines changed

pylint/checkers/base/basic_error_checker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def _get_break_loop_node(break_node: nodes.Break) -> nodes.For | nodes.While | N
2727
"""Returns the loop node that holds the break node in arguments.
2828
2929
Args:
30-
break_node (astroid.Break): the break node of interest.
30+
break_node (nodes.Break): the break node of interest.
3131
3232
Returns:
33-
astroid.For or astroid.While: the loop node holding the break node.
33+
nodes.For or nodes.While: the loop node holding the break node.
3434
"""
3535
loop_nodes = (nodes.For, nodes.While)
3636
parent = break_node.parent
@@ -48,7 +48,7 @@ def _loop_exits_early(loop: nodes.For | nodes.While) -> bool:
4848
"""Returns true if a loop may end with a break statement.
4949
5050
Args:
51-
loop (astroid.For, astroid.While): the loop node inspected.
51+
loop (nodes.For, nodes.While): the loop node inspected.
5252
5353
Returns:
5454
bool: True if the loop may end with a break statement, False otherwise.

pylint/checkers/base/name_checker/checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,9 @@ def _should_exempt_from_invalid_name(node: nodes.NodeNG) -> bool:
650650
@staticmethod
651651
def _assigns_typevar(node: nodes.NodeNG | None) -> str | None:
652652
"""Check if a node is assigning a TypeVar and return TypeVar type."""
653-
if isinstance(node, astroid.Call):
653+
if isinstance(node, nodes.Call):
654654
inferred = utils.safe_infer(node.func)
655-
if isinstance(inferred, astroid.ClassDef):
655+
if isinstance(inferred, nodes.ClassDef):
656656
qname = inferred.qname()
657657
for typevar_node_typ, qnames in TYPE_VAR_QNAMES.items():
658658
if qname in qnames:

pylint/checkers/classes/class_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ def _check_functools_or_not(self, decorator: nodes.Attribute) -> bool:
15171517
return False
15181518
import_node = import_nodes[0]
15191519

1520-
if not isinstance(import_node, (astroid.Import, astroid.ImportFrom)):
1520+
if not isinstance(import_node, (nodes.Import, nodes.ImportFrom)):
15211521
return False
15221522

15231523
return "functools" in dict(import_node.names)

pylint/checkers/classes/special_methods_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def _check_getnewargs_ex(
379379
return
380380

381381
if not isinstance(inferred, nodes.Tuple):
382-
# If it's not an astroid.Tuple we can't analyze it further
382+
# If it's not an nodes.Tuple we can't analyze it further
383383
return
384384

385385
found_error = False

pylint/checkers/deprecated.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
astroid.UnboundMethod,
2525
nodes.FunctionDef,
2626
nodes.ClassDef,
27-
astroid.Attribute,
27+
nodes.Attribute,
2828
)
2929

3030

@@ -89,8 +89,8 @@ class DeprecatedMixin(BaseChecker):
8989
}
9090

9191
@utils.only_required_for_messages("deprecated-attribute")
92-
def visit_attribute(self, node: astroid.Attribute) -> None:
93-
"""Called when an `astroid.Attribute` node is visited."""
92+
def visit_attribute(self, node: nodes.Attribute) -> None:
93+
"""Called when an `Attribute` node is visited."""
9494
self.check_deprecated_attribute(node)
9595

9696
@utils.only_required_for_messages(
@@ -111,7 +111,7 @@ def visit_call(self, node: nodes.Call) -> None:
111111
and inferred.qname() == "builtins.__import__"
112112
and len(node.args) == 1
113113
and (mod_path_node := utils.safe_infer(node.args[0]))
114-
and isinstance(mod_path_node, astroid.Const)
114+
and isinstance(mod_path_node, nodes.Const)
115115
):
116116
self.check_deprecated_module(node, mod_path_node.value)
117117

@@ -219,7 +219,7 @@ def deprecated_attributes(self) -> Iterable[str]:
219219
"""Callback returning the deprecated attributes."""
220220
return ()
221221

222-
def check_deprecated_attribute(self, node: astroid.Attribute) -> None:
222+
def check_deprecated_attribute(self, node: nodes.Attribute) -> None:
223223
"""Checks if the attribute is deprecated."""
224224
inferred_expr = safe_infer(node.expr)
225225
if not isinstance(inferred_expr, (nodes.ClassDef, Instance, nodes.Module)):

pylint/checkers/design_analysis.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from collections.abc import Iterator
1212
from typing import TYPE_CHECKING
1313

14-
import astroid
1514
from astroid import nodes
1615

1716
from pylint.checkers import BaseChecker
@@ -182,7 +181,7 @@
182181
)
183182

184183

185-
def _is_exempt_from_public_methods(node: astroid.ClassDef) -> bool:
184+
def _is_exempt_from_public_methods(node: nodes.ClassDef) -> bool:
186185
"""Check if a class is exempt from too-few-public-methods."""
187186
# If it's a typing.Namedtuple, typing.TypedDict or an Enum
188187
for ancestor in node.ancestors():
@@ -201,10 +200,10 @@ def _is_exempt_from_public_methods(node: astroid.ClassDef) -> bool:
201200

202201
root_locals = set(node.root().locals)
203202
for decorator in node.decorators.nodes:
204-
if isinstance(decorator, astroid.Call):
203+
if isinstance(decorator, nodes.Call):
205204
decorator = decorator.func
206205
match decorator:
207-
case astroid.Name(name=name) | astroid.Attribute(attrname=name):
206+
case nodes.Name(name=name) | nodes.Attribute(attrname=name):
208207
pass
209208
case _:
210209
continue
@@ -227,7 +226,7 @@ def _count_boolean_expressions(bool_op: nodes.BoolOp) -> int:
227226
"""
228227
nb_bool_expr = 0
229228
for bool_expr in bool_op.get_children():
230-
if isinstance(bool_expr, astroid.BoolOp):
229+
if isinstance(bool_expr, nodes.BoolOp):
231230
nb_bool_expr += _count_boolean_expressions(bool_expr)
232231
else:
233232
nb_bool_expr += 1
@@ -662,7 +661,7 @@ def visit_if(self, node: nodes.If) -> None:
662661
branches = 1
663662
# don't double count If nodes coming from some 'elif'
664663
if node.orelse and (
665-
len(node.orelse) > 1 or not isinstance(node.orelse[0], astroid.If)
664+
len(node.orelse) > 1 or not isinstance(node.orelse[0], nodes.If)
666665
):
667666
branches += 1
668667
self._inc_branch(node, branches)
@@ -673,7 +672,7 @@ def _check_boolean_expressions(self, node: nodes.If) -> None:
673672
if the 'if' node test is a BoolOp node.
674673
"""
675674
condition = node.test
676-
if not isinstance(condition, astroid.BoolOp):
675+
if not isinstance(condition, nodes.BoolOp):
677676
return
678677
nb_bool_expr = _count_boolean_expressions(condition)
679678
if nb_bool_expr > self.linter.config.max_bool_expr:

pylint/checkers/refactoring/implicit_booleaness_checker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
def _is_constant_zero(node: str | nodes.NodeNG) -> bool:
1818
# We have to check that node.value is not False because node.value == 0 is True
1919
# when node.value is False
20-
return (
21-
isinstance(node, astroid.Const) and node.value == 0 and node.value is not False
22-
)
20+
return isinstance(node, nodes.Const) and node.value == 0 and node.value is not False
2321

2422

2523
class ImplicitBooleanessChecker(checkers.BaseChecker):
@@ -195,7 +193,7 @@ def _check_compare_to_str_or_zero(self, node: nodes.Compare) -> None:
195193
return
196194

197195
negation_redundant_ops = {"!=", "is not"}
198-
# note: astroid.Compare has the left most operand in node.left
196+
# note: nodes.Compare has the left most operand in node.left
199197
# while the rest are a list of tuples in node.ops
200198
# the format of the tuple is ('compare operator sign', node)
201199
# here we squash everything into `ops` to make it easier for processing later

pylint/checkers/refactoring/recommendation_checker.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,7 @@ def _detect_replacable_format_call(self, node: nodes.Const) -> None:
392392
# If star expressions with more than 1 element are being used
393393
if isinstance(arg, nodes.Starred):
394394
inferred = utils.safe_infer(arg.value)
395-
if (
396-
isinstance(inferred, astroid.List)
397-
and len(inferred.elts) > 1
398-
):
395+
if isinstance(inferred, nodes.List) and len(inferred.elts) > 1:
399396
return
400397
# Backslashes can't be in f-string expressions
401398
if "\\" in arg.as_string():

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ def _check_use_list_literal(self, node: nodes.Call) -> None:
17121712

17131713
def _check_use_dict_literal(self, node: nodes.Call) -> None:
17141714
"""Check if dict is created by using the literal {}."""
1715-
if not (isinstance(node.func, astroid.Name) and node.func.name == "dict"):
1715+
if not (isinstance(node.func, nodes.Name) and node.func.name == "dict"):
17161716
return
17171717
inferred = utils.safe_infer(node.func)
17181718
if (

pylint/checkers/typecheck.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,19 +756,19 @@ def _infer_from_metaclass_constructor(
756756
) -> InferenceResult | None:
757757
"""Try to infer what the given *func* constructor is building.
758758
759-
:param astroid.FunctionDef func:
759+
:param nodes.FunctionDef func:
760760
A metaclass constructor. Metaclass definitions can be
761761
functions, which should accept three arguments, the name of
762762
the class, the bases of the class and the attributes.
763763
The function could return anything, but usually it should
764764
be a proper metaclass.
765-
:param astroid.ClassDef cls:
765+
:param nodes.ClassDef cls:
766766
The class for which the *func* parameter should generate
767767
a metaclass.
768768
:returns:
769769
The class generated by the function or None,
770770
if we couldn't infer it.
771-
:rtype: astroid.ClassDef
771+
:rtype: nodes.ClassDef
772772
"""
773773
context = astroid.context.InferenceContext()
774774

@@ -1130,7 +1130,7 @@ def visit_attribute(
11301130
except astroid.NotFoundError:
11311131
# Avoid false positive in case a decorator supplies member.
11321132
if (
1133-
isinstance(owner, (astroid.FunctionDef, astroid.BoundMethod))
1133+
isinstance(owner, (nodes.FunctionDef, astroid.BoundMethod))
11341134
and owner.decorators
11351135
):
11361136
continue

0 commit comments

Comments
 (0)