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

Function _is_union_subscript

tools/flake8_plugin.py:453–465  ·  view source on GitHub ↗

Slice of `Union[...]` / `Optional[...]`, bare or `typing.`-prefixed. `Optional[X]`'s implicit `None` arm cannot encode a bare `Response`, so unwrapping `X` alone is enough.

(node: ast.expr)

Source from the content-addressed store, hash-verified

451
452
453def _is_union_subscript(node: ast.expr) -> ast.expr | None:
454 """Slice of `Union[...]` / `Optional[...]`, bare or `typing.`-prefixed.
455
456 `Optional[X]`'s implicit `None` arm cannot encode a bare `Response`, so
457 unwrapping `X` alone is enough."""
458 if not isinstance(node, ast.Subscript):
459 return None
460 val = node.value
461 if isinstance(val, ast.Name) and val.id in _UNION_NAMES:
462 return node.slice
463 if isinstance(val, ast.Attribute) and val.attr in _UNION_NAMES:
464 return node.slice
465 return None
466
467
468def _extract_response_annotation_Ts(returns: ast.expr | None) -> list[ast.expr] | None:

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected