Skip to content

Commit

Permalink
Add lineno and col_offset to Keyword nodes (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Jun 7, 2021
1 parent 6e8a575 commit 8579163
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Release Date: TBA

* Improve support for Pattern Matching

* Add lineno and col_offset for ``Keyword`` nodes and Python 3.9+


What's New in astroid 2.5.7?
============================
Expand Down
10 changes: 8 additions & 2 deletions astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
}
PY37 = sys.version_info >= (3, 7)
PY38 = sys.version_info >= (3, 8)
PY39 = sys.version_info >= (3, 9)


def _visit_or_none(node, attr, visitor, parent, visit="visit", **kws):
Expand Down Expand Up @@ -742,9 +743,14 @@ def visit_index(self, node, parent):
newnode.postinit(self.visit(node.value, newnode))
return newnode

def visit_keyword(self, node, parent):
def visit_keyword(self, node: "ast.keyword", parent: NodeNG) -> nodes.Keyword:
"""visit a Keyword node by returning a fresh instance of it"""
newnode = nodes.Keyword(node.arg, parent=parent)
if PY39:
newnode = nodes.Keyword(
node.arg, node.lineno, node.col_offset, parent=parent
)
else:
newnode = nodes.Keyword(node.arg, parent=parent)
newnode.postinit(self.visit(node.value, newnode))
return newnode

Expand Down

0 comments on commit 8579163

Please sign in to comment.