Skip to content

Upgrade astroid to 3.0.0a6 #8822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def visit_call(self, node: nodes.Call) -> None:
and node.func.attrname == "create"
):
return
in_class = node.frame(future=True)
in_class = node.frame()
for param in node.args:
in_class.locals[param.name] = node

Expand Down
4 changes: 2 additions & 2 deletions pylint/checkers/base/basic_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _name_holds_generator(test: nodes.Name) -> tuple[bool, nodes.Call | None]:
assert isinstance(test, nodes.Name)
emit = False
maybe_generator_call = None
lookup_result = test.frame(future=True).lookup(test.name)
lookup_result = test.frame().lookup(test.name)
if not lookup_result:
return emit, maybe_generator_call
maybe_generator_assigned = (
Expand Down Expand Up @@ -717,7 +717,7 @@ def visit_call(self, node: nodes.Call) -> None:
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(future=True) or name in node.root()):
if not (name in node.frame() or name in node.root()):
if name == "exec":
self.add_message("exec-used", node=node)
elif name == "reversed":
Expand Down
8 changes: 4 additions & 4 deletions pylint/checkers/base/basic_error_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def visit_starred(self, node: nodes.Starred) -> None:
# PEP 448 unpacking.
return

stmt = node.statement(future=True)
stmt = node.statement()
if not isinstance(stmt, nodes.Assign):
return

Expand Down Expand Up @@ -356,7 +356,7 @@ def same_scope(current: nodes.Global | nodes.Nonlocal) -> bool:

@utils.only_required_for_messages("return-outside-function")
def visit_return(self, node: nodes.Return) -> None:
if not isinstance(node.frame(future=True), nodes.FunctionDef):
if not isinstance(node.frame(), nodes.FunctionDef):
self.add_message("return-outside-function", node=node)

@utils.only_required_for_messages("yield-outside-function")
Expand Down Expand Up @@ -469,7 +469,7 @@ def _check_inferred_class_is_abstract(
)

def _check_yield_outside_func(self, node: nodes.Yield) -> None:
if not isinstance(node.frame(future=True), (nodes.FunctionDef, nodes.Lambda)):
if not isinstance(node.frame(), (nodes.FunctionDef, nodes.Lambda)):
self.add_message("yield-outside-function", node=node)

def _check_else_on_loop(self, node: nodes.For | nodes.While) -> None:
Expand Down Expand Up @@ -509,7 +509,7 @@ def _check_redefinition(
self, redeftype: str, node: nodes.Call | nodes.FunctionDef
) -> None:
"""Check for redefinition of a function / method / class name."""
parent_frame = node.parent.frame(future=True)
parent_frame = node.parent.frame()

# Ignore function stubs created for type information
redefinitions = [
Expand Down
8 changes: 4 additions & 4 deletions pylint/checkers/base/docstring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
):
return

if isinstance(node.parent.frame(future=True), nodes.ClassDef):
if isinstance(node.parent.frame(), nodes.ClassDef):
overridden = False
confidence = (
interfaces.INFERENCE
if utils.has_known_bases(node.parent.frame(future=True))
if utils.has_known_bases(node.parent.frame())
else interfaces.INFERENCE_FAILURE
)
# check if node is from a method overridden by its ancestor
for ancestor in node.parent.frame(future=True).ancestors():
for ancestor in node.parent.frame().ancestors():
if ancestor.qname() == "builtins.object":
continue
if node.name in ancestor and isinstance(
Expand All @@ -142,7 +142,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
self._check_docstring(
ftype, node, report_missing=not overridden, confidence=confidence # type: ignore[arg-type]
)
elif isinstance(node.parent.frame(future=True), nodes.Module):
elif isinstance(node.parent.frame(), nodes.Module):
self._check_docstring(ftype, node) # type: ignore[arg-type]
else:
return
Expand Down
6 changes: 3 additions & 3 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
# of a base class method.
confidence = interfaces.HIGH
if node.is_method():
if utils.overrides_a_method(node.parent.frame(future=True), node.name):
if utils.overrides_a_method(node.parent.frame(), node.name):
return
confidence = (
interfaces.INFERENCE
if utils.has_known_bases(node.parent.frame(future=True))
if utils.has_known_bases(node.parent.frame())
else interfaces.INFERENCE_FAILURE
)

Expand Down Expand Up @@ -402,7 +402,7 @@ def visit_assignname( # pylint: disable=too-many-branches
self, node: nodes.AssignName
) -> None:
"""Check module level assigned names."""
frame = node.frame(future=True)
frame = node.frame()
assign_type = node.assign_type()

# Check names defined in comprehensions
Expand Down
36 changes: 17 additions & 19 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,17 +1165,15 @@ def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
nodes_lst = [
n
for n in nodes_lst
if not isinstance(
n.statement(future=True), (nodes.Delete, nodes.AugAssign)
)
if not isinstance(n.statement(), (nodes.Delete, nodes.AugAssign))
and n.root() is current_module
]
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(future=True) for node in nodes_lst)
frames = (node.frame() for node in nodes_lst)
if any(
frame.name in defining_methods or is_property_setter(frame)
for frame in frames
Expand All @@ -1187,7 +1185,7 @@ def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
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(future=True).name in defining_methods:
if node.frame().name in defining_methods:
attr_defined = True
if attr_defined:
# we're done :)
Expand All @@ -1198,12 +1196,12 @@ def _check_attribute_defined_outside_init(self, cnode: nodes.ClassDef) -> None:
cnode.local_attr(attr)
except astroid.NotFoundError:
for node in nodes_lst:
if node.frame(future=True).name not in defining_methods:
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
# the warning.
if _called_in_methods(
node.frame(future=True), cnode, defining_methods
node.frame(), cnode, defining_methods
):
continue
self.add_message(
Expand All @@ -1221,7 +1219,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
self._check_property_with_parameters(node)

# 'is_method()' is called and makes sure that this is a 'nodes.ClassDef'
klass: nodes.ClassDef = node.parent.frame(future=True)
klass: nodes.ClassDef = node.parent.frame()
# check first argument is self if this is actually a method
self._check_first_arg_for_type(node, klass.type == "metaclass")
if node.name == "__init__":
Expand Down Expand Up @@ -1286,12 +1284,12 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
# pylint: disable = too-many-try-statements
try:
overridden = klass.instance_attr(node.name)[0]
overridden_frame = overridden.frame(future=True)
overridden_frame = overridden.frame()
if (
isinstance(overridden_frame, nodes.FunctionDef)
and overridden_frame.type == "method"
):
overridden_frame = overridden_frame.parent.frame(future=True)
overridden_frame = overridden_frame.parent.frame()
if not (
isinstance(overridden_frame, nodes.ClassDef)
and klass.is_subtype_of(overridden_frame.qname())
Expand Down Expand Up @@ -1336,7 +1334,7 @@ def _check_useless_super_delegation(self, function: nodes.FunctionDef) -> None:
return

# Check values of default args
klass = function.parent.frame(future=True)
klass = function.parent.frame()
meth_node = None
for overridden in klass.local_attr_ancestors(function.name):
# get astroid for the searched method
Expand Down Expand Up @@ -1719,7 +1717,7 @@ def _check_in_slots(self, node: nodes.AssignAttr) -> None:
return
if node.attrname in klass.locals:
for local_name in klass.locals.get(node.attrname):
statement = local_name.statement(future=True)
statement = local_name.statement()
if (
isinstance(statement, nodes.AnnAssign)
and not statement.value
Expand Down Expand Up @@ -1871,7 +1869,7 @@ def _check_protected_attribute_access(
# class A:
# b = property(lambda: self._b)

stmt = node.parent.statement(future=True)
stmt = node.parent.statement()
if (
isinstance(stmt, nodes.Assign)
and len(stmt.targets) == 1
Expand All @@ -1882,7 +1880,7 @@ def _check_protected_attribute_access(
return

if (
self._is_classmethod(node.frame(future=True))
self._is_classmethod(node.frame())
and self._is_inferred_instance(node.expr, klass)
and self._is_class_or_instance_attribute(attrname, klass)
):
Expand All @@ -1901,7 +1899,7 @@ def _check_protected_attribute_access(
@staticmethod
def _is_called_inside_special_method(node: nodes.NodeNG) -> bool:
"""Returns true if the node is located inside a special (aka dunder) method."""
frame_name = node.frame(future=True).name
frame_name = node.frame().name
return frame_name and frame_name in PYMETHODS

def _is_type_self_call(self, expr: nodes.NodeNG) -> bool:
Expand Down Expand Up @@ -1994,14 +1992,14 @@ def _check_accessed_members(
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(future=True)
frame = defstmt.frame()
lno = defstmt.fromlineno
for _node in nodes_lst:
if (
_node.frame(future=True) is frame
_node.frame() is frame
and _node.fromlineno < lno
and not astroid.are_exclusive(
_node.statement(future=True), defstmt, excs
_node.statement(), defstmt, excs
)
):
self.add_message(
Expand Down Expand Up @@ -2121,7 +2119,7 @@ def is_abstract(method: nodes.FunctionDef) -> bool:
key=lambda item: item[0],
)
for name, method in methods:
owner = method.parent.frame(future=True)
owner = method.parent.frame()
if owner is node:
continue
# owner is not this class, it must be a parent class
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def visit_default(self, node: nodes.NodeNG) -> None:
elif isinstance(node.parent, nodes.Module):
prev_line = 0
else:
prev_line = node.parent.statement(future=True).fromlineno
prev_line = node.parent.statement().fromlineno
line = node.fromlineno
assert line, node
if prev_line == line and self._visited_lines.get(line) != 2:
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ def _check_reimport(
) and not self.linter.is_message_enabled("shadowed-import"):
return

frame = node.frame(future=True)
frame = node.frame()
root = node.root()
contexts = [(frame, level)]
if root is not frame:
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/newstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
# ignore actual functions or method within a new style class
if not node.is_method():
return
klass = node.parent.frame(future=True)
klass = node.parent.frame()
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.
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/refactoring/not_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def visit_unaryop(self, node: nodes.UnaryOp) -> None:
if operator not in self.reverse_op:
return
# Ignore __ne__ as function of __eq__
frame = node.frame(future=True)
frame = node.frame()
if frame.name == "__ne__" and operator == "==":
return
for _type in (utils.node_type(left), utils.node_type(right)):
Expand Down
16 changes: 7 additions & 9 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_curline_index_start() -> int:


def _is_inside_context_manager(node: nodes.Call) -> bool:
frame = node.frame(future=True)
frame = node.frame()
if not isinstance(
frame, (nodes.FunctionDef, astroid.BoundMethod, astroid.UnboundMethod)
):
Expand All @@ -135,7 +135,7 @@ def _is_inside_context_manager(node: nodes.Call) -> bool:


def _is_a_return_statement(node: nodes.Call) -> bool:
frame = node.frame(future=True)
frame = node.frame()
for parent in node.node_ancestors():
if parent is frame:
break
Expand All @@ -148,7 +148,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(future=True)
frame = node.frame()
current = node
while current != frame:
if isinstance(current, nodes.With):
Expand Down Expand Up @@ -998,7 +998,7 @@ def visit_raise(self, node: nodes.Raise) -> None:

def _check_stop_iteration_inside_generator(self, node: nodes.Raise) -> None:
"""Check if an exception of type StopIteration is raised inside a generator."""
frame = node.frame(future=True)
frame = node.frame()
if not isinstance(frame, nodes.FunctionDef) or not frame.is_generator():
return
if utils.node_ignores_exception(node, StopIteration):
Expand Down Expand Up @@ -1176,7 +1176,7 @@ def _looks_like_infinite_iterator(param: nodes.NodeNG) -> bool:
isinstance(inferred, nodes.FunctionDef)
and inferred.qname() == "builtins.next"
):
frame = node.frame(future=True)
frame = node.frame()
# The next builtin can only have up to two
# positional arguments and no keyword arguments
has_sentinel_value = len(node.args) > 1
Expand Down Expand Up @@ -1579,9 +1579,7 @@ def _append_context_managers_to_stack(self, node: nodes.Assign) -> None:
or not isinstance(assignee, (nodes.AssignName, nodes.AssignAttr))
):
continue
stack = self._consider_using_with_stack.get_stack_for_frame(
node.frame(future=True)
)
stack = self._consider_using_with_stack.get_stack_for_frame(node.frame())
varname = (
assignee.name
if isinstance(assignee, nodes.AssignName)
Expand Down Expand Up @@ -1610,7 +1608,7 @@ def _check_consider_using_with(self, node: nodes.Call) -> None:
if (
node
in self._consider_using_with_stack.get_stack_for_frame(
node.frame(future=True)
node.frame()
).values()
):
# the result of this call was already assigned to a variable and will be
Expand Down
Loading