Skip to content

ci: Type check bodies of core tests with mypy - #8318

Draft
sentrivana wants to merge 2 commits into
masterfrom
ivana/typecheck-core-tests
Draft

sentrivana wants to merge 2 commits into
masterfrom
ivana/typecheck-core-tests

Conversation

@sentrivana

@sentrivana sentrivana commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Part of https://linear.app/getsentry/issue/PY-3084/add-meaningful-check-to-mypy

Follow-up to #8316. For tests that don't depend on third-party packages (tests/test_*.py, tests/tracing, tests/profiler, tests/utils), mypy now also checks the bodies of untyped functions (check_untyped_defs) and reports unused type: ignores again. This means calls these tests make into the SDK are checked against its signatures, which is the part that catches tests drifting from the API. Integration tests keep the lenient settings from #8316.

The config change is the second [[tool.mypy.overrides]] block in pyproject.toml. It uses wildcards on purpose, so new core test files are checked strictly by default.

Fixes to the errors this surfaced, roughly by volume:

  • kwargs = {} passed as Client(**kwargs) was inferred too narrowly and produced one error per Client parameter. Annotating it as dict[str, Any] at four sites in test_client.py removed nearly half the errors.
  • assert x is not None to narrow Optional values like client.transport, client.monitor, _propagation_context and get_baggage().
  • Targeted type: ignore[...] where tests pass invalid input on purpose (e.g. test_ai_monitoring's non-dict content parts, NotAnException(), object() pushed into batcher buffers). These are the cases mypy is supposed to flag.
  • The SDK's TypedDicts (Event, MonitorConfig, SDKInfo, SpanLink) instead of plain dict literals.
  • Small cleanups:
    • Scope(ty=...) takes real ScopeType values.
    • Logger mocks use the patched mock directly.
    • os.sys.modules becomes sys.modules.
    • Missing import importlib.util in test_shadowed_module.py.
    • Five ignores that turned out to be unnecessary are removed.

socket.TCP_KEEPIDLE doesn't exist on macOS, so its ignore also lists unused-ignore. That way mypy passes both locally on macOS and on Linux CI.

Enable check_untyped_defs and warn_unused_ignores for tests that don't depend on third-party packages (tests/test_*.py, tests/tracing, tests/profiler, tests/utils), so calls into the SDK are checked against its signatures.

Fix the errors this surfaced: narrow Optional values with asserts, use the SDK's TypedDicts instead of plain dicts, mark intentionally invalid inputs with targeted ignores, and remove ignores that were never needed.
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 59241 passed | ⏭️ 3047 skipped | Total: 62288 | Pass Rate: 95.11% | Execution Time: 161m 54s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +9
Passed Tests 📈 +9
Failed Tests 📉 -1
Skipped Tests 📈 +1

➖ Removed Tests (1)

View removed tests
  • test_execution_outcome[start_sync_execution-FAILED-stepfunctions_execution_failed]
    • File: tests.integrations.boto3.test_stepfunctions

All tests are passing successfully.

✅ Patch coverage is 100.00% (no changed executable lines found; target 80%).
Project statement coverage is 90.08%.


Generated by Coverage Action

@linear-code

linear-code Bot commented Nov 17, 2026

Copy link
Copy Markdown

PY-3084

Base automatically changed from major/3.0 to master November 23, 2026 08:56

This branch has not been deployed

No deployments
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