Walk a return annotation's union arms; return True iff any arm is the bare `Response` name (no `[T]` subscript). Handles both `X | Y` and `Union[X, Y]` union forms.
(returns: ast.expr)
| 506 | |
| 507 | |
| 508 | def _annotation_has_bare_response(returns: ast.expr) -> bool: |
| 509 | """Walk a return annotation's union arms; return True iff any arm is the |
| 510 | bare `Response` name (no `[T]` subscript). Handles both `X | Y` and |
| 511 | `Union[X, Y]` union forms.""" |
| 512 | pending: list[ast.expr] = [returns] |
| 513 | while pending: |
| 514 | node = pending.pop() |
| 515 | if isinstance(node, ast.BinOp) and isinstance(node.op, ast.BitOr): |
| 516 | pending.append(node.left) |
| 517 | pending.append(node.right) |
| 518 | continue |
| 519 | union_slice = _is_union_subscript(node) |
| 520 | if union_slice is not None: |
| 521 | if isinstance(union_slice, ast.Tuple): |
| 522 | pending.extend(union_slice.elts) |
| 523 | else: |
| 524 | pending.append(union_slice) |
| 525 | continue |
| 526 | if isinstance(node, ast.Name) and node.id == "Response": |
| 527 | return True |
| 528 | if isinstance(node, ast.Attribute) and node.attr == "Response": |
| 529 | # `rest_framework.response.Response` — bare attribute form |
| 530 | return True |
| 531 | return False |
| 532 | |
| 533 | |
| 534 | def _decorator_name(dec: ast.expr) -> str | None: |
no test coverage detected