MCPcopy Create free account
hub / github.com/getsentry/sentry / _annotation_has_bare_response

Function _annotation_has_bare_response

tools/flake8_plugin.py:508–531  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

506
507
508def _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
534def _decorator_name(dec: ast.expr) -> str | None:

Callers 1

_check_S022Method · 0.85

Calls 4

_is_union_subscriptFunction · 0.85
appendMethod · 0.65
popMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected