Repository navigation
Conversation
gricha
force-pushed
the
ref/mypy-request-user-principal
branch
from
October 31, 2026 01:29
54aacbe to
a6954ca
Compare
gricha
changed the base branch from
ref/principal-helper-examples
to
ref/sa-narrow-widen
November 1, 2026 04:24
gricha
force-pushed
the
ref/mypy-request-user-principal
branch
from
November 1, 2026 04:24
a6954ca to
8d3da3d
Compare
This was referenced Nov 1, 2026
Contributor
Sentry Snapshot Testing
|
…list request.user on a DRF Request can be a ServiceAccountPrincipal, but mypy didn't know, so nothing forced callers to narrow. The mypy plugin now types it as User | AnonymousUser | ServiceAccountPrincipal, except in the 23 files on tools/mypy_helpers/request_user_allowlist.txt, which keep today's type. ServiceAccountPrincipal.id is hidden from mypy but still raises UserRequired at runtime. A test fails if the allowlist grows or lists a deleted file.
gricha
force-pushed
the
ref/mypy-request-user-principal
branch
from
November 1, 2026 04:57
8d3da3d to
9be4ce4
Compare
This branch has not been deployed
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.
mypy now types DRF
request.userasUser | AnonymousUser | ServiceAccountPrincipal, except in files ontools/mypy_helpers/request_user_allowlist.txt. Those keep today's type, so mypy stays green, while every other file must narrow before it reads user-only attributes.rest_framework.request.Request.userreturns the union outside the allowlist.report_config_datarechecks a cached module when it joins or leaves the list.ServiceAccountPrincipal.idis hidden from mypy (if not TYPE_CHECKING) but kept at runtime, soServiceAccountIdstill guards unconverted reads.features.batch_has(3) and 11 one-offs. A test fails if the list grows or names a deleted file, and another fails if the hook stops applying.No runtime change. It lands after the fixes: the PRs below narrow the rest, and each later fix removes its files from the list.