Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
havogt committed Aug 7, 2024
1 parent d9bcbdb commit 53f6b6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/gt4py/next/ffront/ast_passes/fix_missing_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def generic_visit(self, node: ast.AST) -> ast.AST:
node = copy.copy(node)
parent_node = self._parent_nodes[-1]

node.lineno = parent_node.lineno # type: ignore[attr-defined] # this is monkey patching as not all `ast.AST` have `lineno` etc
node.col_offset = parent_node.col_offset # type: ignore[attr-defined] # this is monkey patching as not all `ast.AST` have `lineno` etc
node.lineno = parent_node.lineno # type: ignore[attr-defined] # we are adding the attribute which breaks type checking
node.col_offset = parent_node.col_offset # type: ignore[attr-defined]

# the end positions are optional according to
# https://docs.python.org/3/library/ast.html#ast.AST.end_col_offset
if hasattr(parent_node, "end_lineno"):
node.end_lineno = parent_node.end_lineno # type: ignore[attr-defined] # this is monkey patching as not all `ast.AST` have `lineno` etc
node.end_lineno = parent_node.end_lineno # type: ignore[attr-defined]
if hasattr(parent_node, "end_col_offset"):
node.end_col_offset = parent_node.end_col_offset # type: ignore[attr-defined] # this is monkey patching as not all `ast.AST` have `lineno` etc
node.end_col_offset = parent_node.end_col_offset # type: ignore[attr-defined]

self._parent_nodes.append(node)
result = super().generic_visit(node)
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/ffront/dialect_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_location(self, node: ast.AST) -> SourceLocation:
line_offset = self.source_definition.line_offset
col_offset = self.source_definition.column_offset

# seems we monkey patched all AST nodes in `fix_missing_locations`, therefore we can assume all location attributes are defined
# `FixMissingLocations` ensures that all nodes have the location attributes
assert hasattr(node, "lineno")
line = node.lineno + line_offset if node.lineno is not None else None
assert hasattr(node, "end_lineno")
Expand Down

0 comments on commit 53f6b6c

Please sign in to comment.