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)
| 191 | |
| 192 | |
| 193 | def 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 | |
| 210 | def fix_missing_locations(node): |
nothing calls this directly
no test coverage detected