Parameters with no annotation and no default that the body never rebinds: the ones pytest may fill with a fixture.
(func_node, source: bytes)
| 3375 | |
| 3376 | |
| 3377 | def _python_untouched_params(func_node, source: bytes) -> set[str]: |
| 3378 | """Parameters with no annotation and no default that the body never rebinds: |
| 3379 | the ones pytest may fill with a fixture.""" |
| 3380 | params = func_node.child_by_field_name("parameters") |
| 3381 | names: set[str] = set() |
| 3382 | if params is not None: |
| 3383 | for child in params.children: |
| 3384 | if child.type == "identifier": |
| 3385 | names.add(_read_text(child, source)) |
| 3386 | rebound: set[str] = set() |
| 3387 | body = func_node.child_by_field_name("body") |
| 3388 | stack = list(body.children) if body is not None else [] |
| 3389 | while stack: |
| 3390 | node = stack.pop() |
| 3391 | if node.type in ("function_definition", "class_definition", "lambda"): |
| 3392 | continue |
| 3393 | if node.type in ("assignment", "augmented_assignment", "for_statement", "for_in_clause"): |
| 3394 | _python_collect_assignment_targets(node.child_by_field_name("left"), source, rebound) |
| 3395 | elif node.type == "named_expression": |
| 3396 | _python_collect_assignment_targets(node.child_by_field_name("name"), source, rebound) |
| 3397 | elif node.type in ("as_pattern_target", "global_statement", "nonlocal_statement", "delete_statement"): |
| 3398 | stack_ids = [node] |
| 3399 | while stack_ids: |
| 3400 | cur = stack_ids.pop() |
| 3401 | if cur.type == "identifier": |
| 3402 | rebound.add(_read_text(cur, source)) |
| 3403 | stack_ids.extend(cur.children) |
| 3404 | stack.extend(node.children) |
| 3405 | return names - rebound - {"self", "cls"} |
| 3406 | |
| 3407 | |
| 3408 | def _python_is_test_module(str_path: str) -> bool: |
no test coverage detected