typing: graduate tests.test_annotation_* chunk out of mypy baseline#1776
Conversation
…eline Continues issue #1738's drain (the #1331 → #1335 → #1447 cadence). The `annotation` domain chunk from the issue's tests.* leaf-files batching plan, following the tests.permissioning.* subpackage in PR #1768. Removes all 6 [mypy-opencontractserver.tests.test_annotation_*] ignore_errors blocks from mypy.ini, prunes the corresponding 138 lines from docs/typing/mypy_baseline.txt (5279 → 5141), and fixes the errors that surface under the current mypy / django-stubs pins. Per-file changes: - test_annotation_admin.py: class-level annotations on TestAnnotationAdmin for every cls.<attr> in setUpTestData; get_user_model() → direct User import. - test_annotation_images_api.py: class-level annotations on AnnotationImagesAPITestCase; same User import switch (also clears the valid-type error on the `owner: User` parameter). - test_annotation_permission_mutations.py: no code change; the historical set_permissions_for_obj_to_user arg-type errors no longer reproduce. - test_annotation_privacy.py: same as above. - test_annotation_tree.py: rename self.client → self.graphene_client on AnnotationTreeTestCase so the graphene Client no longer shadows the inherited django.test.TestCase.client (mypy resolved .execute through Django's Client); replace one assertIsNotNone with `assert ... is not None` narrowing; same User import switch. - test_annotation_utils.py: class-level annotations on the two TestCases; scoped # type: ignore[arg-type] on the two compute_content_modalities calls that deliberately pass mixed/invalid items to exercise defensive skipping; same User import switch. Refs #1738
Code Review — PR #1776: Graduate
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Signed-off-by: JSIV <5049984+JSv4@users.noreply.github.com>
Code Review: PR #1776 —
|
| Category | Assessment |
|---|---|
| Correctness | ✅ All changes are behaviour-neutral |
| mypy compliance | ✅ Clears 138 baseline errors across 6 modules |
| Code style | ✅ Consistent with project conventions |
| Test coverage | ✅ No test logic changed, no regression risk |
| Security | ✅ N/A (test-only changes) |
| CHANGELOG | ✅ Thorough and accurate |
No blocking issues. The minor points above are informational only.
…#1851) * typing: graduate tests.test_document_* chunk out of mypy baseline Continues the mypy baseline drain (issue #1738), following the annotation chunk (PR #1776). Removes the 12 [mypy-opencontractserver.tests.test_document_*] ignore_errors blocks from mypy.ini, prunes the corresponding 331 lines from docs/typing/mypy_baseline.txt (5141 -> 4810), and fixes the 243 errors that surface under the pinned mypy==2.0.0 / django-stubs==6.0.5. Fixes use the established patterns from prior chunks: class-level annotations for setUpClass/setUpTestData attributes, User = get_user_model() -> direct import, the graphene self.client -> self.graphene_client rename, typed list[IndexEntryItem] / OpenContractsAnnotationPythonType literal annotations, and assert-based None narrowing. Typing self.doc as Document in test_document_index_tool also revealed a latent FieldFile.name (str | None) gap in four setUp methods (previously masked behind the attr-defined Any), now narrowed. Full surface: mypy --config-file mypy.ini opencontractserver config -> "Success: no issues found in 1242 source files". Refs #1738 * Address review: explain dual-role MockContext in path-caching test The MockContext class serves as both the GraphQL info object (its .context is read) and the inner context object (its .user is read), mirroring the info.context.user access chain — so it declares both attributes even though any single instance populates only one. Add a comment so the self-referential context: 'MockContext' annotation doesn't read as spurious. (The 'Generated by Claude Code' footer was also removed from the PR body.) --------- Co-authored-by: Claude <noreply@anthropic.com>
Continues the mypy baseline drain (issue Open-Source-Legal#1738, the Open-Source-Legal#1331 -> Open-Source-Legal#1335 -> Open-Source-Legal#1447 cadence). After the config tail (Open-Source-Legal#1748), tests.permissioning.* (Open-Source-Legal#1768), and the annotation (Open-Source-Legal#1776) / document (Open-Source-Legal#1851) / corpus (Open-Source-Legal#1866) / agent (Open-Source-Legal#1877) leaf-file chunks, this is the next cohesive batch from the issue's tests.* batching plan: the extract domain. Removes the 6 [mypy-opencontractserver.tests.test_*] ignore_errors blocks for the structured-data-extraction feature -- Extracts plus their Fieldsets/Columns, Datacells, and metadata columns (all in opencontractserver/extracts/models.py): test_extract_mutations, test_extract_queries, test_extract_tasks, test_datacell_mutations, test_column_mutations, test_metadata_columns_graphql. Prunes the corresponding 57 lines from docs/typing/mypy_baseline.txt (3648 -> 3591) and fixes the 42 errors that surface. Every surfaced error was the same: a graphene.test.Client assigned to self.client shadows django.test.TestCase.client (which has no .execute()). Renamed self.client -> self.graphene_client in the 5 GraphQL test modules -- a behaviour-equivalent rename, since the assignment already shadowed the Django client at runtime and every read was .execute(). test_extract_tasks needed no code change: its historical set_permissions_for_obj_to_user arg-type errors no longer reproduce under django-stubs==6.0.5. 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). Refs Open-Source-Legal#1738
Summary
Continues the mypy baseline drain tracked in #1738 (the
#1331 → #1335 → #1447cadence). After theconfig.*tail (PR #1748) and thetests.permissioning.*subpackage (PR #1768), this is the next cohesive batch called out in the issue's batching plan: theannotationdomain chunk of thetests.*leaf-files (6 files).Removes all 6
[mypy-opencontractserver.tests.test_annotation_*]ignore_errorsblocks frommypy.ini, prunes the corresponding 138 lines fromdocs/typing/mypy_baseline.txt(5279 → 5141), and fixes the errors that surface under the currentmypy==2.1.0/django-stubs==6.0.4pins.After this PR:
opencontractserver.mcp.tests.test_mcpand the remainingopencontractserver.tests.*leaf-file modules remain on the baseline, per the issue's batching plan.Per-file fixes
test_annotation_admin.pyTestAnnotationAdminfor everycls.<attr> = …insidesetUpTestData(superuser,corpus,document,annotation_label,annotation,annotation2,embedding_384,embedding2_384a,embedding2_384b); switchedUser = get_user_model()to a directfrom opencontractserver.users.models import User.test_annotation_images_api.pyAnnotationImagesAPITestCase(user,other_user,label_set,annotation_label,corpus); sameget_user_model()→ direct import switch (also resolves thevalid-typeerror on theowner: Userparameter at_create_test_document_with_images).test_annotation_permission_mutations.pyset_permissions_for_obj_to_userarg-typeerrors no longer reproduce under the current pins.test_annotation_privacy.pyarg-typeerrors no longer reproduce.test_annotation_tree.pyself.client→self.graphene_clientonAnnotationTreeTestCaseso the assignment of agraphene.test.Clientno longer shadows the inheriteddjango.test.TestCase.clientattribute (mypy was resolving.execute(...)through Django'sClient, which has no.execute()method; the tests only ever use the GraphQL client, so the rename is behaviour-equivalent and matches the project convention inpermissioning/test_permissioning.py); replaced oneassertIsNotNone(root_node)with anassert root_node is not Nonenarrowing; sameget_user_model()→ direct import switch.test_annotation_utils.pyTestComputeContentModalitiesWithDocument(user,corpus) andTestUpdateAnnotationModalities(user,corpus,label); scoped two# type: ignore[arg-type]comments on the twocompute_content_modalitiescalls that deliberately pass mixed/invalid items (["invalid_string", None, 123, {...}]and["not_a_dict", None, {...}]) to exercise the function's defensive skipping paths; sameget_user_model()→ direct import switch.All test behaviour is preserved — the changes are either no-ops at runtime (class-level annotations,
assertvsassertIsNotNone) or behaviour-equivalent renames (self.client→self.graphene_client— the rename masks the inherited Django test client, but the original code already shadowed it at runtime by assignment, so no test relied on it).Test plan
mypy --config-file mypy.ini opencontractserver config→Success: no issues found in 1157 source files(the acceptance gate per Continue draining the mypy baseline established in #1331 — test suite + config tail #1738)black/isort/flake8/pyupgradeclean on all changed filespy_compilesmoke test)backend.ymllinter + test jobs) — the authoritative runtime checkRefs #1738
Generated by Claude Code