MCPcopy Index your code
hub / github.com/RustPython/RustPython / copy_location

Function copy_location

Lib/ast.py:193–207  ·  view source on GitHub ↗

Copy source location (`lineno`, `col_offset`, `end_lineno`, and `end_col_offset` attributes) from *old_node* to *new_node* if possible, and return *new_node*.

(new_node, old_node)

Source from the content-addressed store, hash-verified

191
192
193def copy_location(new_node, old_node):
194 """
195 Copy source location (`lineno`, `col_offset`, `end_lineno`, and `end_col_offset`
196 attributes) from *old_node* to *new_node* if possible, and return *new_node*.
197 """
198 for attr in 'lineno', 'col_offset', 'end_lineno', 'end_col_offset':
199 if attr in old_node._attributes and attr in new_node._attributes:
200 value = getattr(old_node, attr, None)
201 # end_lineno and end_col_offset are optional attributes, and they
202 # should be copied whether the value is None or not.
203 if value is not None or (
204 hasattr(old_node, attr) and attr.startswith("end_")
205 ):
206 setattr(new_node, attr, value)
207 return new_node
208
209
210def fix_missing_locations(node):

Callers

nothing calls this directly

Calls 4

getattrFunction · 0.85
hasattrFunction · 0.85
setattrFunction · 0.85
startswithMethod · 0.45

Tested by

no test coverage detected