ast parse and prefix names with `.` to avoid collision with user vars
(src: str, expected_type: type[_ASTT])
| 297 | |
| 298 | |
| 299 | def _prefix_names(src: str, expected_type: type[_ASTT]) -> _ASTT: |
| 300 | """ast parse and prefix names with `.` to avoid collision with user vars""" |
| 301 | tree: ast.AST = ast.parse(src).body[0] |
| 302 | if isinstance(tree, ast.Expr): |
| 303 | tree = tree.value |
| 304 | if not isinstance(tree, expected_type): |
| 305 | raise TypeError( |
| 306 | f"AST node is of type {type(tree).__name__}, not {expected_type.__name__}" |
| 307 | ) |
| 308 | for node in ast.walk(tree): |
| 309 | if isinstance(node, ast.Name): |
| 310 | node.id = f".{node.id}" |
| 311 | return tree |
| 312 | |
| 313 | |
| 314 | _CALL_CONVERTER_CODE_FMT = "self._converters[{elem!r}].to_url()" |
no test coverage detected