Plain parameter identifiers declared on a Python `parameters` node. Covers positional/keyword params plus `*args` / `**kwargs` and typed or default forms — anything that binds a local name the function body can shadow a module-level definition with.
(params_node, source: bytes)
| 5 | |
| 6 | |
| 7 | def _python_param_names(params_node, source: bytes) -> set[str]: |
| 8 | """Plain parameter identifiers declared on a Python `parameters` node. |
| 9 | |
| 10 | Covers positional/keyword params plus `*args` / `**kwargs` and typed or |
| 11 | default forms — anything that binds a local name the function body can shadow |
| 12 | a module-level definition with. |
| 13 | """ |
| 14 | out: set[str] = set() |
| 15 | if params_node is None: |
| 16 | return out |
| 17 | for child in params_node.children: |
| 18 | if child.type == "identifier": |
| 19 | out.add(_read_text(child, source)) |
| 20 | elif child.type in ( |
| 21 | "typed_parameter", |
| 22 | "default_parameter", |
| 23 | "typed_default_parameter", |
| 24 | "list_splat_pattern", |
| 25 | "dictionary_splat_pattern", |
| 26 | ): |
| 27 | # The bound name is the first identifier child (the rest is type/default). |
| 28 | name_n = child.child_by_field_name("name") |
| 29 | if name_n is None: |
| 30 | name_n = next( |
| 31 | (c for c in child.children if c.type == "identifier"), None |
| 32 | ) |
| 33 | if name_n is not None: |
| 34 | out.add(_read_text(name_n, source)) |
| 35 | return out |
| 36 | |
| 37 | |
| 38 | def _python_param_shadow_checker(source: bytes): |
no test coverage detected