Repository navigation
ci: Type check bodies of core tests with mypy - #8318
Draft
sentrivana wants to merge 2 commits into
Draft
sentrivana wants to merge 2 commits into
sentrivana wants to merge 2 commits into
Conversation
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.
Contributor
Coverage Results 📊✅ 59241 passed | ⏭️ 3047 skipped | Total: 62288 | Pass Rate: 95.11% | Execution Time: 161m 54s 📊 Comparison with Base Branch
➖ Removed Tests (1)View removed tests
All tests are passing successfully. ✅ Patch coverage is 100.00% (no changed executable lines found; target 80%). Generated by Coverage Action |
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.
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 unusedtype: 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 inpyproject.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 asClient(**kwargs)was inferred too narrowly and produced one error perClientparameter. Annotating it asdict[str, Any]at four sites intest_client.pyremoved nearly half the errors.assert x is not Noneto narrow Optional values likeclient.transport,client.monitor,_propagation_contextandget_baggage().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.Event,MonitorConfig,SDKInfo,SpanLink) instead of plain dict literals.Scope(ty=...)takes realScopeTypevalues.os.sys.modulesbecomessys.modules.import importlib.utilintest_shadowed_module.py.socket.TCP_KEEPIDLEdoesn't exist on macOS, so its ignore also listsunused-ignore. That way mypy passes both locally on macOS and on Linux CI.