Skip to content

Commit

Permalink
Remove uses of future argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 22, 2023
1 parent d0558cb commit 19e0af3
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 79 deletions.
2 changes: 1 addition & 1 deletion astroid/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def infer_argument(
return positional[0].infer(context=context)
if boundnode is None:
# XXX can do better ?
boundnode = funcnode.parent.frame(future=True)
boundnode = funcnode.parent.frame()

if isinstance(boundnode, nodes.ClassDef):
# Verify that we're accessing a method
Expand Down
4 changes: 2 additions & 2 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class UnboundMethod(Proxy):

def __repr__(self) -> str:
assert self._proxied.parent, "Expected a parent node"
frame = self._proxied.parent.frame(future=True)
frame = self._proxied.parent.frame()
return "<{} {} of {} at 0x{}".format(
self.__class__.__name__, self._proxied.name, frame.qname(), id(self)
)
Expand Down Expand Up @@ -472,7 +472,7 @@ def infer_call_result(
# instance of the class given as first argument.
if self._proxied.name == "__new__":
assert self._proxied.parent, "Expected a parent node"
qname = self._proxied.parent.frame(future=True).qname()
qname = self._proxied.parent.frame().qname()
# Avoid checking builtins.type: _infer_type_new_call() does more validation
if qname.startswith("builtins.") and qname != "builtins.type":
return self._infer_builtin_new(caller, context or InferenceContext())
Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def _looks_like_dataclass_field_call(
If check_scope is False, skips checking the statement and body.
"""
if check_scope:
stmt = node.statement(future=True)
stmt = node.statement()
scope = stmt.scope()
if not (
isinstance(stmt, nodes.AnnAssign)
Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_namedtuple_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def infer_enum_class(node: nodes.ClassDef) -> nodes.ClassDef:
if any(not isinstance(value, nodes.AssignName) for value in values):
continue

stmt = values[0].statement(future=True)
stmt = values[0].statement()
if isinstance(stmt, nodes.Assign):
if isinstance(stmt.targets[0], nodes.Tuple):
targets = stmt.targets[0].itered()
Expand Down
4 changes: 2 additions & 2 deletions astroid/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def delayed_assattr(self, node: nodes.AssignAttr) -> None:
from astroid import objects # pylint: disable=import-outside-toplevel

try:
frame = node.frame(future=True)
frame = node.frame()
for inferred in node.expr.infer():
if isinstance(inferred, util.UninferableBase):
continue
Expand Down Expand Up @@ -268,7 +268,7 @@ def delayed_assattr(self, node: nodes.AssignAttr) -> None:
if (
frame.name == "__init__"
and values
and values[0].frame(future=True).name != "__init__"
and values[0].frame().name != "__init__"
):
values.insert(0, node)
else:
Expand Down
10 changes: 3 additions & 7 deletions astroid/filter_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
def _get_filtered_node_statements(
base_node: nodes.NodeNG, stmt_nodes: list[nodes.NodeNG]
) -> list[tuple[nodes.NodeNG, nodes.Statement]]:
statements = [(node, node.statement(future=True)) for node in stmt_nodes]
statements = [(node, node.statement()) for node in stmt_nodes]
# Next we check if we have ExceptHandlers that are parent
# of the underlying variable, in which case the last one survives
if len(statements) > 1 and all(
Expand Down Expand Up @@ -83,16 +83,12 @@ def _filter_stmts(
#
# def test(b=1):
# ...
if (
base_node.parent
and base_node.statement(future=True) is myframe
and myframe.parent
):
if base_node.parent and base_node.statement() is myframe and myframe.parent:
myframe = myframe.parent.frame()

mystmt: nodes.Statement | None = None
if base_node.parent:
mystmt = base_node.statement(future=True)
mystmt = base_node.statement()

# line filtering if we are in the same frame
#
Expand Down
2 changes: 1 addition & 1 deletion astroid/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def object_len(node, context: InferenceContext | None = None):

# prevent self referential length calls from causing a recursion error
# see https://github.com/pylint-dev/astroid/issues/777
node_frame = node.frame(future=True)
node_frame = node.frame()
if (
isinstance(node_frame, scoped_nodes.FunctionDef)
and node_frame.name == "__len__"
Expand Down
2 changes: 1 addition & 1 deletion astroid/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ def infer_functiondef(
# of the wrapping frame. This means that every time we infer a property, the locals
# are mutated with a new instance of the property. To avoid this, we detect this
# scenario and avoid passing the `parent` argument to the constructor.
parent_frame = self.parent.frame(future=True)
parent_frame = self.parent.frame()
property_already_in_parent_locals = self.name in parent_frame.locals and any(
isinstance(val, objects.Property) for val in parent_frame.locals[self.name]
)
Expand Down
4 changes: 2 additions & 2 deletions astroid/nodes/_base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FilterStmtsBaseNode(NodeNG):

def _get_filtered_stmts(self, _, node, _stmts, mystmt: Statement | None):
"""Method used in _filter_stmts to get statements and trigger break."""
if self.statement(future=True) is mystmt:
if self.statement() is mystmt:
# original node's statement is the assignment, only keep
# current node (gen exp, list comp)
return [node], True
Expand All @@ -88,7 +88,7 @@ def _get_filtered_stmts(self, lookup_node, node, _stmts, mystmt: Statement | Non
"""Method used in filter_stmts."""
if self is mystmt:
return _stmts, True
if self.statement(future=True) is mystmt:
if self.statement() is mystmt:
# original node's statement is the assignment, only keep
# current node (gen exp, list comp)
return [node], True
Expand Down
8 changes: 4 additions & 4 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ def _get_filtered_stmts(
if isinstance(lookup_node, (Const, Name)):
return [lookup_node], True

elif self.statement(future=True) is mystmt:
elif self.statement() is mystmt:
# original node's statement is the assignment, only keeps
# current node (gen exp, list comp)

Expand Down Expand Up @@ -3823,9 +3823,9 @@ def frame(
raise ParentMissingError(target=self.parent)
if not self.parent.parent.parent:
raise ParentMissingError(target=self.parent.parent)
return self.parent.parent.parent.frame(future=True)
return self.parent.parent.parent.frame()

return self.parent.frame(future=True)
return self.parent.frame()

def scope(self) -> LocalsDictNodeNG:
"""The first parent node defining a new scope.
Expand Down Expand Up @@ -3857,7 +3857,7 @@ def set_local(self, name: str, stmt: NodeNG) -> None:
:param stmt: The statement that defines the given name.
"""
self.frame(future=True).set_local(name, stmt)
self.frame().set_local(name, stmt)


class Unknown(_base_nodes.AssignTypeNode):
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/node_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def statement(self, *, future: Literal[None, True] = None) -> nodes.Statement:
return cast("nodes.Statement", self)
if not self.parent:
raise StatementMissing(target=self)
return self.parent.statement(future=future)
return self.parent.statement()

def frame(
self, *, future: Literal[None, True] = None
Expand Down
2 changes: 1 addition & 1 deletion astroid/nodes/scoped_nodes/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def qname(self) -> str:
# pylint: disable=no-member; github.com/pylint-dev/astroid/issues/278
if self.parent is None or isinstance(self.parent, node_classes.Unknown):
return self.name
return f"{self.parent.frame(future=True).qname()}.{self.name}"
return f"{self.parent.frame().qname()}.{self.name}"

def scope(self: _T) -> _T:
"""The first parent node defining a new scope.
Expand Down
28 changes: 13 additions & 15 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def scope_lookup(
if (self.args.defaults and node in self.args.defaults) or (
self.args.kw_defaults and node in self.args.kw_defaults
):
frame = self.parent.frame(future=True)
frame = self.parent.frame()
# line offset to avoid that def func(f=func) resolve the default
# value to the defined function
offset = -1
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def __init__(
parent=parent,
)
if parent and not isinstance(parent, Unknown):
frame = parent.frame(future=True)
frame = parent.frame()
frame.set_local(name, self)

def postinit(
Expand Down Expand Up @@ -1161,7 +1161,7 @@ def extra_decorators(self) -> list[node_classes.Call]:
The property will return all the callables that are used for
decoration.
"""
frame = self.parent.frame(future=True)
frame = self.parent.frame()
if not isinstance(frame, ClassDef):
return []

Expand All @@ -1188,7 +1188,7 @@ def extra_decorators(self) -> list[node_classes.Call]:
# original method.
if (
isinstance(meth, FunctionDef)
and assign_node.frame(future=True) == frame
and assign_node.frame() == frame
):
decorators.append(assign.value)
return decorators
Expand Down Expand Up @@ -1259,7 +1259,7 @@ def type(self) -> str: # pylint: disable=too-many-return-statements # noqa: C90
if decorator.func.name in BUILTIN_DESCRIPTORS:
return decorator.func.name

frame = self.parent.frame(future=True)
frame = self.parent.frame()
type_name = "function"
if isinstance(frame, ClassDef):
if self.name == "__new__":
Expand Down Expand Up @@ -1373,9 +1373,7 @@ def is_method(self) -> bool:
"""
# check we are defined in a ClassDef, because this is usually expected
# (e.g. pylint...) when is_method() return True
return self.type != "function" and isinstance(
self.parent.frame(future=True), ClassDef
)
return self.type != "function" and isinstance(self.parent.frame(), ClassDef)

def decoratornames(self, context: InferenceContext | None = None) -> set[str]:
"""Get the qualified names of each of the decorators on this function.
Expand Down Expand Up @@ -1586,14 +1584,14 @@ def scope_lookup(
# if any methods in a class body refer to either __class__ or super.
# In our case, we want to be able to look it up in the current scope
# when `__class__` is being used.
frame = self.parent.frame(future=True)
frame = self.parent.frame()
if isinstance(frame, ClassDef):
return self, [frame]

if (self.args.defaults and node in self.args.defaults) or (
self.args.kw_defaults and node in self.args.kw_defaults
):
frame = self.parent.frame(future=True)
frame = self.parent.frame()
# line offset to avoid that def func(f=func) resolve the default
# value to the defined function
offset = -1
Expand Down Expand Up @@ -1708,12 +1706,12 @@ def get_wrapping_class(node):
:rtype: ClassDef or None
"""

klass = node.frame(future=True)
klass = node.frame()
while klass is not None and not isinstance(klass, ClassDef):
if klass.parent is None:
klass = None
else:
klass = klass.parent.frame(future=True)
klass = klass.parent.frame()
return klass


Expand Down Expand Up @@ -1811,7 +1809,7 @@ def __init__(
parent=parent,
)
if parent and not isinstance(parent, Unknown):
parent.frame(future=True).set_local(name, self)
parent.frame().set_local(name, self)

for local_name, node in self.implicit_locals():
self.add_local_node(node, local_name)
Expand Down Expand Up @@ -2086,7 +2084,7 @@ def scope_lookup(
# class A(name.Name):
# def name(self): ...

frame = self.parent.frame(future=True)
frame = self.parent.frame()
# line offset to avoid that class A(A) resolve the ancestor to
# the defined class
offset = -1
Expand Down Expand Up @@ -2304,7 +2302,7 @@ def getattr(
# Remove AnnAssigns without value, which are not attributes in the purest sense.
for value in values.copy():
if isinstance(value, node_classes.AssignName):
stmt = value.statement(future=True)
stmt = value.statement()
if isinstance(stmt, node_classes.AnnAssign) and stmt.value is None:
values.pop(values.index(value))

Expand Down
4 changes: 2 additions & 2 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def arguments_assigned_stmts(
callee = callee._proxied
else:
return _arguments_infer_argname(self, node_name, context)
if node and getattr(callee, "name", None) == node.frame(future=True).name:
if node and getattr(callee, "name", None) == node.frame().name:
# reset call context/name
callcontext = context.callcontext
context = copy_context(context)
Expand Down Expand Up @@ -755,7 +755,7 @@ def _determine_starred_iteration_lookups(
lookups.append((index, len(element.itered())))
_determine_starred_iteration_lookups(starred, element, lookups)

stmt = self.statement(future=True)
stmt = self.statement()
if not isinstance(stmt, (nodes.Assign, nodes.For)):
raise InferenceError(
"Statement {stmt!r} enclosing {node!r} must be an Assign or For node.",
Expand Down
12 changes: 6 additions & 6 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def test_module_base_props(self) -> None:
self.assertEqual(module.fromlineno, 0)
self.assertIsNone(module.parent)
self.assertEqual(module.frame(), module)
self.assertEqual(module.frame(future=True), module)
self.assertEqual(module.frame(), module)
self.assertEqual(module.root(), module)
self.assertEqual(module.file, os.path.abspath(resources.find("data/module.py")))
self.assertEqual(module.pure_python, 1)
Expand All @@ -766,7 +766,7 @@ def test_module_base_props(self) -> None:
self.assertEqual(module.statement(), module)
assert len(records) == 1
with self.assertRaises(StatementMissing):
module.statement(future=True)
module.statement()

def test_module_locals(self) -> None:
"""Test the 'locals' dictionary of an astroid module."""
Expand Down Expand Up @@ -800,8 +800,8 @@ def test_function_base_props(self) -> None:
self.assertTrue(function.parent)
self.assertEqual(function.frame(), function)
self.assertEqual(function.parent.frame(), module)
self.assertEqual(function.frame(future=True), function)
self.assertEqual(function.parent.frame(future=True), module)
self.assertEqual(function.frame(), function)
self.assertEqual(function.parent.frame(), module)
self.assertEqual(function.root(), module)
self.assertEqual([n.name for n in function.args.args], ["key", "val"])
self.assertEqual(function.type, "function")
Expand All @@ -824,8 +824,8 @@ def test_class_base_props(self) -> None:
self.assertTrue(klass.parent)
self.assertEqual(klass.frame(), klass)
self.assertEqual(klass.parent.frame(), module)
self.assertEqual(klass.frame(future=True), klass)
self.assertEqual(klass.parent.frame(future=True), module)
self.assertEqual(klass.frame(), klass)
self.assertEqual(klass.parent.frame(), module)
self.assertEqual(klass.root(), module)
self.assertEqual(klass.basenames, [])
self.assertTrue(klass.newstyle)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_filter_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ def test_empty_node() -> None:
enum_mod = extract_node("import enum")
empty = EmptyNode(parent=enum_mod)
empty.is_statement = True
filtered_statements = _filter_stmts(
empty, [empty.statement(future=True)], empty.frame(future=True), 0
)
filtered_statements = _filter_stmts(empty, [empty.statement()], empty.frame(), 0)
assert filtered_statements[0] is empty
4 changes: 2 additions & 2 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_unbound_method_inference(self) -> None:
self.assertIsInstance(meth1, UnboundMethod)
self.assertEqual(meth1.name, "meth1")
self.assertEqual(meth1.parent.frame().name, "C")
self.assertEqual(meth1.parent.frame(future=True).name, "C")
self.assertEqual(meth1.parent.frame().name, "C")
self.assertRaises(StopIteration, partial(next, inferred))

def test_bound_method_inference(self) -> None:
Expand All @@ -324,7 +324,7 @@ def test_bound_method_inference(self) -> None:
self.assertIsInstance(meth1, BoundMethod)
self.assertEqual(meth1.name, "meth1")
self.assertEqual(meth1.parent.frame().name, "C")
self.assertEqual(meth1.parent.frame(future=True).name, "C")
self.assertEqual(meth1.parent.frame().name, "C")
self.assertRaises(StopIteration, partial(next, inferred))

def test_args_default_inference1(self) -> None:
Expand Down
Loading

0 comments on commit 19e0af3

Please sign in to comment.