ref: Lint PUBLIC endpoints for typed return annotations#117356
Merged
Conversation
Adds a check to the apidocs response-annotation linter: any HTTP method declared `ApiPublishStatus.PUBLIC` in `publish_status` must annotate its return with `Response[T]`, a union of `Response[T_i]` arms (optionally mixed with non-`Response` Django response types), or a concrete non-DRF type. Bare `-> Response` and missing annotations are errors. PUBLIC endpoints are documented in OpenAPI and consumed by SDK generators; an untyped body lets the runtime drift from the declared schema. The diagnostic includes a copy-able fix template and a pointer to `sentry.apidocs.response_types` for standard error shapes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2f7e645 to
970358e
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 970358e. Configure here.
gricha
approved these changes
Jun 10, 2026
Locks down that `from __future__ import annotations` doesn't change what the AST-based bare-`Response` check sees — the future import is a runtime-evaluation directive, not a parse-time one, so `ast.parse()` still produces a `Name` node for `Response` regardless. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Extends the PUBLIC-untyped check to handle two additional AST shapes:
- `publish_status: dict[str, ApiPublishStatus] = {...}` (annotated
assignment) is now read alongside the plain-assignment form.
- `Union[Response, Response[T]]` (typing.Union syntax) is now walked
the same way `X | Y` BinOps already were; a bare-`Response` arm in
either form fires the diagnostic.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds `Optional` to the union-subscript walker so `-> Optional[Response]` is recognized as a bare-`Response` arm. `Optional[X]` is `Union[X, None]` semantically, so unwrapping the `X` arm is sufficient (`None` can't introduce a bare `Response`). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds a check to the apidocs response-annotation linter: any HTTP method declared
ApiPublishStatus.PUBLICinpublish_statusmust annotate its return withResponse[T], a union ofResponse[T_i]arms (optionally mixed with non-ResponseDjango response types), or a concrete non-DRF type. Bare-> Responseand missing annotations are errors.PUBLIC endpoints are documented in OpenAPI and consumed by SDK generators; an untyped body lets the runtime drift from the declared schema. The diagnostic includes a copy-able fix template and a pointer to
sentry.apidocs.response_typesfor standard error shapes.