From fff4db4631a5898d6c280512898d0a829da62fed Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sat, 20 Nov 2021 16:42:43 +0530 Subject: [PATCH 01/35] Fix frame() error on inferred node --- astroid/nodes/node_ng.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 5eb6d1985c..dd65611d34 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -323,6 +323,9 @@ def frame( :returns: The first parent frame node. """ + if self.parent is None: + return self + return self.parent.frame() def scope(self) -> "nodes.LocalsDictNodeNG": From 2cab0659e5d5c3af250687244b021c09875265cf Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sat, 20 Nov 2021 16:45:50 +0530 Subject: [PATCH 02/35] Update node_ng.py --- astroid/nodes/node_ng.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index dd65611d34..eafbdd7354 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -324,7 +324,9 @@ def frame( :returns: The first parent frame node. """ if self.parent is None: - return self + if isinstance(self, (nodes.Module, nodes.FunctionDef, nodes.ClassDef, nodes.Lambda)): + return self + return None return self.parent.frame() From 8952c6434e92472f077f4bfe198b870002942799 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 20 Nov 2021 11:16:24 +0000 Subject: [PATCH 03/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/nodes/node_ng.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index eafbdd7354..25ea239ab9 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -324,7 +324,9 @@ def frame( :returns: The first parent frame node. """ if self.parent is None: - if isinstance(self, (nodes.Module, nodes.FunctionDef, nodes.ClassDef, nodes.Lambda)): + if isinstance( + self, (nodes.Module, nodes.FunctionDef, nodes.ClassDef, nodes.Lambda) + ): return self return None From 4ea13b2061dc5cdd8db95a0eef64725ab5e4a67a Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sat, 20 Nov 2021 23:15:41 +0530 Subject: [PATCH 04/35] Update node_ng.py --- astroid/nodes/node_ng.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 25ea239ab9..e4e6b5a8a2 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -17,7 +17,7 @@ overload, ) -from astroid import decorators, util +from astroid import decorators, nodes, util from astroid.exceptions import ( AstroidError, InferenceError, From 42ce9f4ee407af8c03a08bdbfa282fb736f06e35 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 21 Nov 2021 23:24:43 +0530 Subject: [PATCH 05/35] Add FrameMissing exception --- astroid/exceptions.py | 15 +++++++++++++++ astroid/nodes/node_ng.py | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/astroid/exceptions.py b/astroid/exceptions.py index b8838023e4..b9d97b7707 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -289,6 +289,21 @@ def __init__(self, target: "nodes.NodeNG") -> None: message=f"Statement not found on {target!r}" ) +class FrameMissing(ParentMissingError): + """Raised when a call to node.frame() does not return a node. This is because + a node in the chain does not have a parent attribute and therefore does not + return a node for frame(). + + Standard attributes: + target: The node for which the parent lookup failed. + """ + + def __init__(self, target: "nodes.NodeNG") -> None: + super(ParentMissingError, self).__init__( + message=f"Frame not found on {target!r}" + ) + + # Backwards-compatibility aliases OperationError = util.BadOperationMessage diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index e4e6b5a8a2..49b443ac6e 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -20,6 +20,7 @@ from astroid import decorators, nodes, util from astroid.exceptions import ( AstroidError, + FrameMissing, InferenceError, ParentMissingError, StatementMissing, @@ -328,7 +329,7 @@ def frame( self, (nodes.Module, nodes.FunctionDef, nodes.ClassDef, nodes.Lambda) ): return self - return None + raise FrameMissing(target=self) return self.parent.frame() From 4629c93a05d5c42ff591f342b17954d97605fa43 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Nov 2021 17:55:39 +0000 Subject: [PATCH 06/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroid/exceptions.py b/astroid/exceptions.py index b9d97b7707..52798620a2 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -289,6 +289,7 @@ def __init__(self, target: "nodes.NodeNG") -> None: message=f"Statement not found on {target!r}" ) + class FrameMissing(ParentMissingError): """Raised when a call to node.frame() does not return a node. This is because a node in the chain does not have a parent attribute and therefore does not @@ -304,7 +305,6 @@ def __init__(self, target: "nodes.NodeNG") -> None: ) - # Backwards-compatibility aliases OperationError = util.BadOperationMessage UnaryOperationError = util.BadUnaryOperationMessage From 9b2c4832dfab5008b20cfc9437bf03a56f6471f5 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 21 Nov 2021 23:27:45 +0530 Subject: [PATCH 07/35] Fix flake8 lint --- astroid/nodes/node_ng.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 49b443ac6e..3dfe5d4361 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -31,8 +31,6 @@ from astroid.nodes.const import OP_PRECEDENCE if TYPE_CHECKING: - from astroid import nodes - if sys.version_info >= (3, 6, 2): from typing import NoReturn else: From 27c1707c09633ed928e444765ab12d6714a2beb8 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 22 Nov 2021 01:20:19 +0530 Subject: [PATCH 08/35] Fix pylint error --- astroid/exceptions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/astroid/exceptions.py b/astroid/exceptions.py index 52798620a2..86b4605106 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -300,6 +300,7 @@ class FrameMissing(ParentMissingError): """ def __init__(self, target: "nodes.NodeNG") -> None: + # pylint: disable-next=bad-super-call super(ParentMissingError, self).__init__( message=f"Frame not found on {target!r}" ) From 1b59f00dd0e640e8830f3d3e084ded5be67faf99 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 14 Dec 2021 16:07:35 +0530 Subject: [PATCH 09/35] Remove unnecessary isinstance --- astroid/nodes/node_ng.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 3dfe5d4361..fc4e04821f 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -323,10 +323,6 @@ def frame( :returns: The first parent frame node. """ if self.parent is None: - if isinstance( - self, (nodes.Module, nodes.FunctionDef, nodes.ClassDef, nodes.Lambda) - ): - return self raise FrameMissing(target=self) return self.parent.frame() From 54bcb598da375ef5f190de9caa650c232cffbd56 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 13:57:38 +0530 Subject: [PATCH 10/35] Add types and remove exception type --- astroid/exceptions.py | 16 ---------------- astroid/nodes/node_classes.py | 5 ++++- astroid/nodes/node_ng.py | 18 +++++++++++++----- astroid/nodes/scoped_nodes.py | 8 ++++---- tests/unittest_nodes.py | 8 ++++++++ 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/astroid/exceptions.py b/astroid/exceptions.py index 86b4605106..b8838023e4 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -290,22 +290,6 @@ def __init__(self, target: "nodes.NodeNG") -> None: ) -class FrameMissing(ParentMissingError): - """Raised when a call to node.frame() does not return a node. This is because - a node in the chain does not have a parent attribute and therefore does not - return a node for frame(). - - Standard attributes: - target: The node for which the parent lookup failed. - """ - - def __init__(self, target: "nodes.NodeNG") -> None: - # pylint: disable-next=bad-super-call - super(ParentMissingError, self).__init__( - message=f"Frame not found on {target!r}" - ) - - # Backwards-compatibility aliases OperationError = util.BadOperationMessage UnaryOperationError = util.BadUnaryOperationMessage diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index f7abb6e3ce..bae0f9afeb 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -65,6 +65,7 @@ from typing_extensions import Literal if TYPE_CHECKING: + from astroid import nodes from astroid.nodes import LocalsDictNodeNG @@ -5006,7 +5007,9 @@ def postinit(self, target: NodeNG, value: NodeNG) -> None: See astroid/protocols.py for actual implementation. """ - def frame(self): + def frame( + self, *, future: Literal[None, True] = None + ) -> Union["nodes.FunctionDef", "nodes.Module", "nodes.ClassDef", "nodes.Lambda"]: """The first parent frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index fc4e04821f..beea7d0199 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -20,7 +20,6 @@ from astroid import decorators, nodes, util from astroid.exceptions import ( AstroidError, - FrameMissing, InferenceError, ParentMissingError, StatementMissing, @@ -288,7 +287,7 @@ def statement(self, *, future: Literal[True]) -> "nodes.Statement": def statement( self, *, future: Literal[None, True] = None - ) -> Union["nodes.Statement", "nodes.Module", "NoReturn"]: + ) -> Union["nodes.Statement", "nodes.Module"]: """The first parent node, including self, marked as statement node. TODO: Deprecate the future parameter and only raise StatementMissing and return @@ -313,7 +312,7 @@ def statement( return self.parent.statement(future=future) def frame( - self, + self, *, future: Literal[None, True] = None ) -> Union["nodes.FunctionDef", "nodes.Module", "nodes.ClassDef", "nodes.Lambda"]: """The first parent frame node. @@ -323,9 +322,18 @@ def frame( :returns: The first parent frame node. """ if self.parent is None: - raise FrameMissing(target=self) + if future: + raise ParentMissingError(target=self) + warnings.warn( + "In astroid 3.0.0 NodeNG.frame() will return either a Frame, " + "or raise ParentMissingError. AttributeError will no longer be raised. " + "This behaviour can already be triggered " + "by passing 'future=True' to a statement() call.", + DeprecationWarning, + ) + raise AttributeError(f"{self} object has no attribute 'parent'") - return self.parent.frame() + return self.parent.frame(future=future) def scope(self) -> "nodes.LocalsDictNodeNG": """The first parent node defining a new scope. diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py index 96a034c868..1251f4f123 100644 --- a/astroid/nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes.py @@ -856,7 +856,7 @@ def bool_value(self, context=None): def get_children(self): yield from self.body - def frame(self: T) -> T: + def frame(self: T, *, future: Literal[None, True] = None) -> T: """The node's frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, @@ -1471,7 +1471,7 @@ def get_children(self): yield self.args yield self.body - def frame(self: T) -> T: + def frame(self: T, *, future: Literal[None, True] = None) -> T: """The node's frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, @@ -2001,7 +2001,7 @@ def scope_lookup(self, node, name, offset=0): return self, [frame] return super().scope_lookup(node, name, offset) - def frame(self: T) -> T: + def frame(self: T, *, future: Literal[None, True] = None) -> T: """The node's frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, @@ -3248,7 +3248,7 @@ def _get_assign_nodes(self): ) return list(itertools.chain.from_iterable(children_assign_nodes)) - def frame(self: T) -> T: + def frame(self: T, *, future: Literal[None, True] = None) -> T: """The node's frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py index 68e2b33561..aab8c5a123 100644 --- a/tests/unittest_nodes.py +++ b/tests/unittest_nodes.py @@ -55,6 +55,7 @@ AstroidBuildingError, AstroidSyntaxError, AttributeInferenceError, + ParentMissingError, StatementMissing, ) from astroid.nodes.node_classes import ( @@ -641,6 +642,13 @@ def _test(self, value: Any) -> None: with self.assertRaises(StatementMissing): node.statement(future=True) + with self.assertRaises(AttributeError): + with pytest.warns(DeprecationWarning) as records: + node.frame() + assert len(records) == 1 + with self.assertRaises(ParentMissingError): + node.frame(future=True) + def test_none(self) -> None: self._test(None) From 7bee39138513c7f0fa98ea5633556064b4a734a6 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sun, 21 Nov 2021 12:53:13 +0530 Subject: [PATCH 11/35] Add visit_unknown --- astroid/nodes/as_string.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/astroid/nodes/as_string.py b/astroid/nodes/as_string.py index bc8dab1c16..dcd066cf13 100644 --- a/astroid/nodes/as_string.py +++ b/astroid/nodes/as_string.py @@ -99,6 +99,9 @@ def _should_wrap(self, node, child, is_left): # visit_ methods ########################################### + def visit_unknown(self, node): + return 'astroid.Unknown()' + def visit_await(self, node): return f"await {node.value.accept(self)}" From 9e55d844b563aceab2dd9a50e7aa6757a108d9c4 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:00:09 +0530 Subject: [PATCH 12/35] Formatting --- astroid/nodes/as_string.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astroid/nodes/as_string.py b/astroid/nodes/as_string.py index dcd066cf13..72e19176ed 100644 --- a/astroid/nodes/as_string.py +++ b/astroid/nodes/as_string.py @@ -100,8 +100,8 @@ def _should_wrap(self, node, child, is_left): # visit_ methods ########################################### def visit_unknown(self, node): - return 'astroid.Unknown()' - + return "astroid.Unknown()" + def visit_await(self, node): return f"await {node.value.accept(self)}" From 9da479c450e497bc81eda2002d2abaeed610950f Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 15 Dec 2021 18:26:02 +0100 Subject: [PATCH 13/35] Upgrade pylint to 2.12.2 (#1297) * Upgrade pylint to 2.12.2 * Default Python in the CI is now python 3.8 * Remove useless suppression for python 3.8 * Disable no-member for false positive with zipimport --- astroid/nodes/node_ng.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index beea7d0199..64a750f884 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -30,6 +30,8 @@ from astroid.nodes.const import OP_PRECEDENCE if TYPE_CHECKING: + from astroid import nodes + if sys.version_info >= (3, 6, 2): from typing import NoReturn else: From 9fb55c5afbd031415ea9f90f6f34934093e804bf Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sun, 21 Nov 2021 23:27:45 +0530 Subject: [PATCH 14/35] Fix flake8 lint --- astroid/nodes/node_ng.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 64a750f884..beea7d0199 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -30,8 +30,6 @@ from astroid.nodes.const import OP_PRECEDENCE if TYPE_CHECKING: - from astroid import nodes - if sys.version_info >= (3, 6, 2): from typing import NoReturn else: From dac07c68d709752c81b1b73d68a092ae86dac19a Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 13:57:38 +0530 Subject: [PATCH 15/35] Add types and remove exception type --- astroid/nodes/node_ng.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index beea7d0199..835dda644e 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -29,12 +29,6 @@ from astroid.nodes.as_string import AsStringVisitor from astroid.nodes.const import OP_PRECEDENCE -if TYPE_CHECKING: - if sys.version_info >= (3, 6, 2): - from typing import NoReturn - else: - from typing_extensions import NoReturn - if sys.version_info >= (3, 8): from typing import Literal else: From 31636651f7083485c144e302b63473bad64525b9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:39:36 +0000 Subject: [PATCH 16/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/nodes/node_ng.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 835dda644e..a3ee52c8f8 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -4,7 +4,6 @@ import warnings from functools import singledispatch as _singledispatch from typing import ( - TYPE_CHECKING, ClassVar, Iterator, List, From 08014edb8d76d1a627039f9420d5b1f8ab1b3074 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:10:18 +0530 Subject: [PATCH 17/35] Remove unrelated code --- astroid/nodes/as_string.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/astroid/nodes/as_string.py b/astroid/nodes/as_string.py index 72e19176ed..bc8dab1c16 100644 --- a/astroid/nodes/as_string.py +++ b/astroid/nodes/as_string.py @@ -99,9 +99,6 @@ def _should_wrap(self, node, child, is_left): # visit_ methods ########################################### - def visit_unknown(self, node): - return "astroid.Unknown()" - def visit_await(self, node): return f"await {node.value.accept(self)}" From 67281cb9e29ca0e4168ceb333a17287358008bf2 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:12:14 +0530 Subject: [PATCH 18/35] Hack to trigger ci --- astroid/nodes/as_string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroid/nodes/as_string.py b/astroid/nodes/as_string.py index bc8dab1c16..de2601cc35 100644 --- a/astroid/nodes/as_string.py +++ b/astroid/nodes/as_string.py @@ -22,7 +22,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE """This module renders Astroid nodes as string""" -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING, List, Union if TYPE_CHECKING: from astroid.nodes.node_classes import ( From 3bee4f540aa6d8953d2eefdd8b4860b85e304caf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:43:02 +0000 Subject: [PATCH 19/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/nodes/as_string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroid/nodes/as_string.py b/astroid/nodes/as_string.py index de2601cc35..bc8dab1c16 100644 --- a/astroid/nodes/as_string.py +++ b/astroid/nodes/as_string.py @@ -22,7 +22,7 @@ # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE """This module renders Astroid nodes as string""" -from typing import TYPE_CHECKING, List, Union +from typing import TYPE_CHECKING, List if TYPE_CHECKING: from astroid.nodes.node_classes import ( From db901ce901fa98272d43556a86b65180ce2283e6 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:15:48 +0530 Subject: [PATCH 20/35] Remove unused import --- astroid/nodes/node_ng.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index a3ee52c8f8..9df1398486 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -16,7 +16,7 @@ overload, ) -from astroid import decorators, nodes, util +from astroid import decorators, util from astroid.exceptions import ( AstroidError, InferenceError, @@ -29,7 +29,8 @@ from astroid.nodes.const import OP_PRECEDENCE if sys.version_info >= (3, 8): - from typing import Literal + from astroid import nodes + from typing import Literal, Union else: from typing_extensions import Literal From a01e510ccb5ce1d65b76a5303993b07be065786b Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:16:27 +0530 Subject: [PATCH 21/35] something --- astroid/nodes/node_ng.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 9df1398486..36f8744397 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -11,6 +11,7 @@ Tuple, Type, TypeVar, + Sequence, Union, cast, overload, @@ -30,7 +31,7 @@ if sys.version_info >= (3, 8): from astroid import nodes - from typing import Literal, Union + from typing import Literal else: from typing_extensions import Literal From 410445b6dbf64e664136e43e8b4a8e4cb0bdb341 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:16:58 +0530 Subject: [PATCH 22/35] Move import to TYPE_CHECKING block --- astroid/nodes/node_ng.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 36f8744397..f4dc3a560d 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -4,6 +4,7 @@ import warnings from functools import singledispatch as _singledispatch from typing import ( + TYPE_CHECKING, ClassVar, Iterator, List, @@ -30,11 +31,12 @@ from astroid.nodes.const import OP_PRECEDENCE if sys.version_info >= (3, 8): - from astroid import nodes from typing import Literal else: from typing_extensions import Literal +if TYPE_CHECKING: + from astroid import nodes # Types for 'NodeNG.nodes_of_class()' T_Nodes = TypeVar("T_Nodes", bound="NodeNG") From 1d6dc24fa2358394b7daaed93de1bdefb6b16642 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Dec 2021 08:47:11 +0000 Subject: [PATCH 23/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/nodes/node_ng.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index f4dc3a560d..bf80e17f3d 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -12,7 +12,6 @@ Tuple, Type, TypeVar, - Sequence, Union, cast, overload, @@ -32,6 +31,8 @@ if sys.version_info >= (3, 8): from typing import Literal + + from astroid import nodes else: from typing_extensions import Literal From a3b2db9bf549fc296b52045cab4f2649f7476ba7 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:18:59 +0530 Subject: [PATCH 24/35] Unused import --- astroid/nodes/node_ng.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index bf80e17f3d..5b551e878f 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -31,8 +31,6 @@ if sys.version_info >= (3, 8): from typing import Literal - - from astroid import nodes else: from typing_extensions import Literal From 4a1a4ada2051c9018aabf2585e6dbfe6a0d74aef Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 20 Dec 2021 14:20:18 +0530 Subject: [PATCH 25/35] ci --- astroid/nodes/node_ng.py | 1 + 1 file changed, 1 insertion(+) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 5b551e878f..3097ff6213 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -9,6 +9,7 @@ Iterator, List, Optional, + Sequence, Tuple, Type, TypeVar, From 42b787e5bd5f8262910ced59b1585df582e1da60 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Dec 2021 22:06:44 +0000 Subject: [PATCH 26/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/nodes/node_ng.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index d9e79db6d9..56a1772bac 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -9,7 +9,6 @@ Iterator, List, Optional, - Sequence, Tuple, Type, TypeVar, From 9be8a89f2741df9db1330bf5d1bd49f2acf5f88f Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 25 Dec 2021 03:38:49 +0530 Subject: [PATCH 27/35] Fix imports --- astroid/nodes/node_ng.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 56a1772bac..2145f1c1a9 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -29,14 +29,19 @@ from astroid.nodes.as_string import AsStringVisitor from astroid.nodes.const import OP_PRECEDENCE +if TYPE_CHECKING: + from astroid import nodes + + if sys.version_info >= (3, 6, 2): + from typing import NoReturn + else: + from typing_extensions import NoReturn + if sys.version_info >= (3, 8): from typing import Literal else: from typing_extensions import Literal -if TYPE_CHECKING: - from astroid import nodes - # Types for 'NodeNG.nodes_of_class()' T_Nodes = TypeVar("T_Nodes", bound="NodeNG") T_Nodes2 = TypeVar("T_Nodes2", bound="NodeNG") @@ -281,7 +286,7 @@ def statement(self, *, future: Literal[True]) -> "nodes.Statement": def statement( self, *, future: Literal[None, True] = None - ) -> Union["nodes.Statement", "nodes.Module"]: + ) -> Union["nodes.Statement", "nodes.Module", "NoReturn"]: """The first parent node, including self, marked as statement node. TODO: Deprecate the future parameter and only raise StatementMissing and return From 08bcd0886edb524dbb2ef071cd6ea14b434bd3e9 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sat, 25 Dec 2021 03:42:12 +0530 Subject: [PATCH 28/35] Apply suggestions from code review --- astroid/nodes/node_ng.py | 1 + 1 file changed, 1 insertion(+) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 2145f1c1a9..7d474892af 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -42,6 +42,7 @@ else: from typing_extensions import Literal + # Types for 'NodeNG.nodes_of_class()' T_Nodes = TypeVar("T_Nodes", bound="NodeNG") T_Nodes2 = TypeVar("T_Nodes2", bound="NodeNG") From 79bb6c277deb59e6441394998d0150c62eb39ae9 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sat, 25 Dec 2021 03:42:35 +0530 Subject: [PATCH 29/35] Update astroid/nodes/node_ng.py --- astroid/nodes/node_ng.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 7d474892af..2531f67284 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -287,7 +287,7 @@ def statement(self, *, future: Literal[True]) -> "nodes.Statement": def statement( self, *, future: Literal[None, True] = None - ) -> Union["nodes.Statement", "nodes.Module", "NoReturn"]: + ) -> Union["nodes.Statement", "nodes.Module"]: """The first parent node, including self, marked as statement node. TODO: Deprecate the future parameter and only raise StatementMissing and return From 76faa99f0fd3840395651d496e741c5ea4457189 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Dec 2021 22:13:23 +0000 Subject: [PATCH 30/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/nodes/node_ng.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 2531f67284..eee2a3b4e3 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -33,9 +33,9 @@ from astroid import nodes if sys.version_info >= (3, 6, 2): - from typing import NoReturn + pass else: - from typing_extensions import NoReturn + pass if sys.version_info >= (3, 8): from typing import Literal From 1f1f7e7adcf9b0e485e95f206cb70cb11ae0d4a0 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 25 Dec 2021 03:51:28 +0530 Subject: [PATCH 31/35] Docstring --- astroid/nodes/node_ng.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index eee2a3b4e3..240b65ac35 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -325,10 +325,10 @@ def frame( if future: raise ParentMissingError(target=self) warnings.warn( - "In astroid 3.0.0 NodeNG.frame() will return either a Frame, " + "In astroid 3.0.0 NodeNG.frame() will return either a Frame node, " "or raise ParentMissingError. AttributeError will no longer be raised. " "This behaviour can already be triggered " - "by passing 'future=True' to a statement() call.", + "by passing 'future=True' to a frame() call.", DeprecationWarning, ) raise AttributeError(f"{self} object has no attribute 'parent'") From c68db0026ff01aec413e229228f9ad5d4e7c11ea Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Sat, 25 Dec 2021 03:52:50 +0530 Subject: [PATCH 32/35] Update astroid/nodes/node_ng.py --- astroid/nodes/node_ng.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/astroid/nodes/node_ng.py b/astroid/nodes/node_ng.py index 240b65ac35..93ee8a3a32 100644 --- a/astroid/nodes/node_ng.py +++ b/astroid/nodes/node_ng.py @@ -32,11 +32,6 @@ if TYPE_CHECKING: from astroid import nodes - if sys.version_info >= (3, 6, 2): - pass - else: - pass - if sys.version_info >= (3, 8): from typing import Literal else: From 8bbba4199cf07408857a03be00e1596e7b741b11 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 28 Dec 2021 13:39:10 +0530 Subject: [PATCH 33/35] Add changelog entry --- ChangeLog | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5bfa2f6856..6ae787256c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,7 +6,9 @@ What's New in astroid 2.10.0? ============================= Release date: TBA - +* ``NodeNG.frame()`` and ``NodeNG.statement()`` will start raising ``ParentMissingError`` + instead of ``AttributeError`` in astroid 3.0. This behaviour can already be triggered + by passing ``future=True`` to a ``frame()`` or ``statement()`` call. What's New in astroid 2.9.1? ============================ From 7ad182c1cbc5f0856d083d81f4ecfe636a8a1442 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 28 Dec 2021 18:56:07 +0530 Subject: [PATCH 34/35] Move changelog --- ChangeLog | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ae787256c..0b336fb639 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,14 +6,14 @@ What's New in astroid 2.10.0? ============================= Release date: TBA -* ``NodeNG.frame()`` and ``NodeNG.statement()`` will start raising ``ParentMissingError`` - instead of ``AttributeError`` in astroid 3.0. This behaviour can already be triggered - by passing ``future=True`` to a ``frame()`` or ``statement()`` call. - What's New in astroid 2.9.1? ============================ Release date: TBA +* ``NodeNG.frame()`` and ``NodeNG.statement()`` will start raising ``ParentMissingError`` + instead of ``AttributeError`` in astroid 3.0. This behaviour can already be triggered + by passing ``future=True`` to a ``frame()`` or ``statement()`` call. + * Prefer the module loader get_source() method in AstroidBuilder's module_build() when possible to avoid assumptions about source code being available on a filesystem. Otherwise the source cannot From 1fe3c114ecae7cac77da7e479cb4b5ee830d6792 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Tue, 28 Dec 2021 18:56:48 +0530 Subject: [PATCH 35/35] whitespace --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0b336fb639..76c15f0f38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ What's New in astroid 2.10.0? ============================= Release date: TBA + + What's New in astroid 2.9.1? ============================ Release date: TBA