[ty] disallow explicit specialization of type variables themselves#21938
[ty] disallow explicit specialization of type variables themselves#21938carljm merged 7 commits intoastral-sh:mainfrom
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
b40e802 to
a4585f7
Compare
|
|
||
| T = TypeVar("T") | ||
| ImplicitPositive = T | ||
| Positive: TypeAlias = T |
There was a problem hiding this comment.
This usage seems to be used in bokeh, so we should allow it.
There was a problem hiding this comment.
For reference, pyright and pyrefly support both ImplicitPositive and Positive forms. Mypy supports only the explicit PEP 613 version.
With our current implementation of implicit type aliases, it would be quite difficult for us to distinguish ImplicitPositive from direct use of T. This may change in the future, but for now it seems fine to match mypy's support.
carljm
left a comment
There was a problem hiding this comment.
Looks good, thanks! A few nits, I will just make some minor updates and then merge.
|
|
||
| T = TypeVar("T") | ||
| ImplicitPositive = T | ||
| Positive: TypeAlias = T |
There was a problem hiding this comment.
For reference, pyright and pyrefly support both ImplicitPositive and Positive forms. Mypy supports only the explicit PEP 613 version.
With our current implementation of implicit type aliases, it would be quite difficult for us to distinguish ImplicitPositive from direct use of T. This may change in the future, but for now it seems fine to match mypy's support.
| /// `T = TypeVar("T")` | ||
| Legacy, | ||
| /// `Alias: typing.TypeAlias = T` | ||
| Pep613, |
There was a problem hiding this comment.
This variant is unlike the others -- it is not really a kind of typevar, but rather a kind of type alias -- a direct alias to a typevar.
I think this is the most direct implementation, but I would probably name and document this variant so as to emphasize its differentness more.
* origin/main: (22 commits) [ty] Allow gradual lower/upper bounds in a constraint set (#21957) [ty] disallow explicit specialization of type variables themselves (#21938) [ty] Improve diagnostics for unsupported binary operations and unsupported augmented assignments (#21947) [ty] update implicit root docs (#21955) [ty] Enable even more goto-definition on inlay hints (#21950) Document known lambda formatting deviations from Black (#21954) [ty] fix hover type on named expression target (#21952) Bump benchmark dependencies (#21951) Keep lambda parameters on one line and parenthesize the body if it expands (#21385) [ty] Improve resolution of absolute imports in tests (#21817) [ty] Support `__all__ += submodule.__all__` [ty] Change frequency of invalid `__all__` debug message [ty] Add `KnownUnion::to_type()` (#21948) [ty] Classify `cls` as class parameter (#21944) [ty] Stabilize rename (#21940) [ty] Ignore `__all__` for document and workspace symbol requests [ty] Attach db to background request handler task (#21941) [ty] Fix outdated version in publish diagnostics after `didChange` (#21943) [ty] avoid fixpoint unioning of types containing current-cycle Divergent (#21910) [ty] improve bad specialization results & error messages (#21840) ...
Summary
This PR makes explicit specialization of a type variable itself an error, and the result of the specialization is
Unknown.The change also fixes astral-sh/ty#1794.
Test Plan
mdtests updated
new corpus test