summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/custom.py2
-rw-r--r--pylint/checkers/base.py22
-rw-r--r--pylint/checkers/classes/class_checker.py30
-rw-r--r--pylint/checkers/format.py2
-rw-r--r--pylint/checkers/imports.py2
-rw-r--r--pylint/checkers/newstyle.py2
-rw-r--r--pylint/checkers/refactoring/not_checker.py2
-rw-r--r--pylint/checkers/refactoring/refactoring_checker.py16
-rw-r--r--pylint/checkers/utils.py8
-rw-r--r--pylint/checkers/variables.py25
-rw-r--r--pylint/extensions/_check_docs_utils.py2
-rw-r--r--pylint/extensions/bad_builtin.py2
-rw-r--r--pylint/extensions/docparams.py6
-rw-r--r--pylint/pyreverse/inspector.py6
-rw-r--r--pylint/utils/utils.py4
15 files changed, 66 insertions, 65 deletions
diff --git a/examples/custom.py b/examples/custom.py
index d4376fc4e..d7757dc78 100644
--- a/examples/custom.py
+++ b/examples/custom.py
@@ -61,7 +61,7 @@ class MyAstroidChecker(BaseChecker):
and node.func.attrname == "create"
):
return
- in_class = node.frame()
+ in_class = node.frame(future=True)
for param in node.args:
in_class.locals[param.name] = node
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 2f79f852e..febc7026b 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -719,7 +719,7 @@ class BasicErrorChecker(_BasicChecker):
@utils.check_messages("return-outside-function")
def visit_return(self, node: nodes.Return) -> None:
- if not isinstance(node.frame(), nodes.FunctionDef):
+ if not isinstance(node.frame(future=True), nodes.FunctionDef):
self.add_message("return-outside-function", node=node)
@utils.check_messages("yield-outside-function")
@@ -827,7 +827,7 @@ class BasicErrorChecker(_BasicChecker):
)
def _check_yield_outside_func(self, node):
- if not isinstance(node.frame(), (nodes.FunctionDef, nodes.Lambda)):
+ if not isinstance(node.frame(future=True), (nodes.FunctionDef, nodes.Lambda)):
self.add_message("yield-outside-function", node=node)
def _check_else_on_loop(self, node):
@@ -862,7 +862,7 @@ class BasicErrorChecker(_BasicChecker):
def _check_redefinition(self, redeftype, node):
"""check for redefinition of a function / method / class name"""
- parent_frame = node.parent.frame()
+ parent_frame = node.parent.frame(future=True)
# Ignore function stubs created for type information
redefinitions = [
@@ -1426,7 +1426,7 @@ class BasicChecker(_BasicChecker):
name = node.func.name
# ignore the name if it's not a builtin (i.e. not defined in the
# locals nor globals scope)
- if not (name in node.frame() or name in node.root()):
+ if not (name in node.frame(future=True) or name in node.root()):
if name == "exec":
self.add_message("exec-used", node=node)
elif name == "reversed":
@@ -1913,11 +1913,11 @@ class NameChecker(_BasicChecker):
self._check_assign_to_new_keyword_violation(node.name, node)
confidence = interfaces.HIGH
if node.is_method():
- if utils.overrides_a_method(node.parent.frame(), node.name):
+ if utils.overrides_a_method(node.parent.frame(future=True), node.name):
return
confidence = (
interfaces.INFERENCE
- if utils.has_known_bases(node.parent.frame())
+ if utils.has_known_bases(node.parent.frame(future=True))
else interfaces.INFERENCE_FAILURE
)
@@ -1943,7 +1943,7 @@ class NameChecker(_BasicChecker):
def visit_assignname(self, node: nodes.AssignName) -> None:
"""check module level assigned names"""
self._check_assign_to_new_keyword_violation(node.name, node)
- frame = node.frame()
+ frame = node.frame(future=True)
assign_type = node.assign_type()
if isinstance(assign_type, nodes.Comprehension):
self._check_name("inlinevar", node.name, node)
@@ -2156,15 +2156,15 @@ class DocStringChecker(_BasicChecker):
):
return
- if isinstance(node.parent.frame(), nodes.ClassDef):
+ if isinstance(node.parent.frame(future=True), nodes.ClassDef):
overridden = False
confidence = (
interfaces.INFERENCE
- if utils.has_known_bases(node.parent.frame())
+ if utils.has_known_bases(node.parent.frame(future=True))
else interfaces.INFERENCE_FAILURE
)
# check if node is from a method overridden by its ancestor
- for ancestor in node.parent.frame().ancestors():
+ for ancestor in node.parent.frame(future=True).ancestors():
if ancestor.qname() == "builtins.object":
continue
if node.name in ancestor and isinstance(
@@ -2175,7 +2175,7 @@ class DocStringChecker(_BasicChecker):
self._check_docstring(
ftype, node, report_missing=not overridden, confidence=confidence # type: ignore[arg-type]
)
- elif isinstance(node.parent.frame(), nodes.Module):
+ elif isinstance(node.parent.frame(future=True), nodes.Module):
self._check_docstring(ftype, node) # type: ignore[arg-type]
else:
return
diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py
index 452d57c1b..aaa5de0cb 100644
--- a/pylint/checkers/classes/class_checker.py
+++ b/pylint/checkers/classes/class_checker.py
@@ -1033,7 +1033,7 @@ a metaclass class method.",
# 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_lst)
+ frames = (node.frame(future=True) for node in nodes_lst)
if any(
frame.name in defining_methods or is_property_setter(frame)
for frame in frames
@@ -1045,7 +1045,7 @@ a metaclass class method.",
attr_defined = False
# check if any parent method attr is defined in is a defining method
for node in parent.instance_attrs[attr]:
- if node.frame().name in defining_methods:
+ if node.frame(future=True).name in defining_methods:
attr_defined = True
if attr_defined:
# we're done :)
@@ -1056,12 +1056,12 @@ a metaclass class method.",
cnode.local_attr(attr)
except astroid.NotFoundError:
for node in nodes_lst:
- if node.frame().name not in defining_methods:
+ if node.frame(future=True).name not in defining_methods:
# If the attribute was set by a call in any
# of the defining methods, then don't emit
# the warning.
if _called_in_methods(
- node.frame(), cnode, defining_methods
+ node.frame(future=True), cnode, defining_methods
):
continue
self.add_message(
@@ -1077,7 +1077,7 @@ a metaclass class method.",
self._check_useless_super_delegation(node)
self._check_property_with_parameters(node)
- klass = node.parent.frame()
+ klass = node.parent.frame(future=True)
self._meth_could_be_func = True
# check first argument is self if this is actually a method
self._check_first_arg_for_type(node, klass.type == "metaclass")
@@ -1138,12 +1138,12 @@ a metaclass class method.",
# check if the method is hidden by an attribute
try:
overridden = klass.instance_attr(node.name)[0]
- overridden_frame = overridden.frame()
+ overridden_frame = overridden.frame(future=True)
if (
isinstance(overridden_frame, nodes.FunctionDef)
and overridden_frame.type == "method"
):
- overridden_frame = overridden_frame.parent.frame()
+ overridden_frame = overridden_frame.parent.frame(future=True)
if not (
isinstance(overridden_frame, nodes.ClassDef)
and klass.is_subtype_of(overridden_frame.qname())
@@ -1226,7 +1226,7 @@ a metaclass class method.",
return
# Check values of default args
- klass = function.parent.frame()
+ klass = function.parent.frame(future=True)
meth_node = None
for overridden in klass.local_attr_ancestors(function.name):
# get astroid for the searched method
@@ -1396,7 +1396,7 @@ a metaclass class method.",
self._first_attrs.pop()
if not self.linter.is_message_enabled("no-self-use"):
return
- class_node = node.parent.frame()
+ class_node = node.parent.frame(future=True)
if (
self._meth_could_be_func
and node.type == "method"
@@ -1641,7 +1641,7 @@ a metaclass class method.",
return
if (
- self._is_classmethod(node.frame())
+ self._is_classmethod(node.frame(future=True))
and self._is_inferred_instance(node.expr, klass)
and self._is_class_attribute(attrname, klass)
):
@@ -1661,7 +1661,7 @@ a metaclass class method.",
def _is_called_inside_special_method(node: nodes.NodeNG) -> bool:
"""Returns true if the node is located inside a special (aka dunder) method"""
try:
- frame_name = node.frame().name
+ frame_name = node.frame(future=True).name
except AttributeError:
return False
return frame_name and frame_name in PYMETHODS
@@ -1766,11 +1766,11 @@ a metaclass class method.",
defstmt = defstmts[0]
# check that if the node is accessed in the same method as
# it's defined, it's accessed after the initial assignment
- frame = defstmt.frame()
+ frame = defstmt.frame(future=True)
lno = defstmt.fromlineno
for _node in nodes_lst:
if (
- _node.frame() is frame
+ _node.frame(future=True) is frame
and _node.fromlineno < lno
and not astroid.are_exclusive(
_node.statement(future=True), defstmt, excs
@@ -1875,7 +1875,7 @@ a metaclass class method.",
key=lambda item: item[0],
)
for name, method in methods:
- owner = method.parent.frame()
+ owner = method.parent.frame(future=True)
if owner is node:
continue
# owner is not this class, it must be a parent class
@@ -1893,7 +1893,7 @@ a metaclass class method.",
"super-init-not-called"
) and not self.linter.is_message_enabled("non-parent-init-called"):
return
- klass_node = node.parent.frame()
+ klass_node = node.parent.frame(future=True)
to_call = _ancestors_to_call(klass_node)
not_called_yet = dict(to_call)
for stmt in node.nodes_of_class(nodes.Call):
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py
index f38944ded..4f5f01e55 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -661,7 +661,7 @@ class FormatChecker(BaseTokenChecker):
and isinstance(node.value, nodes.Const)
and node.value.value is Ellipsis
):
- frame = node.frame()
+ frame = node.frame(future=True)
if is_overload_stub(frame) or is_protocol_class(node_frame_class(frame)):
return
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index 528f7d80c..b0daf4bd6 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -910,7 +910,7 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
if not self.linter.is_message_enabled("reimported"):
return
- frame = node.frame()
+ frame = node.frame(future=True)
root = node.root()
contexts = [(frame, level)]
if root is not frame:
diff --git a/pylint/checkers/newstyle.py b/pylint/checkers/newstyle.py
index 45b4409d8..143550909 100644
--- a/pylint/checkers/newstyle.py
+++ b/pylint/checkers/newstyle.py
@@ -66,7 +66,7 @@ class NewStyleConflictChecker(BaseChecker):
# ignore actual functions or method within a new style class
if not node.is_method():
return
- klass = node.parent.frame()
+ klass = node.parent.frame(future=True)
for stmt in node.nodes_of_class(nodes.Call):
if node_frame_class(stmt) != node_frame_class(node):
# Don't look down in other scopes.
diff --git a/pylint/checkers/refactoring/not_checker.py b/pylint/checkers/refactoring/not_checker.py
index f8c670e96..ec29dfb8e 100644
--- a/pylint/checkers/refactoring/not_checker.py
+++ b/pylint/checkers/refactoring/not_checker.py
@@ -62,7 +62,7 @@ class NotChecker(checkers.BaseChecker):
if operator not in self.reverse_op:
return
# Ignore __ne__ as function of __eq__
- frame = node.frame()
+ frame = node.frame(future=True)
if frame.name == "__ne__" and operator == "==":
return
for _type in (utils.node_type(left), utils.node_type(right)):
diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py
index a18257456..2387595d3 100644
--- a/pylint/checkers/refactoring/refactoring_checker.py
+++ b/pylint/checkers/refactoring/refactoring_checker.py
@@ -97,7 +97,7 @@ def _is_trailing_comma(tokens: List[tokenize.TokenInfo], index: int) -> bool:
def _is_inside_context_manager(node: nodes.Call) -> bool:
- frame = node.frame()
+ frame = node.frame(future=True)
if not isinstance(
frame, (nodes.FunctionDef, astroid.BoundMethod, astroid.UnboundMethod)
):
@@ -108,7 +108,7 @@ def _is_inside_context_manager(node: nodes.Call) -> bool:
def _is_a_return_statement(node: nodes.Call) -> bool:
- frame = node.frame()
+ frame = node.frame(future=True)
for parent in node.node_ancestors():
if parent is frame:
break
@@ -121,7 +121,7 @@ def _is_part_of_with_items(node: nodes.Call) -> bool:
"""Checks if one of the node's parents is a ``nodes.With`` node and that the node itself is located
somewhere under its ``items``.
"""
- frame = node.frame()
+ frame = node.frame(future=True)
current = node
while current != frame:
if isinstance(current, nodes.With):
@@ -910,7 +910,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
def _check_stop_iteration_inside_generator(self, node):
"""Check if an exception of type StopIteration is raised inside a generator"""
- frame = node.frame()
+ frame = node.frame(future=True)
if not isinstance(frame, nodes.FunctionDef) or not frame.is_generator():
return
if utils.node_ignores_exception(node, StopIteration):
@@ -1069,7 +1069,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
inferred = utils.safe_infer(node.func)
if getattr(inferred, "name", "") == "next":
- frame = node.frame()
+ frame = node.frame(future=True)
# The next builtin can only have up to two
# positional arguments and no keyword arguments
has_sentinel_value = len(node.args) > 1
@@ -1451,7 +1451,9 @@ class RefactoringChecker(checkers.BaseTokenChecker):
or not isinstance(assignee, (nodes.AssignName, nodes.AssignAttr))
):
continue
- stack = self._consider_using_with_stack.get_stack_for_frame(node.frame())
+ stack = self._consider_using_with_stack.get_stack_for_frame(
+ node.frame(future=True)
+ )
varname = (
assignee.name
if isinstance(assignee, nodes.AssignName)
@@ -1479,7 +1481,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
if (
node
in self._consider_using_with_stack.get_stack_for_frame(
- node.frame()
+ node.frame(future=True)
).values()
):
# the result of this call was already assigned to a variable and will be checked when leaving the scope.
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index b0b15e361..65c7e3102 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -668,7 +668,7 @@ def node_frame_class(node: nodes.NodeNG) -> Optional[nodes.ClassDef]:
The function returns a class for a method node (or a staticmethod or a
classmethod), otherwise it returns `None`.
"""
- klass = node.frame()
+ klass = node.frame(future=True)
nodes_to_check = (
nodes.NodeNG,
astroid.UnboundMethod,
@@ -682,14 +682,14 @@ def node_frame_class(node: nodes.NodeNG) -> Optional[nodes.ClassDef]:
if klass.parent is None:
return None
- klass = klass.parent.frame()
+ klass = klass.parent.frame(future=True)
return klass
def get_outer_class(class_node: astroid.ClassDef) -> Optional[astroid.ClassDef]:
"""Return the class that is the outer class of given (nested) class_node"""
- parent_klass = class_node.parent.frame()
+ parent_klass = class_node.parent.frame(future=True)
return parent_klass if isinstance(parent_klass, astroid.ClassDef) else None
@@ -1086,7 +1086,7 @@ def class_is_abstract(node: nodes.ClassDef) -> bool:
return True
for method in node.methods():
- if method.parent.frame() is node:
+ if method.parent.frame(future=True) is node:
if method.is_abstract(pass_is_abstract=False):
return True
return False
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 5ce58df14..2a94d3ce0 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -1108,7 +1108,7 @@ class VariablesChecker(BaseChecker):
)
def visit_global(self, node: nodes.Global) -> None:
"""check names imported exists in the global scope"""
- frame = node.frame()
+ frame = node.frame(future=True)
if isinstance(frame, nodes.Module):
self.add_message("global-at-module-level", node=node)
return
@@ -1142,7 +1142,7 @@ class VariablesChecker(BaseChecker):
):
self.add_message("redefined-builtin", args=name, node=node)
break
- if anode.frame() is module:
+ if anode.frame(future=True) is module:
# module level assignment
break
if isinstance(anode, nodes.FunctionDef) and anode.parent is module:
@@ -1344,7 +1344,7 @@ class VariablesChecker(BaseChecker):
defnode = utils.assign_parent(found_nodes[0])
defstmt = defnode.statement(future=True)
- defframe = defstmt.frame()
+ defframe = defstmt.frame(future=True)
# The class reuses itself in the class scope.
is_recursive_klass = (
@@ -1669,7 +1669,7 @@ class VariablesChecker(BaseChecker):
# equivalent to frame.statement().scope()
forbid_lookup = (
isinstance(frame, nodes.FunctionDef)
- or isinstance(node.frame(), nodes.Lambda)
+ or isinstance(node.frame(future=True), nodes.Lambda)
) and _assigned_locally(node)
if not forbid_lookup and defframe.root().lookup(node.name)[1]:
maybe_before_assign = False
@@ -1836,8 +1836,8 @@ class VariablesChecker(BaseChecker):
if not isinstance(defstmt, nodes.AnnAssign) or defstmt.value:
return False
- defstmt_frame = defstmt.frame()
- node_frame = node.frame()
+ defstmt_frame = defstmt.frame(future=True)
+ node_frame = node.frame(future=True)
parent = node
while parent is not defstmt_frame.parent:
@@ -1876,10 +1876,9 @@ class VariablesChecker(BaseChecker):
1 = Break
2 = Break + emit message
"""
- if (
- node.frame().parent == defstmt
- and node.statement(future=True) == node.frame()
- ):
+ if node.frame(future=True).parent == defstmt and node.statement(
+ future=True
+ ) == node.frame(future=True):
# Check if used as type annotation
# Break but don't emit message if postponed evaluation is enabled
if utils.is_node_in_type_annotation_context(node):
@@ -2129,7 +2128,7 @@ class VariablesChecker(BaseChecker):
def _check_unused_arguments(self, name, node, stmt, argnames):
is_method = node.is_method()
- klass = node.parent.frame()
+ klass = node.parent.frame(future=True)
if is_method and isinstance(klass, nodes.ClassDef):
confidence = (
INFERENCE if utils.has_known_bases(klass) else INFERENCE_FAILURE
@@ -2180,12 +2179,12 @@ class VariablesChecker(BaseChecker):
if not self.linter.is_message_enabled("cell-var-from-loop"):
return
- node_scope = node.frame()
+ node_scope = node.frame(future=True)
# If node appears in a default argument expression,
# look at the next enclosing frame instead
if utils.is_default_argument(node, node_scope):
- node_scope = node_scope.parent.frame()
+ node_scope = node_scope.parent.frame(future=True)
# Check if node is a cell var
if (
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py
index 2ff86b00b..f6fa34724 100644
--- a/pylint/extensions/_check_docs_utils.py
+++ b/pylint/extensions/_check_docs_utils.py
@@ -155,7 +155,7 @@ def possible_exc_types(node: nodes.NodeNG) -> Set[nodes.ClassDef]:
exceptions = [target]
elif isinstance(target, nodes.FunctionDef):
for ret in target.nodes_of_class(nodes.Return):
- if ret.frame() != target:
+ if ret.frame(future=True) != target:
# return from inner function - ignore it
continue
diff --git a/pylint/extensions/bad_builtin.py b/pylint/extensions/bad_builtin.py
index 197bf231b..bf8072244 100644
--- a/pylint/extensions/bad_builtin.py
+++ b/pylint/extensions/bad_builtin.py
@@ -62,7 +62,7 @@ class BadBuiltinChecker(BaseChecker):
name = node.func.name
# ignore the name if it's not a builtin (i.e. not defined in the
# locals nor globals scope)
- if not (name in node.frame() or name in node.root()):
+ if not (name in node.frame(future=True) or name in node.root()):
if name in self.config.bad_functions:
hint = BUILTIN_HINTS.get(name)
args = f"{name!r}. {hint}" if hint else repr(name)
diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py
index 8d9472fbf..7c18e6b62 100644
--- a/pylint/extensions/docparams.py
+++ b/pylint/extensions/docparams.py
@@ -289,7 +289,7 @@ class DocstringParameterChecker(BaseChecker):
self.add_message("redundant-yields-doc", node=node)
def visit_raise(self, node: nodes.Raise) -> None:
- func_node = node.frame()
+ func_node = node.frame(future=True)
if not isinstance(func_node, astroid.FunctionDef):
return
@@ -336,7 +336,7 @@ class DocstringParameterChecker(BaseChecker):
if self.config.accept_no_return_doc:
return
- func_node = node.frame()
+ func_node = node.frame(future=True)
if not isinstance(func_node, astroid.FunctionDef):
return
@@ -357,7 +357,7 @@ class DocstringParameterChecker(BaseChecker):
if self.config.accept_no_yields_doc:
return
- func_node = node.frame()
+ func_node = node.frame(future=True)
if not isinstance(func_node, astroid.FunctionDef):
return
diff --git a/pylint/pyreverse/inspector.py b/pylint/pyreverse/inspector.py
index 2c7162d7c..d3774389e 100644
--- a/pylint/pyreverse/inspector.py
+++ b/pylint/pyreverse/inspector.py
@@ -49,7 +49,7 @@ def interfaces(node, herited=True, handler_func=_iface_hdlr):
implements = astroid.bases.Instance(node).getattr("__implements__")[0]
except astroid.exceptions.NotFoundError:
return
- if not herited and implements.frame() is not node:
+ if not herited and implements.frame(future=True) is not node:
return
found = set()
missing = False
@@ -222,8 +222,8 @@ class Linker(IdGeneratorMixIn, utils.LocalsVisitor):
if hasattr(node, "_handled"):
return
node._handled = True
- if node.name in node.frame():
- frame = node.frame()
+ if node.name in node.frame(future=True):
+ frame = node.frame(future=True)
else:
# the name has been defined as 'global' in the frame and belongs
# there.
diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py
index e84ffa472..f99690b33 100644
--- a/pylint/utils/utils.py
+++ b/pylint/utils/utils.py
@@ -108,7 +108,7 @@ def diff_string(old, new):
def get_module_and_frameid(node):
"""return the module name and the frame id in the module"""
- frame = node.frame()
+ frame = node.frame(future=True)
module, obj = "", []
while frame:
if isinstance(frame, Module):
@@ -116,7 +116,7 @@ def get_module_and_frameid(node):
else:
obj.append(getattr(frame, "name", "<lambda>"))
try:
- frame = frame.parent.frame()
+ frame = frame.parent.frame(future=True)
except AttributeError:
break
obj.reverse()