Skip to content
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

Add typing to NodeNG.statement #1217

Merged
merged 24 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d8347f0
Add typing to ``NodeNG.statement``
DanielNoord Oct 22, 2021
f9fe68d
Rewrite to use ``StatementMissing``
DanielNoord Nov 2, 2021
7c47926
Merge branch 'main' of https://github.com/PyCQA/astroid into statement
DanielNoord Nov 2, 2021
b6373e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2021
19c5ed4
Add ``future`` parameter to ``NodeNG.statement()`` and add typing
DanielNoord Nov 3, 2021
baef395
Merge branch 'statement' of https://github.com/DanielNoord/astroid in…
DanielNoord Nov 3, 2021
005a9ff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 3, 2021
da1b989
Update astroid/exceptions.py
DanielNoord Nov 3, 2021
d95d5ac
Fix overload
DanielNoord Nov 3, 2021
4a9af1e
Merge branch 'statement' of https://github.com/DanielNoord/astroid in…
DanielNoord Nov 3, 2021
ef019e6
Update astroid/nodes/node_ng.py
DanielNoord Nov 3, 2021
1f6ec98
WIP Code Review
DanielNoord Nov 4, 2021
df9b49c
Update astroid/nodes/scoped_nodes.py
DanielNoord Nov 4, 2021
6026560
Add NoReturn
DanielNoord Nov 4, 2021
d07374c
Code review
DanielNoord Nov 6, 2021
2596ee6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 6, 2021
e8d0ff2
Apply suggestions from code review
DanielNoord Nov 6, 2021
73fb21d
Add tests
DanielNoord Nov 6, 2021
6777dc9
Apply suggestions from code review
DanielNoord Nov 6, 2021
1900532
Code Review
DanielNoord Nov 6, 2021
11aefd2
Added keyword parameter to all overloads and statements
DanielNoord Nov 6, 2021
2b6e7d0
Add disable
DanielNoord Nov 6, 2021
cab6a88
Update astroid/exceptions.py
DanielNoord Nov 6, 2021
78588ff
Update astroid/nodes/scoped_nodes.py
DanielNoord Nov 7, 2021
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
10 changes: 7 additions & 3 deletions astroid/nodes/node_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Type,
TypeVar,
Union,
cast,
overload,
)

Expand All @@ -25,7 +26,7 @@
from astroid.nodes.const import OP_PRECEDENCE

if TYPE_CHECKING:
from astroid.nodes import LocalsDictNodeNG
from astroid import nodes

# Types for 'NodeNG.nodes_of_class()'
T_Nodes = TypeVar("T_Nodes", bound="NodeNG")
Expand Down Expand Up @@ -248,14 +249,17 @@ def parent_of(self, node):
return True
return False

def statement(self):
def statement(self) -> Union["nodes.Statement", "nodes.Module"]:
"""The first parent node, including self, marked as statement node.

:returns: The first parent statement.
:rtype: NodeNG
"""
if self.is_statement:
self = cast("nodes.Statement", self)
return self
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
if not self.parent:
raise ParentMissingError(target=self)
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
return self.parent.statement()

def frame(self):
Expand All @@ -269,7 +273,7 @@ def frame(self):
"""
return self.parent.frame()

def scope(self) -> "LocalsDictNodeNG":
def scope(self) -> "nodes.LocalsDictNodeNG":
"""The first parent node defining a new scope.
These can be Module, FunctionDef, ClassDef, Lambda, or GeneratorExp nodes.

Expand Down
3 changes: 1 addition & 2 deletions astroid/nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,10 @@ def fully_defined(self):
"""
return self.file is not None and self.file.endswith(".py")

def statement(self):
def statement(self) -> "Module":
"""The first parent node, including self, marked as statement node.

:returns: The first parent statement.
:rtype: NodeNG
"""
return self
cdce8p marked this conversation as resolved.
Show resolved Hide resolved

Expand Down