Skip to content

typing: graduate tests.test_admin* chunk out of the mypy baseline (#1738) - #2165

Closed
feiiiiii5 wants to merge 1 commit into
Open-Source-Legal:mainfrom
feiiiiii5:typing/graduate-tests-test-admin-chunk-1738
Closed

typing: graduate tests.test_admin* chunk out of the mypy baseline (#1738)#2165
feiiiiii5 wants to merge 1 commit into
Open-Source-Legal:mainfrom
feiiiiii5:typing/graduate-tests-test-admin-chunk-1738

Conversation

@feiiiiii5

Copy link
Copy Markdown

Part of #1738. Graduates the tests.test_admin* chunk (2 files) out of the mypy baseline — the Auth0 admin authentication tests + the Django admin views tests.

What changed

  • mypy.ini — removed 2 ignore_errors blocks:
    • [mypy-opencontractserver.tests.test_admin]
    • [mypy-opencontractserver.tests.test_admin_auth]
  • docs/typing/mypy_baseline.txt — pruned the corresponding 122 lines (2942 → 2820).

Per-file fixes

test_admin.py (6 errors)

  • Swapped the module-level User = get_user_model() alias for the concrete from opencontractserver.users.models import User import (mypy rejects a get_user_model() variable as a type annotation).
  • Widened two helper signatures from obj: object to obj: Model so _meta / pk resolve.
  • # type: ignore[arg-type] on CorpusAdmin(Corpus, None)ModelAdmin's second-arg AdminSite is genuinely optional at runtime but typed as required.
  • # type: ignore[method-assign] on the Mock() reassignment of message_user — intentional test isolation.

test_admin_auth.py (116 errors)

  • Same get_user_model() → direct import swap.
  • Class-level annotations on 7 TestCase classes that store User instances on setUpTestData(cls):
    • TestAdminClaimsSync.user
    • TestAuth0SuperuserAllowlist.user
    • TestAuth0AdminBackend.{staff_user, non_staff_user, inactive_staff, superuser}
    • TestAdminLoginView.{staff_user, regular_user}
    • TestAdminLogoutView.staff_user
    • TestGetUserByPayloadWithClaimSync.user
    • TestAdminLoginRateLimit.staff_user
  • 17 # type: ignore[attr-defined] on response.url redirects — django-stubs' _MonkeyPatchedWSGIResponse doesn't expose .url even though Django's test client always sets it on 302s.

Verification

  • mypy --config-file mypy.ini opencontractserver config → `Success: no issues found in 1513 source files` (both pre-commit mypy==2.0.0 and CI mypy==2.1.0 pins).
  • python scripts/collate_changelog.py --check → `OK: 252 changelog fragment(s) valid`.
  • No production code changed.

Patterns used (consistent with earlier #1738 graduation passes)

…en-Source-Legal#1738)

Removed the two `[mypy-opencontractserver.tests.test_admin]` and
`[mypy-opencontractserver.tests.test_admin_auth]` `ignore_errors` blocks
and pruned the corresponding 122 lines from `docs/typing/mypy_baseline.txt`
(2942 → 2820). Fixes follow the established patterns from earlier Open-Source-Legal#1738
graduation passes — the `get_user_model()` → direct `User` import swap,
class-level annotations for `setUpTestData` attributes, and `# type: ignore`
on Django-stubs gaps (`_MonkeyPatchedWSGIResponse.url`, `ModelAdmin`'s
optional `AdminSite`).

No production code changed. The full project surface (`mypy --config-file
mypy.ini opencontractserver config`) stays clean under both the pre-commit
pin (`mypy==2.0.0`) and CI's pin (`mypy==2.1.0`).
@feiiiiii5

Copy link
Copy Markdown
Author

Closing this typing cleanup — I'm trimming my open PRs and won't be actively following up on it. The mypy-baseline graduation stands on its own if it's wanted later; the branch stays on my fork for an easy reopen. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant