When you compile a node tree with compile(), the compiler expects lineno and col_offset attributes for every node that supports them. This is rather tedious to fill in for generated nodes, so this helper adds these attributes recursively where not already set, by setting them to th
(node)
| 222 | |
| 223 | |
| 224 | def fix_missing_locations(node): |
| 225 | """ |
| 226 | When you compile a node tree with compile(), the compiler expects lineno and |
| 227 | col_offset attributes for every node that supports them. This is rather |
| 228 | tedious to fill in for generated nodes, so this helper adds these attributes |
| 229 | recursively where not already set, by setting them to the values of the |
| 230 | parent node. It works recursively starting at *node*. |
| 231 | """ |
| 232 | def _fix(node, lineno, col_offset, end_lineno, end_col_offset): |
| 233 | if 'lineno' in node._attributes: |
| 234 | if not hasattr(node, 'lineno'): |
| 235 | node.lineno = lineno |
| 236 | else: |
| 237 | lineno = node.lineno |
| 238 | if 'end_lineno' in node._attributes: |
| 239 | if getattr(node, 'end_lineno', None) is None: |
| 240 | node.end_lineno = end_lineno |
| 241 | else: |
| 242 | end_lineno = node.end_lineno |
| 243 | if 'col_offset' in node._attributes: |
| 244 | if not hasattr(node, 'col_offset'): |
| 245 | node.col_offset = col_offset |
| 246 | else: |
| 247 | col_offset = node.col_offset |
| 248 | if 'end_col_offset' in node._attributes: |
| 249 | if getattr(node, 'end_col_offset', None) is None: |
| 250 | node.end_col_offset = end_col_offset |
| 251 | else: |
| 252 | end_col_offset = node.end_col_offset |
| 253 | for child in iter_child_nodes(node): |
| 254 | _fix(child, lineno, col_offset, end_lineno, end_col_offset) |
| 255 | _fix(node, 1, 0, 1, 0) |
| 256 | return node |
| 257 | |
| 258 | |
| 259 | def increment_lineno(node, n=1): |
nothing calls this directly
no test coverage detected
searching dependent graphs…