Commit e6ddeed
authored
[ty] Default-specialization of generic type aliases (#21765)
## Summary
Implement default-specialization of generic type aliases (implicit or
PEP-613) if they are used in a type expression without an explicit
specialization.
closes astral-sh/ty#1690
## Typing conformance
```diff
-generics_defaults_specialization.py:26:5: error[type-assertion-failure] Type `SomethingWithNoDefaults[int, str]` does not match asserted type `SomethingWithNoDefaults[int, DefaultStrT]`
```
That's exactly what we want :heavy_check_mark:
All other tests in this file pass as well, with the exception of this
assertion, which is just wrong (at least according to our
interpretation, `type[Bar] != <class 'Bar'>`). I checked that we do
correctly default-specialize the type parameter which is not displayed
in the diagnostic that we raise.
```py
class Bar(SubclassMe[int, DefaultStrT]): ...
assert_type(Bar, type[Bar[str]]) # ty: Type `type[Bar[str]]` does not match asserted type `<class 'Bar'>`
```
## Ecosystem impact
Looks like I should have included this last week :sunglasses:
## Test Plan
Updated pre-existing tests and add a few new ones.1 parent c5b8d55 commit e6ddeed
File tree
4 files changed
+49
-43
lines changed- crates/ty_python_semantic
- resources/mdtest
- src
- types/infer/builder
4 files changed
+49
-43
lines changedLines changed: 25 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
201 | 197 | | |
202 | 198 | | |
203 | 199 | | |
| |||
529 | 525 | | |
530 | 526 | | |
531 | 527 | | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
549 | 537 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
| 538 | + | |
| 539 | + | |
554 | 540 | | |
555 | 541 | | |
556 | 542 | | |
| |||
563 | 549 | | |
564 | 550 | | |
565 | 551 | | |
| 552 | + | |
| 553 | + | |
566 | 554 | | |
567 | 555 | | |
568 | | - | |
569 | | - | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
570 | 559 | | |
571 | 560 | | |
572 | 561 | | |
| |||
601 | 590 | | |
602 | 591 | | |
603 | 592 | | |
604 | | - | |
| 593 | + | |
605 | 594 | | |
606 | 595 | | |
607 | 596 | | |
| |||
615 | 604 | | |
616 | 605 | | |
617 | 606 | | |
| 607 | + | |
| 608 | + | |
618 | 609 | | |
619 | 610 | | |
620 | 611 | | |
| 612 | + | |
| 613 | + | |
621 | 614 | | |
622 | 615 | | |
623 | 616 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8263 | 8263 | | |
8264 | 8264 | | |
8265 | 8265 | | |
| 8266 | + | |
| 8267 | + | |
| 8268 | + | |
| 8269 | + | |
| 8270 | + | |
| 8271 | + | |
| 8272 | + | |
| 8273 | + | |
| 8274 | + | |
| 8275 | + | |
8266 | 8276 | | |
8267 | 8277 | | |
8268 | 8278 | | |
| |||
Lines changed: 12 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
157 | 152 | | |
158 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
0 commit comments