[ty] disallow type variables within type variable bounds/constraints#21984
[ty] disallow type variables within type variable bounds/constraints#21984mtshiba wants to merge 1 commit intoastral-sh:mainfrom
Conversation
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-12-23 21:37:03.629255814 +0000
+++ new-output.txt 2025-12-23 21:37:05.796265312 +0000
@@ -586,6 +586,8 @@
generics_syntax_infer_variance.py:154:38: error[invalid-assignment] Object of type `ShouldBeInvariant5[int]` is not assignable to `ShouldBeInvariant5[int | float]`
generics_syntax_infer_variance.py:165:45: error[invalid-assignment] Object of type `ShouldBeContravariant1[int]` is not assignable to `ShouldBeContravariant1[int | float]`
generics_syntax_infer_variance.py:166:43: error[invalid-assignment] Object of type `ShouldBeContravariant1[int | float]` is not assignable to `ShouldBeContravariant1[int]`
+generics_syntax_scoping.py:14:20: error[invalid-type-variable-bound] Type variable bound type cannot be generic
+generics_syntax_scoping.py:18:17: error[invalid-type-variable-bound] Type variable bound type cannot be generic
generics_syntax_scoping.py:35:7: error[unresolved-reference] Name `T` used when not defined
generics_syntax_scoping.py:40:23: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `((**P@decorator1) -> R@decorator1, /) -> (**P@decorator1) -> R@decorator1`
generics_syntax_scoping.py:44:17: error[unresolved-reference] Name `T` used when not defined
@@ -1033,4 +1035,4 @@
typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
typeddicts_usage.py:28:18: error[invalid-key] Unknown key "title" for TypedDict `Movie`: Unknown key "title"
typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions
-Found 1035 diagnostics
+Found 1037 diagnostics
|
|
5aa3477 to
e59740e
Compare
|
Probably unrelated to this PR, but the error messages in pydantic seem to change non-deterministically. |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-return-type |
0 | 1 | 4 |
invalid-argument-type |
0 | 3 | 1 |
invalid-type-variable-bound |
4 | 0 | 0 |
| Total | 4 | 4 | 5 |
Yes, unfortunately this non-determinism in the error messages in some projects (and occasionally non-determinism of the presence/absence of a few diagnostics also) was introduced with the |
e59740e to
d628e32
Compare
|
I rebased on main, but it seems that some other recent change in main means that we no longer emit the diagnostics for typevars with self-referential bounds/constraints. |
|
Replaced by #22949 |
That PR only did legacy type variables; we still don't validate PEP-695 parameters on |
…traints (#22982) ## Summary This is a revival of #21984. Legacy typevar checks were already supported in #22949. This PR addresses PEP-695 typevars. ## Test Plan mdtest updated --------- Co-authored-by: Ibraheem Ahmed <[email protected]>
Summary
This PR resolves astral-sh/ty#1839.
Test Plan
mdtests updated