Names bound LOCALLY inside a Python function: parameters plus assignment, `for`, `with ... as`, and comprehension targets. Used by the indirect-dispatch guard to reject a call-argument identifier that is a parameter or a local binding — it names a local value, not the module- level
(func_def_node, source: bytes)
| 3704 | return label_to_nid.get(callee) |
| 3705 | |
| 3706 | def _python_local_bound_names(func_def_node, source: bytes) -> set[str]: |
| 3707 | """Names bound LOCALLY inside a Python function: parameters plus assignment, |
| 3708 | `for`, `with ... as`, and comprehension targets. |
| 3709 | |
| 3710 | Used by the indirect-dispatch guard to reject a call-argument identifier that |
| 3711 | is a parameter or a local binding — it names a local value, not the module- |
| 3712 | level function/class that happens to share the name. Nested `function_definition` |
| 3713 | and `class_definition` subtrees are NOT descended into: their bindings belong |
| 3714 | to a different scope. |
| 3715 | """ |
| 3716 | bound: set[str] = set() |
| 3717 | bound |= _python_param_names(func_def_node.child_by_field_name("parameters"), source) |
| 3718 | |
| 3719 | def walk(n) -> None: |
| 3720 | for child in n.children: |
| 3721 | t = child.type |
| 3722 | if t in ("function_definition", "class_definition", "lambda"): |
| 3723 | continue # inner scope — its bindings are not this function's locals |
| 3724 | if t == "assignment": |
| 3725 | _python_collect_assignment_targets( |
| 3726 | child.child_by_field_name("left"), source, bound |
| 3727 | ) |
| 3728 | elif t in ("for_statement", "for_in_clause"): |
| 3729 | _python_collect_assignment_targets( |
| 3730 | child.child_by_field_name("left"), source, bound |
| 3731 | ) |
| 3732 | elif t == "with_statement": |
| 3733 | for item in child.children: |
| 3734 | if item.type == "with_clause": |
| 3735 | for wi in item.children: |
| 3736 | if wi.type == "with_item": |
| 3737 | alias = wi.child_by_field_name("alias") |
| 3738 | _python_collect_assignment_targets(alias, source, bound) |
| 3739 | elif t == "named_expression": # walrus := |
| 3740 | _python_collect_assignment_targets( |
| 3741 | child.child_by_field_name("name"), source, bound |
| 3742 | ) |
| 3743 | walk(child) |
| 3744 | |
| 3745 | body = func_def_node.child_by_field_name("body") |
| 3746 | if body is not None: |
| 3747 | walk(body) |
| 3748 | return bound |
| 3749 | |
| 3750 | def _python_module_bound_names(root, source: bytes) -> set[str]: |
| 3751 | """Names rebound by assignment at MODULE scope (top-level `x = ...`, `for`, walrus). |
no test coverage detected