(body)
| 49 | scopes: dict[int, tuple[set[str], set[str]]] = {} |
| 50 | |
| 51 | def rebound_names(body) -> set[str]: |
| 52 | names: set[str] = set() |
| 53 | pending = list(body.named_children) |
| 54 | while pending: |
| 55 | node = pending.pop() |
| 56 | kind = node.type |
| 57 | if kind in ("function_definition", "class_definition"): |
| 58 | name = node.child_by_field_name("name") |
| 59 | if name is not None: |
| 60 | names.add(_read_text(name, source)) |
| 61 | elif kind == "global_statement": |
| 62 | names.update(_read_text(c, source) for c in node.named_children) |
| 63 | elif kind in ("import_statement", "import_from_statement"): |
| 64 | for item in node.children_by_field_name("name"): |
| 65 | alias = item.child_by_field_name("alias") |
| 66 | text = _read_text(item if alias is None else alias, source) |
| 67 | names.add(text.split(".")[0] if kind == "import_statement" else text) |
| 68 | elif kind != "lambda": |
| 69 | pending.extend(node.named_children) |
| 70 | return names |
| 71 | |
| 72 | def facts(scope, body) -> tuple[set[str], set[str]]: |
| 73 | if scope.id not in scopes: |
no test coverage detected