Commit 5e75c25
typing: graduate tests.permissioning.* subpackage out of the mypy baseline (#1768)
Continues the mypy baseline drain tracked in #1738 (the #1331 → #1335 → #1447
cadence). After the config tail (#1748), this is the next cohesive batch
called out in the issue: the 18-module ``opencontractserver.tests.permissioning.*``
subpackage. Removes all 18 ``[mypy-…]`` ``ignore_errors`` blocks from ``mypy.ini``,
prunes the corresponding 313 lines from ``docs/typing/mypy_baseline.txt``
(5592 → 5279), and fixes the 162 errors that surface.
Most errors were the standard Django ``setUpTestData(cls)`` class-attribute
pattern flagged by mypy (recommended fix from #1479: annotate the assigned
names as class-level attributes before the ``@classmethod`` body).
One real production-code gap surfaced:
- ``CoreAgent`` Protocol was missing its public ``config: AgentConfig``
attribute (``opencontractserver/llms/agents/core_agents.py``). Five tests
read ``agent.config.tools`` / ``agent.config._approval_bypass_allowed``
directly off agents handed back by ``llm_agents.for_corpus(...)`` /
``for_document(...)``. The factory returns the ``CoreAgent`` Protocol;
the concrete ``CoreAgentBase`` initialises ``self.config = config`` in
``__init__``, but the Protocol never declared it. Added ``config:
AgentConfig`` to the Protocol body — captures the existing public API
contract without a behaviour change.
Per-file test fixes:
- ``test_query_optimizer_methods.py`` (108 errors): added class-level
annotations to ``AnalysisServicePermissionTestCase`` and
``DocumentPermissionFilterQueryCountTestCase`` covering every
``cls.<attr> = ...`` assignment inside ``setUpTestData``; switched
``User = get_user_model()`` to ``from opencontractserver.users.models
import User`` so the name is usable as a type annotation; replaced three
``qs.first().<attr>`` accesses with ``qs[0].<attr>`` after the
pre-existing ``qs.count() == 1`` guard.
- ``test_metadata_query_optimizer.py`` (15 errors): added ``assert status
is not None`` narrowings before indexing into the ``dict | None`` return
of ``MetadataService.get_metadata_completion_status``; one ``column is
not None`` narrowing in ``test_validate_column_valid``.
- ``test_permissioning.py`` (10 errors): same ``setUpTestData`` annotation
pattern on ``SetPermissionsIsNewTests``; same ``get_user_model()`` →
direct import switch.
- ``test_permissioned_querysets.py`` (8 errors): narrowed
``qs.query.select_related`` (``dict | bool``) via ``assert isinstance(...,
dict)`` before three ``assertIn`` calls; gave two ``PermissionQuerySet``
constructions explicit type annotations.
- ``test_public_and_permissions.py`` (7 errors): removed six unused
``# type: ignore[attr-defined]`` comments on ``Model.objects.acount()``
calls (django-stubs now ships proper async-manager typing).
- ``test_version_aware_query_optimizer.py`` (7 errors): replaced six
``result.first().id`` accesses with ``result[0].id`` after the
pre-existing ``result.count() == 1`` guard.
- ``test_custom_permission_filters.py`` (4 errors): replaced two
``assertIsNotNone`` calls with ``assert`` narrowings.
- ``test_creator_based_permissions.py`` (2 errors): narrow
``# type: ignore[arg-type]`` on the two ``get_users_permissions_for_obj
(instance=mock_instance, ...)`` calls (the test deliberately passes a
non-``Model`` mock to exercise the no-guardian-tables fallback).
- ``test_comment_permission.py`` (1 error): replaced one ``assertIsNotNone``
with ``assert`` for narrowing.
Pre-commit ``mypy`` continues to pass on the full project surface
(``mypy --config-file mypy.ini opencontractserver config`` → "Success: no
issues found in 1157 source files").
Refs #1738
Co-authored-by: Claude <noreply@anthropic.com>1 parent 7544cd5 commit 5e75c25
13 files changed
Lines changed: 91 additions & 405 deletions
File tree
- docs/typing
- opencontractserver
- llms/agents
- tests/permissioning
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
| |||
0 commit comments