Skip to content

[ty] Emit errors on invalid TypeVar defaults#23194

Merged
charliermarsh merged 5 commits intomainfrom
charlie/typevar-validation
Feb 10, 2026
Merged

[ty] Emit errors on invalid TypeVar defaults#23194
charliermarsh merged 5 commits intomainfrom
charlie/typevar-validation

Conversation

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Feb 10, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 10, 2026

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 82.45% to 82.54%. The percentage of expected errors that received a diagnostic increased from 73.38% to 73.84%.

Summary

Metric Old New Diff Outcome
True Positives 794 799 +5 ⏫ (✅)
False Positives 169 169 +0
False Negatives 288 283 -5 ⏬ (✅)
Total Diagnostics 963 968 +5
Precision 82.45% 82.54% +0.09% ⏫ (✅)
Recall 73.38% 73.84% +0.46% ⏫ (✅)

True positives added

Details
Location Name Message
generics_defaults.py:107:51 invalid-type-variable-default TypeVar default is not assignable to the TypeVar's upper bound
generics_defaults.py:114:52 invalid-type-variable-default TypeVar default is inconsistent with the TypeVar's constraints: int is not one of the constraints of Invalid2
generics_defaults_referential.py:68:40 invalid-type-variable-default Default X1 of TypeVar Invalid1 is not assignable to upper bound str of Invalid1 because its upper bound int is not assignable to str
generics_defaults_referential.py:74:52 invalid-type-variable-default TypeVar default is inconsistent with the TypeVar's constraints: Bounded TypeVar cannot be used as the default for a constrained TypeVar
generics_defaults_referential.py:78:63 invalid-type-variable-default Default Y2 of TypeVar AlsoInvalid2 is inconsistent with its constraints AlsoInvalid2 because constraint int of Y2 is not one of the constraints of AlsoInvalid2

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 10, 2026

mypy_primer results

Changes were detected when running on open source projects
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/deployments/runner.py:1017:70: warning[possibly-missing-attribute] Attribute `__name__` may be missing on object of type `Unknown | (((...) -> Any) & ((*args: object, **kwargs: object) -> object))`
+ src/prefect/deployments/runner.py:1017:70: warning[possibly-missing-attribute] Attribute `__name__` may be missing on object of type `Unknown | ((...) -> Any)`
+ src/prefect/flow_engine.py:1004:32: error[invalid-await] `Unknown | R@FlowRunEngine | Coroutine[Any, Any, R@FlowRunEngine]` is not awaitable
+ src/prefect/flow_engine.py:1610:24: error[invalid-await] `Unknown | R@AsyncFlowRunEngine | Coroutine[Any, Any, R@AsyncFlowRunEngine]` is not awaitable
+ src/prefect/flow_engine.py:1691:43: error[invalid-argument-type] Argument to function `next` is incorrect: Expected `SupportsNext[Unknown]`, found `Unknown | R@run_generator_flow_sync`
+ src/prefect/flow_engine.py:1699:21: warning[possibly-missing-attribute] Attribute `throw` may be missing on object of type `Unknown | R@run_generator_flow_sync`
+ src/prefect/flow_engine.py:1733:44: warning[possibly-missing-attribute] Attribute `__anext__` may be missing on object of type `Unknown | R@run_generator_flow_async`
+ src/prefect/flow_engine.py:1740:25: warning[possibly-missing-attribute] Attribute `throw` may be missing on object of type `Unknown | R@run_generator_flow_async`
- src/prefect/flows.py:286:34: error[unresolved-attribute] Object of type `((**P@Flow) -> R@Flow) & ((*args: object, **kwargs: object) -> object)` has no attribute `__name__`
+ src/prefect/flows.py:286:34: error[unresolved-attribute] Object of type `(**P@Flow) -> R@Flow` has no attribute `__name__`
- src/prefect/flows.py:404:68: error[unresolved-attribute] Object of type `((**P@Flow) -> R@Flow) & ((*args: object, **kwargs: object) -> object)` has no attribute `__name__`
+ src/prefect/flows.py:404:68: error[unresolved-attribute] Object of type `(**P@Flow) -> R@Flow` has no attribute `__name__`
- src/prefect/flows.py:1886:53: warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ src/prefect/flows.py:1946:21: error[no-matching-overload] No overload of function `run_coro_as_sync` matches arguments
- Found 5499 diagnostics
+ Found 5505 diagnostics

setuptools (https://github.com/pypa/setuptools)
+ setuptools/_distutils/command/install.py:719:42: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `map[str]`
- Found 1126 diagnostics
+ Found 1127 diagnostics

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 50 diagnostics
+ Found 49 diagnostics

sympy (https://github.com/sympy/sympy)
+ sympy/parsing/mathematica.py:692:38: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `Unknown | list[Unknown | str]`
- Found 16053 diagnostics
+ Found 16054 diagnostics

@charliermarsh charliermarsh force-pushed the charlie/typevar-validation branch from bbec421 to e6e0dfc Compare February 10, 2026 02:43
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 10, 2026

Memory usage report

Summary

Project Old New Diff Outcome
prefect 710.08MB 710.08MB +0.0% (0.00MB)
trio 123.94MB 123.95MB +0.0% (0.00MB)
sphinx 282.30MB 282.30MB +0.0% (0.00MB)
flake8 51.85MB 51.85MB +0.0% (0.00MB)

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
infer_deferred_types 0.74MB 0.74MB +0.0% (0.00MB)

prefect

Name Old New Diff Outcome
TypeVarConstraints 0.00MB 0.00MB +23.0% (0.00MB)
infer_deferred_types 14.98MB 14.98MB +0.0% (0.00MB)

sphinx

Name Old New Diff Outcome
TypeVarConstraints 0.00MB 0.00MB +21.0% (0.00MB)
infer_deferred_types 6.10MB 6.10MB +0.0% (0.00MB)

trio

Name Old New Diff Outcome
TypeVarConstraints 0.00MB 0.00MB +21.0% (0.00MB)
infer_deferred_types 2.56MB 2.56MB +0.0% (0.00MB)

@ibraheemdev
Copy link
Member

(I will fix that memory report 🙃)

@charliermarsh charliermarsh force-pushed the charlie/typevar-validation branch from e6e0dfc to 2650bd1 Compare February 10, 2026 02:48
@charliermarsh charliermarsh marked this pull request as ready for review February 10, 2026 02:51
@charliermarsh charliermarsh force-pushed the charlie/typevar-validation branch from 2650bd1 to c214253 Compare February 10, 2026 02:58
@AlexWaygood AlexWaygood self-assigned this Feb 10, 2026
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think we can make some of these diagnostics a bit more helpful for users

@charliermarsh charliermarsh marked this pull request as draft February 10, 2026 16:02
@charliermarsh charliermarsh force-pushed the charlie/typevar-validation branch from 291173f to 5b2322c Compare February 10, 2026 16:03
@charliermarsh charliermarsh marked this pull request as ready for review February 10, 2026 16:21
@AlexWaygood
Copy link
Member

Thanks! I pushed some updates so that the diagnostics now look something like this:

image

@charliermarsh charliermarsh merged commit 02c67e2 into main Feb 10, 2026
50 checks passed
@charliermarsh charliermarsh deleted the charlie/typevar-validation branch February 10, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit errors on invalid defaulted TypeVar constructions

3 participants