summaryrefslogtreecommitdiff
path: root/pylint/checkers/classes.py
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-08-17 22:19:04 +0200
committerGitHub <noreply@github.com>2021-08-17 22:19:04 +0200
commit6e2dbbf4630c97c2fa7dc36dcb29c7501221acd6 (patch)
tree4fbb8b6d843e095a34f89c40b993d50c6a61c2c3 /pylint/checkers/classes.py
parentef72cdc6f9b96ea680d6a9d0f37861f80d6bc3db (diff)
downloadpylint-git-6e2dbbf4630c97c2fa7dc36dcb29c7501221acd6.tar.gz
Use alias for astroid.nodes 01 (#4855)
* Use from astroid import nodes * Resolve name conflicts
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r--pylint/checkers/classes.py229
1 files changed, 115 insertions, 114 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index ec0312eba..3ecc738e5 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -50,6 +50,7 @@ from itertools import chain, zip_longest
from typing import List, Pattern, cast
import astroid
+from astroid import nodes
from pylint.checkers import BaseChecker
from pylint.checkers.utils import (
@@ -99,21 +100,21 @@ def _signature_from_call(call):
starred_args = []
for keyword in call.keywords or []:
arg, value = keyword.arg, keyword.value
- if arg is None and isinstance(value, astroid.Name):
+ if arg is None and isinstance(value, nodes.Name):
# Starred node and we are interested only in names,
# otherwise some transformation might occur for the parameter.
starred_kws.append(value.name)
- elif isinstance(value, astroid.Name):
+ elif isinstance(value, nodes.Name):
kws[arg] = value.name
else:
kws[arg] = None
for arg in call.args:
- if isinstance(arg, astroid.Starred) and isinstance(arg.value, astroid.Name):
+ if isinstance(arg, nodes.Starred) and isinstance(arg.value, nodes.Name):
# Positional variadic and a name, otherwise some transformation
# might have occurred.
starred_args.append(arg.value.name)
- elif isinstance(arg, astroid.Name):
+ elif isinstance(arg, nodes.Name):
args.append(arg.name)
else:
args.append(None)
@@ -245,11 +246,11 @@ def _has_different_parameters_default_value(original, overridden):
return True
astroid_type_compared_attr = {
- astroid.Const: "value",
- astroid.ClassDef: "name",
- astroid.Tuple: "elts",
- astroid.List: "elts",
- astroid.Dict: "items",
+ nodes.Const: "value",
+ nodes.ClassDef: "name",
+ nodes.Tuple: "elts",
+ nodes.List: "elts",
+ nodes.Dict: "items",
}
handled_types = tuple(
astroid_type for astroid_type in astroid_type_compared_attr
@@ -271,8 +272,8 @@ def _has_different_parameters_default_value(original, overridden):
def _has_different_parameters(
- original: List[astroid.AssignName],
- overridden: List[astroid.AssignName],
+ original: List[nodes.AssignName],
+ overridden: List[nodes.AssignName],
dummy_parameter_regex: Pattern,
) -> List[str]:
result = []
@@ -296,8 +297,8 @@ def _has_different_parameters(
def _different_parameters(
- original: astroid.FunctionDef,
- overridden: astroid.FunctionDef,
+ original: nodes.FunctionDef,
+ overridden: nodes.FunctionDef,
dummy_parameter_regex: Pattern,
) -> List[str]:
"""Determine if the two methods have different parameters
@@ -400,7 +401,7 @@ def _called_in_methods(func, klass, methods):
"""Check if the func was called in any of the given methods,
belonging to the *klass*. Returns True if so, False otherwise.
"""
- if not isinstance(func, astroid.FunctionDef):
+ if not isinstance(func, nodes.FunctionDef):
return False
for method in methods:
try:
@@ -408,7 +409,7 @@ def _called_in_methods(func, klass, methods):
except astroid.NotFoundError:
continue
for infer_method in inferred:
- for call in infer_method.nodes_of_class(astroid.Call):
+ for call in infer_method.nodes_of_class(nodes.Call):
try:
bound = next(call.func.infer())
except (astroid.InferenceError, StopIteration):
@@ -445,7 +446,7 @@ def _is_attribute_property(name, klass):
inferred = next(attr.infer())
except astroid.InferenceError:
continue
- if isinstance(inferred, astroid.FunctionDef) and decorated_with_property(
+ if isinstance(inferred, nodes.FunctionDef) and decorated_with_property(
inferred
):
return True
@@ -460,9 +461,9 @@ def _is_attribute_property(name, klass):
def _has_bare_super_call(fundef_node):
- for call in fundef_node.nodes_of_class(astroid.Call):
+ for call in fundef_node.nodes_of_class(nodes.Call):
func = call.func
- if isinstance(func, astroid.Name) and func.name == "super" and not call.args:
+ if isinstance(func, nodes.Name) and func.name == "super" and not call.args:
return True
return False
@@ -492,7 +493,7 @@ def _safe_infer_call_result(node, caller, context=None):
def _has_same_layout_slots(slots, assigned_value):
inferred = next(assigned_value.infer())
- if isinstance(inferred, astroid.ClassDef):
+ if isinstance(inferred, nodes.ClassDef):
other_slots = inferred.slots()
if all(
first_slot and second_slot and first_slot.value == second_slot.value
@@ -883,7 +884,7 @@ a metaclass class method.",
):
continue
- if not isinstance(ancestor, astroid.ClassDef) or _is_invalid_base_class(
+ if not isinstance(ancestor, nodes.ClassDef) or _is_invalid_base_class(
ancestor
):
self.add_message("inherit-non-class", args=base.as_string(), node=node)
@@ -894,7 +895,7 @@ a metaclass class method.",
)
@check_messages("unused-private-member", "attribute-defined-outside-init")
- def leave_classdef(self, node: astroid.ClassDef) -> None:
+ def leave_classdef(self, node: nodes.ClassDef) -> None:
"""close a class node:
check that instance attributes are defined in __init__ and check
access to existent members
@@ -904,36 +905,36 @@ a metaclass class method.",
self._check_unused_private_attributes(node)
self._check_attribute_defined_outside_init(node)
- def _check_unused_private_functions(self, node: astroid.ClassDef) -> None:
- for function_def in node.nodes_of_class(astroid.FunctionDef):
- function_def = cast(astroid.FunctionDef, function_def)
+ def _check_unused_private_functions(self, node: nodes.ClassDef) -> None:
+ for function_def in node.nodes_of_class(nodes.FunctionDef):
+ function_def = cast(nodes.FunctionDef, function_def)
if not is_attr_private(function_def.name):
continue
parent_scope = function_def.parent.scope()
- if isinstance(parent_scope, astroid.FunctionDef):
+ if isinstance(parent_scope, nodes.FunctionDef):
# Handle nested functions
if function_def.name in (
- n.name for n in parent_scope.nodes_of_class(astroid.Name)
+ n.name for n in parent_scope.nodes_of_class(nodes.Name)
):
continue
- for attribute in node.nodes_of_class(astroid.Attribute):
- attribute = cast(astroid.Attribute, attribute)
+ for attribute in node.nodes_of_class(nodes.Attribute):
+ attribute = cast(nodes.Attribute, attribute)
if (
attribute.attrname != function_def.name
or attribute.scope() == function_def # We ignore recursive calls
):
continue
- if isinstance(attribute.expr, astroid.Name) and attribute.expr.name in (
+ if isinstance(attribute.expr, nodes.Name) and attribute.expr.name in (
"self",
node.name,
):
# self.__attrname / node_name.__attrname
break
- if isinstance(attribute.expr, astroid.Call):
+ if isinstance(attribute.expr, nodes.Call):
# type(self).__attrname
inferred = safe_infer(attribute.expr)
if (
- isinstance(inferred, astroid.ClassDef)
+ isinstance(inferred, nodes.ClassDef)
and inferred.name == node.name
):
break
@@ -953,17 +954,17 @@ a metaclass class method.",
args=(node.name, function_repr.lstrip(".")),
)
- def _check_unused_private_variables(self, node: astroid.ClassDef) -> None:
- for assign_name in node.nodes_of_class(astroid.AssignName):
- if isinstance(assign_name.parent, astroid.Arguments):
+ def _check_unused_private_variables(self, node: nodes.ClassDef) -> None:
+ for assign_name in node.nodes_of_class(nodes.AssignName):
+ if isinstance(assign_name.parent, nodes.Arguments):
continue # Ignore function arguments
if not is_attr_private(assign_name.name):
continue
- for child in node.nodes_of_class((astroid.Name, astroid.Attribute)):
- if isinstance(child, astroid.Name) and child.name == assign_name.name:
+ for child in node.nodes_of_class((nodes.Name, nodes.Attribute)):
+ if isinstance(child, nodes.Name) and child.name == assign_name.name:
break
if (
- isinstance(child, astroid.Attribute)
+ isinstance(child, nodes.Attribute)
and child.attrname == assign_name.name
and child.expr.name in ("self", "cls", node.name)
):
@@ -972,11 +973,11 @@ a metaclass class method.",
args = (node.name, assign_name.name)
self.add_message("unused-private-member", node=assign_name, args=args)
- def _check_unused_private_attributes(self, node: astroid.ClassDef) -> None:
- for assign_attr in node.nodes_of_class(astroid.AssignAttr):
- assign_attr = cast(astroid.AssignAttr, assign_attr)
+ def _check_unused_private_attributes(self, node: nodes.ClassDef) -> None:
+ for assign_attr in node.nodes_of_class(nodes.AssignAttr):
+ assign_attr = cast(nodes.AssignAttr, assign_attr)
if not is_attr_private(assign_attr.attrname) or not isinstance(
- assign_attr.expr, astroid.Name
+ assign_attr.expr, nodes.Name
):
continue
@@ -985,17 +986,17 @@ a metaclass class method.",
# Then check if the attribute was consumed in other instance methods
acceptable_obj_names: List[str] = ["self"]
scope = assign_attr.scope()
- if isinstance(scope, astroid.FunctionDef) and scope.name == "__new__":
+ if isinstance(scope, nodes.FunctionDef) and scope.name == "__new__":
acceptable_obj_names.extend(
[
return_node.value.name
- for return_node in scope.nodes_of_class(astroid.Return)
- if isinstance(return_node.value, astroid.Name)
+ for return_node in scope.nodes_of_class(nodes.Return)
+ if isinstance(return_node.value, nodes.Name)
]
)
- for attribute in node.nodes_of_class(astroid.Attribute):
- attribute = cast(astroid.Attribute, attribute)
+ for attribute in node.nodes_of_class(nodes.Attribute):
+ attribute = cast(nodes.Attribute, attribute)
if attribute.attrname != assign_attr.attrname:
continue
@@ -1022,7 +1023,7 @@ a metaclass class method.",
args = (node.name, assign_attr.attrname)
self.add_message("unused-private-member", node=assign_attr, args=args)
- def _check_attribute_defined_outside_init(self, cnode: astroid.ClassDef) -> None:
+ def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
# check access to existent members on non metaclass classes
if self._ignore_mixin and cnode.name[-5:].lower() == "mixin":
# We are in a mixin class. No need to try to figure out if
@@ -1038,25 +1039,25 @@ a metaclass class method.",
return
defining_methods = self.config.defining_attr_methods
current_module = cnode.root()
- for attr, nodes in cnode.instance_attrs.items():
+ for attr, nodes_lst in cnode.instance_attrs.items():
# Exclude `__dict__` as it is already defined.
if attr == "__dict__":
continue
# Skip nodes which are not in the current module and it may screw up
# the output, while it's not worth it
- nodes = [
+ nodes_lst = [
n
- for n in nodes
- if not isinstance(n.statement(), (astroid.Delete, astroid.AugAssign))
+ for n in nodes_lst
+ if not isinstance(n.statement(), (nodes.Delete, nodes.AugAssign))
and n.root() is current_module
]
- if not nodes:
+ if not nodes_lst:
continue # error detected by typechecking
# Check if any method attr is defined in is a defining method
# or if we have the attribute defined in a setter.
- frames = (node.frame() for node in nodes)
+ frames = (node.frame() for node in nodes_lst)
if any(
frame.name in defining_methods or is_property_setter(frame)
for frame in frames
@@ -1078,7 +1079,7 @@ a metaclass class method.",
try:
cnode.local_attr(attr)
except astroid.NotFoundError:
- for node in nodes:
+ for node in nodes_lst:
if node.frame().name not in defining_methods:
# If the attribute was set by a call in any
# of the defining methods, then don't emit
@@ -1117,7 +1118,7 @@ a metaclass class method.",
# dictionary.
# This may happen with astroid build from living objects
continue
- if not isinstance(parent_function, astroid.FunctionDef):
+ if not isinstance(parent_function, nodes.FunctionDef):
continue
self._check_signature(node, parent_function, "overridden", klass)
self._check_invalid_overridden_method(node, parent_function)
@@ -1125,14 +1126,14 @@ a metaclass class method.",
if node.decorators:
for decorator in node.decorators.nodes:
- if isinstance(decorator, astroid.Attribute) and decorator.attrname in (
+ if isinstance(decorator, nodes.Attribute) and decorator.attrname in (
"getter",
"setter",
"deleter",
):
# attribute affectation will call this method, not hiding it
return
- if isinstance(decorator, astroid.Name):
+ if isinstance(decorator, nodes.Name):
if decorator.name == "property":
# attribute affectation will either call a setter or raise
# an attribute error, anyway not hiding the function
@@ -1142,7 +1143,7 @@ a metaclass class method.",
inferred = safe_infer(decorator)
if not inferred:
return
- if isinstance(inferred, astroid.FunctionDef):
+ if isinstance(inferred, nodes.FunctionDef):
# Okay, it's a decorator, let's see what it can infer.
try:
inferred = next(inferred.infer_call_result(inferred))
@@ -1150,7 +1151,7 @@ a metaclass class method.",
return
try:
if (
- isinstance(inferred, (astroid.Instance, astroid.ClassDef))
+ isinstance(inferred, (astroid.Instance, nodes.ClassDef))
and inferred.getattr("__get__")
and inferred.getattr("__set__")
):
@@ -1163,12 +1164,12 @@ a metaclass class method.",
overridden = klass.instance_attr(node.name)[0]
overridden_frame = overridden.frame()
if (
- isinstance(overridden_frame, astroid.FunctionDef)
+ isinstance(overridden_frame, nodes.FunctionDef)
and overridden_frame.type == "method"
):
overridden_frame = overridden_frame.parent.frame()
if not (
- isinstance(overridden_frame, astroid.ClassDef)
+ isinstance(overridden_frame, nodes.ClassDef)
and klass.is_subtype_of(overridden_frame.qname())
):
return
@@ -1178,7 +1179,7 @@ a metaclass class method.",
if node.name in ancestor.instance_attrs and is_attr_private(node.name):
return
for obj in ancestor.lookup(node.name)[1]:
- if isinstance(obj, astroid.FunctionDef):
+ if isinstance(obj, nodes.FunctionDef):
return
args = (overridden.root().name, overridden.fromlineno)
self.add_message("method-hidden", args=args, node=node)
@@ -1213,15 +1214,15 @@ a metaclass class method.",
return
statement = body[0]
- if not isinstance(statement, (astroid.Expr, astroid.Return)):
+ if not isinstance(statement, (nodes.Expr, nodes.Return)):
# Doing something else than what we are interested into.
return
call = statement.value
if (
- not isinstance(call, astroid.Call)
+ not isinstance(call, nodes.Call)
# Not a super() attribute access.
- or not isinstance(call.func, astroid.Attribute)
+ or not isinstance(call.func, nodes.Attribute)
):
return
@@ -1261,7 +1262,7 @@ a metaclass class method.",
# This may happen with astroid build from living objects
continue
if (
- not isinstance(meth_node, astroid.FunctionDef)
+ not isinstance(meth_node, nodes.FunctionDef)
# If the method have an ancestor which is not a
# function then it is legitimate to redefine it
or _has_different_parameters_default_value(
@@ -1323,8 +1324,8 @@ a metaclass class method.",
node=function_node,
)
- parent_is_async = isinstance(parent_function_node, astroid.AsyncFunctionDef)
- current_is_async = isinstance(function_node, astroid.AsyncFunctionDef)
+ parent_is_async = isinstance(parent_function_node, nodes.AsyncFunctionDef)
+ current_is_async = isinstance(function_node, nodes.AsyncFunctionDef)
if parent_is_async and not current_is_async:
self.add_message(
@@ -1351,7 +1352,7 @@ a metaclass class method.",
self.add_message("invalid-slots", node=node)
continue
- if isinstance(slots, astroid.Const):
+ if isinstance(slots, nodes.Const):
# a string, ignore the following checks
self.add_message("single-string-used-for-slots", node=node)
continue
@@ -1359,7 +1360,7 @@ a metaclass class method.",
# we can't obtain the values, maybe a .deque?
continue
- if isinstance(slots, astroid.Dict):
+ if isinstance(slots, nodes.Dict):
values = [item[0] for item in slots.items]
else:
values = slots.itered()
@@ -1375,7 +1376,7 @@ a metaclass class method.",
for inferred in elt.infer():
if inferred is astroid.Uninferable:
continue
- if not isinstance(inferred, astroid.Const) or not isinstance(
+ if not isinstance(inferred, nodes.Const) or not isinstance(
inferred.value, str
):
self.add_message(
@@ -1393,7 +1394,7 @@ a metaclass class method.",
# Skip annotated assignments which don't conflict at all with slots.
if len(class_variable) == 1:
parent = class_variable[0].parent
- if isinstance(parent, astroid.AnnAssign) and parent.value is None:
+ if isinstance(parent, nodes.AnnAssign) and parent.value is None:
return
self.add_message(
"class-variable-slots-conflict", args=(inferred.value,), node=elt
@@ -1442,19 +1443,19 @@ a metaclass class method.",
self._check_protected_attribute_access(node)
@check_messages("assigning-non-slot", "invalid-class-object")
- def visit_assignattr(self, node: astroid.AssignAttr) -> None:
+ def visit_assignattr(self, node: nodes.AssignAttr) -> None:
if isinstance(
- node.assign_type(), astroid.AugAssign
+ node.assign_type(), nodes.AugAssign
) and self._uses_mandatory_method_param(node):
self._accessed.set_accessed(node)
self._check_in_slots(node)
self._check_invalid_class_object(node)
- def _check_invalid_class_object(self, node: astroid.AssignAttr) -> None:
+ def _check_invalid_class_object(self, node: nodes.AssignAttr) -> None:
if not node.attrname == "__class__":
return
inferred = safe_infer(node.parent.value)
- if isinstance(inferred, astroid.ClassDef) or inferred is astroid.Uninferable:
+ if isinstance(inferred, nodes.ClassDef) or inferred is astroid.Uninferable:
# If is uninferrable, we allow it to prevent false positives
return
self.add_message("invalid-class-object", node=node)
@@ -1516,7 +1517,7 @@ a metaclass class method.",
def visit_assign(self, assign_node):
self._check_classmethod_declaration(assign_node)
node = assign_node.targets[0]
- if not isinstance(node, astroid.AssignAttr):
+ if not isinstance(node, nodes.AssignAttr):
return
if self._uses_mandatory_method_param(node):
@@ -1532,12 +1533,12 @@ a metaclass class method.",
is defined.
`node` is an assign node.
"""
- if not isinstance(node.value, astroid.Call):
+ if not isinstance(node.value, nodes.Call):
return
# check the function called is "classmethod" or "staticmethod"
func = node.value.func
- if not isinstance(func, astroid.Name) or func.name not in (
+ if not isinstance(func, nodes.Name) or func.name not in (
"classmethod",
"staticmethod",
):
@@ -1550,12 +1551,12 @@ a metaclass class method.",
)
# assignment must be at a class scope
parent_class = node.scope()
- if not isinstance(parent_class, astroid.ClassDef):
+ if not isinstance(parent_class, nodes.ClassDef):
return
# Check if the arg passed to classmethod is a class member
classmeth_arg = node.value.args[0]
- if not isinstance(classmeth_arg, astroid.Name):
+ if not isinstance(classmeth_arg, nodes.Name):
return
method_name = classmeth_arg.name
@@ -1592,8 +1593,8 @@ a metaclass class method.",
# If the expression begins with a call to super, that's ok.
if (
- isinstance(node.expr, astroid.Call)
- and isinstance(node.expr.func, astroid.Name)
+ isinstance(node.expr, nodes.Call)
+ and isinstance(node.expr.func, nodes.Name)
and node.expr.func.name == "super"
):
return
@@ -1613,9 +1614,9 @@ a metaclass class method.",
stmt = node.parent.statement()
if (
- isinstance(stmt, astroid.Assign)
+ isinstance(stmt, nodes.Assign)
and len(stmt.targets) == 1
- and isinstance(stmt.targets[0], astroid.AssignName)
+ and isinstance(stmt.targets[0], nodes.AssignName)
):
name = stmt.targets[0].name
if _is_attribute_property(name, klass):
@@ -1639,7 +1640,7 @@ a metaclass class method.",
self.add_message("protected-access", node=node, args=attrname)
@staticmethod
- def _is_called_inside_special_method(node: astroid.node_classes.NodeNG) -> bool:
+ def _is_called_inside_special_method(node: nodes.NodeNG) -> bool:
"""
Returns true if the node is located inside a special (aka dunder) method
"""
@@ -1651,8 +1652,8 @@ a metaclass class method.",
def _is_type_self_call(self, expr):
return (
- isinstance(expr, astroid.Call)
- and isinstance(expr.func, astroid.Name)
+ isinstance(expr, nodes.Call)
+ and isinstance(expr.func, nodes.Name)
and expr.func.name == "type"
and len(expr.args) == 1
and self._is_mandatory_method_param(expr.args[0])
@@ -1662,7 +1663,7 @@ a metaclass class method.",
def _is_classmethod(func):
"""Check if the given *func* node is a class method."""
- return isinstance(func, astroid.FunctionDef) and (
+ return isinstance(func, nodes.FunctionDef) and (
func.type == "classmethod" or func.name == "__class_getitem__"
)
@@ -1708,7 +1709,7 @@ a metaclass class method.",
def _check_accessed_members(self, node, accessed):
"""check that accessed members are defined"""
excs = ("AttributeError", "Exception", "BaseException")
- for attr, nodes in accessed.items():
+ for attr, nodes_lst in accessed.items():
try:
# is it a class attribute ?
node.local_attr(attr)
@@ -1730,7 +1731,7 @@ a metaclass class method.",
pass
else:
# filter out augment assignment nodes
- defstmts = [stmt for stmt in defstmts if stmt not in nodes]
+ defstmts = [stmt for stmt in defstmts if stmt not in nodes_lst]
if not defstmts:
# only augment assignment for this node, no-member should be
# triggered by the typecheck checker
@@ -1751,7 +1752,7 @@ a metaclass class method.",
# it's defined, it's accessed after the initial assignment
frame = defstmt.frame()
lno = defstmt.fromlineno
- for _node in nodes:
+ for _node in nodes_lst:
if (
_node.frame() is frame
and _node.fromlineno < lno
@@ -1881,14 +1882,14 @@ a metaclass class method.",
klass_node = node.parent.frame()
to_call = _ancestors_to_call(klass_node)
not_called_yet = dict(to_call)
- for stmt in node.nodes_of_class(astroid.Call):
+ for stmt in node.nodes_of_class(nodes.Call):
expr = stmt.func
- if not isinstance(expr, astroid.Attribute) or expr.attrname != "__init__":
+ if not isinstance(expr, nodes.Attribute) or expr.attrname != "__init__":
continue
# skip the test if using super
if (
- isinstance(expr.expr, astroid.Call)
- and isinstance(expr.expr.func, astroid.Name)
+ isinstance(expr.expr, nodes.Call)
+ and isinstance(expr.expr.func, nodes.Name)
and expr.expr.func.name == "super"
):
return
@@ -1905,7 +1906,7 @@ a metaclass class method.",
if (
isinstance(klass, astroid.Instance)
- and isinstance(klass._proxied, astroid.ClassDef)
+ and isinstance(klass._proxied, nodes.ClassDef)
and is_builtin_object(klass._proxied)
and klass._proxied.name == "super"
):
@@ -1932,8 +1933,8 @@ a metaclass class method.",
def _check_signature(self, method1, refmethod, class_type, cls):
"""check that the signature of the two given methods match"""
if not (
- isinstance(method1, astroid.FunctionDef)
- and isinstance(refmethod, astroid.FunctionDef)
+ isinstance(method1, nodes.FunctionDef)
+ and isinstance(refmethod, nodes.FunctionDef)
):
self.add_message(
"method-check-failed", args=(method1, refmethod), node=method1
@@ -2015,13 +2016,13 @@ a metaclass class method.",
return self._is_mandatory_method_param(node.expr)
def _is_mandatory_method_param(self, node):
- """Check if astroid.Name corresponds to first attribute variable name
+ """Check if nodes.Name corresponds to first attribute variable name
Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.
"""
return (
self._first_attrs
- and isinstance(node, astroid.Name)
+ and isinstance(node, nodes.Name)
and node.name == self._first_attrs[-1]
)
@@ -2215,7 +2216,7 @@ class SpecialMethodsChecker(BaseChecker):
return (
isinstance(node, astroid.Instance)
and node.name == type_
- and not isinstance(node, astroid.Const)
+ and not isinstance(node, nodes.Const)
)
@staticmethod
@@ -2223,42 +2224,42 @@ class SpecialMethodsChecker(BaseChecker):
if SpecialMethodsChecker._is_wrapped_type(node, "int"):
return True
- return isinstance(node, astroid.Const) and isinstance(node.value, int)
+ return isinstance(node, nodes.Const) and isinstance(node.value, int)
@staticmethod
def _is_str(node):
if SpecialMethodsChecker._is_wrapped_type(node, "str"):
return True
- return isinstance(node, astroid.Const) and isinstance(node.value, str)
+ return isinstance(node, nodes.Const) and isinstance(node.value, str)
@staticmethod
def _is_bool(node):
if SpecialMethodsChecker._is_wrapped_type(node, "bool"):
return True
- return isinstance(node, astroid.Const) and isinstance(node.value, bool)
+ return isinstance(node, nodes.Const) and isinstance(node.value, bool)
@staticmethod
def _is_bytes(node):
if SpecialMethodsChecker._is_wrapped_type(node, "bytes"):
return True
- return isinstance(node, astroid.Const) and isinstance(node.value, bytes)
+ return isinstance(node, nodes.Const) and isinstance(node.value, bytes)
@staticmethod
def _is_tuple(node):
if SpecialMethodsChecker._is_wrapped_type(node, "tuple"):
return True
- return isinstance(node, astroid.Const) and isinstance(node.value, tuple)
+ return isinstance(node, nodes.Const) and isinstance(node.value, tuple)
@staticmethod
def _is_dict(node):
if SpecialMethodsChecker._is_wrapped_type(node, "dict"):
return True
- return isinstance(node, astroid.Const) and isinstance(node.value, dict)
+ return isinstance(node, nodes.Const) and isinstance(node.value, dict)
@staticmethod
def _is_iterator(node):
@@ -2275,9 +2276,9 @@ class SpecialMethodsChecker(BaseChecker):
return True
except astroid.NotFoundError:
pass
- elif isinstance(node, astroid.ClassDef):
+ elif isinstance(node, nodes.ClassDef):
metaclass = node.metaclass()
- if metaclass and isinstance(metaclass, astroid.ClassDef):
+ if metaclass and isinstance(metaclass, nodes.ClassDef):
try:
metaclass.local_attr(NEXT_METHOD)
return True
@@ -2292,7 +2293,7 @@ class SpecialMethodsChecker(BaseChecker):
def _check_len(self, node, inferred):
if not self._is_int(inferred):
self.add_message("invalid-length-returned", node=node)
- elif isinstance(inferred, astroid.Const) and inferred.value < 0:
+ elif isinstance(inferred, nodes.Const) and inferred.value < 0:
self.add_message("invalid-length-returned", node=node)
def _check_bool(self, node, inferred):
@@ -2322,7 +2323,7 @@ class SpecialMethodsChecker(BaseChecker):
def _check_length_hint(self, node, inferred):
if not self._is_int(inferred):
self.add_message("invalid-length-hint-returned", node=node)
- elif isinstance(inferred, astroid.Const) and inferred.value < 0:
+ elif isinstance(inferred, nodes.Const) and inferred.value < 0:
self.add_message("invalid-length-hint-returned", node=node)
def _check_format(self, node, inferred):
@@ -2338,7 +2339,7 @@ class SpecialMethodsChecker(BaseChecker):
self.add_message("invalid-getnewargs-ex-returned", node=node)
return
- if not isinstance(inferred, astroid.Tuple):
+ if not isinstance(inferred, nodes.Tuple):
# If it's not an astroid.Tuple we can't analyze it further
return
@@ -2352,7 +2353,7 @@ class SpecialMethodsChecker(BaseChecker):
(inferred.elts[1], self._is_dict),
):
- if isinstance(arg, astroid.Call):
+ if isinstance(arg, nodes.Call):
arg = safe_infer(arg)
if arg and arg is not astroid.Uninferable: