Skip to content

Commit

Permalink
Deprecate future argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 22, 2023
1 parent 19e0af3 commit e3ba1ca
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ Release date: TBA
missing parents regardless of the value of the ``future`` argument (which gave this behavior
already).

The ``future`` argument to each method is deprecated and will be removed in astroid 4.0.

Refs #1217

* Remove deprecated ``Ellipsis``, ``ExtSlice``, ``Index`` nodes.
Expand Down
6 changes: 6 additions & 0 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3814,6 +3814,12 @@ def frame(
:returns: The first parent frame node.
"""
if future is not None:
warnings.warn(
"The future arg will be removed in astroid 4.0.",
DeprecationWarning,
stacklevel=2,
)
if not self.parent:
raise ParentMissingError(target=self)

Expand Down
12 changes: 12 additions & 0 deletions astroid/nodes/node_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ def statement(self, *, future: Literal[None, True] = None) -> nodes.Statement:
:raises StatementMissing: If self has no parent attribute.
"""
if future is not None:
warnings.warn(
"The future arg will be removed in astroid 4.0.",
DeprecationWarning,
stacklevel=2,
)
if self.is_statement:
return cast("nodes.Statement", self)
if not self.parent:
Expand All @@ -310,6 +316,12 @@ def frame(
:returns: The first parent frame node.
:raises ParentMissingError: If self has no parent attribute.
"""
if future is not None:
warnings.warn(
"The future arg will be removed in astroid 4.0.",
DeprecationWarning,
stacklevel=2,
)
if self.parent is None:
raise ParentMissingError(target=self)
return self.parent.frame(future=future)
Expand Down
6 changes: 6 additions & 0 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ def statement(self, *, future: Literal[None, True] = None) -> NoReturn:
When called on a :class:`Module` this raises a StatementMissing.
"""
if future is not None:
warnings.warn(
"The future arg will be removed in astroid 4.0.",
DeprecationWarning,
stacklevel=2,
)
raise StatementMissing(target=self)

def previous_sibling(self):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,10 @@ def test_module_base_props(self) -> None:
self.assertEqual(module.pure_python, 1)
self.assertEqual(module.package, 0)
self.assertFalse(module.is_statement)
with pytest.warns(DeprecationWarning) as records:
self.assertEqual(module.statement(), module)
assert len(records) == 1
with self.assertRaises(StatementMissing):
with pytest.warns(DeprecationWarning) as records:
self.assertEqual(module.statement(future=True), module)
assert len(records) == 1
with self.assertRaises(StatementMissing):
module.statement()

Expand Down
8 changes: 4 additions & 4 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,16 +541,16 @@ def _test(self, value: Any) -> None:
self.assertIs(node.value, value)
self.assertTrue(node._proxied.parent)
self.assertEqual(node._proxied.root().name, value.__class__.__module__)
with self.assertRaises(AttributeError):
with self.assertRaises(StatementMissing):
with pytest.warns(DeprecationWarning) as records:
node.statement()
node.statement(future=True)
assert len(records) == 1
with self.assertRaises(StatementMissing):
node.statement()

with self.assertRaises(AttributeError):
with self.assertRaises(ParentMissingError):
with pytest.warns(DeprecationWarning) as records:
node.frame()
node.frame(future=True)
assert len(records) == 1
with self.assertRaises(ParentMissingError):
node.frame()
Expand Down

0 comments on commit e3ba1ca

Please sign in to comment.