chore: switch to ty type checker #19835
Draft
+78
−14
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.
summary
pytest-mypy-pluginstypesafety tests intests/typesafety/approach
starting with permissive rules - all ~1100 existing errors are ignored for now and can be gradually enabled as we fix them.
fast-follow PRs
here's a breakdown of the error categories, roughly in order of ease/impact:
1.
invalid-parameter-default(71 errors) - easy winsmostly fastapi endpoints with
param: SomeFilter = Nonethat should beparam: SomeFilter | None = None:2.
unresolved-import(18 errors) - conditional importsimports inside try/except blocks for optional dependencies (pendulum, logfire, apprise plugins). ty doesn't understand these are guarded - may need
# ty: ignorecomments or restructuring.3.
invalid-assignment(95 errors) - mixed bag__init__in deprecation decorators (~10 errors)4.
invalid-return-type(134 errors) - generic type issuesmany in
_internal/concurrency/whereCall[T].result()returnsTbut ty infersUnknown. likely needs better type annotations on theCallclass.5.
invalid-argument-type(370 errors) - largest categorycast_to_call,call_soon_in_*)6.
unresolved-attribute(134 errors) - dynamic attributes__name__on wrapped functions - ty doesn't understand@wrapstypeobjects - Block class introspectionsys.maxintin vendored croniter (py2 compat)threading._register_atexit)7.
possibly-missing-attribute(139 warnings) - optional checksOptional[X]used without None checks. mostly in task/flow engine code where we know the attribute exists at runtime.8.
invalid-method-override(23 errors) - inheritance issuessubclasses with incompatible method signatures. needs investigation.
9. other smaller categories
non-subscriptable(27) - likely type annotation issuesinvalid-await(25) - async/sync confusion in type stubsno-matching-overload(18) - overload resolution failureschanges
ty>=0.0.2to dev dependencies[tool.ty]config to pyproject.toml with permissive rulestesting
references
🤖 Generated with Claude Code