Commit 9e80e5a
authored
## Summary
Support `type[…]` in implicit type aliases, for example:
```py
SubclassOfInt = type[int]
reveal_type(SubclassOfInt) # GenericAlias
def _(subclass_of_int: SubclassOfInt):
reveal_type(subclass_of_int) # type[int]
```
part of astral-sh/ty#221
## Typing conformance
```diff
-specialtypes_type.py:138:5: error[type-assertion-failure] Argument does not have asserted type `type[Any]`
-specialtypes_type.py:140:5: error[type-assertion-failure] Argument does not have asserted type `type[Any]`
```
Two new tests passing :heavy_check_mark:
```diff
-specialtypes_type.py:146:1: error[unresolved-attribute] Object of type `GenericAlias` has no attribute `unknown`
```
An `TA4.unknown` attribute on a PEP 613 alias (`TA4: TypeAlias =
type[Any]`) is being accessed, and the conformance suite expects this to
be an error. Since we currently use the inferred type for these type
aliases (and possibly in the future as well), we treat this as a direct
access of the attribute on `type[Any]`, which falls back to an access on
`Any` itself, which succeeds. :red_circle:
```
+specialtypes_type.py:152:16: error[invalid-type-form] `typing.TypeVar` is not a generic class
+specialtypes_type.py:156:16: error[invalid-type-form] `typing.TypeVar` is not a generic class
```
New errors because we don't handle `T = TypeVar("T"); MyType = type[T];
MyType[T]` yet. Support for this is being tracked in
astral-sh/ty#221 🔴
## Ecosystem impact
Looks mostly good, a few known problems.
## Test Plan
New Markdown tests
1 parent f9cc26a commit 9e80e5a
File tree
6 files changed
+207
-8
lines changed- crates/ty_python_semantic
- resources/mdtest
- type_of
- src
- types
- infer
- builder
6 files changed
+207
-8
lines changedLines changed: 163 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| 136 | + | |
| 137 | + | |
132 | 138 | | |
133 | 139 | | |
134 | 140 | | |
| |||
160 | 166 | | |
161 | 167 | | |
162 | 168 | | |
| 169 | + | |
| 170 | + | |
163 | 171 | | |
164 | 172 | | |
165 | 173 | | |
| |||
599 | 607 | | |
600 | 608 | | |
601 | 609 | | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
602 | 762 | | |
603 | 763 | | |
604 | 764 | | |
| |||
633 | 793 | | |
634 | 794 | | |
635 | 795 | | |
| 796 | + | |
636 | 797 | | |
637 | 798 | | |
638 | 799 | | |
639 | 800 | | |
640 | 801 | | |
641 | 802 | | |
| 803 | + | |
642 | 804 | | |
643 | 805 | | |
644 | 806 | | |
| 807 | + | |
645 | 808 | | |
646 | 809 | | |
647 | 810 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
| 152 | + | |
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6607 | 6607 | | |
6608 | 6608 | | |
6609 | 6609 | | |
| 6610 | + | |
| 6611 | + | |
| 6612 | + | |
| 6613 | + | |
| 6614 | + | |
| 6615 | + | |
| 6616 | + | |
| 6617 | + | |
| 6618 | + | |
| 6619 | + | |
| 6620 | + | |
6610 | 6621 | | |
6611 | 6622 | | |
6612 | 6623 | | |
| |||
7847 | 7858 | | |
7848 | 7859 | | |
7849 | 7860 | | |
| 7861 | + | |
| 7862 | + | |
| 7863 | + | |
7850 | 7864 | | |
7851 | 7865 | | |
7852 | 7866 | | |
| |||
7881 | 7895 | | |
7882 | 7896 | | |
7883 | 7897 | | |
7884 | | - | |
| 7898 | + | |
| 7899 | + | |
| 7900 | + | |
7885 | 7901 | | |
7886 | 7902 | | |
7887 | 7903 | | |
| |||
7928 | 7944 | | |
7929 | 7945 | | |
7930 | 7946 | | |
| 7947 | + | |
7931 | 7948 | | |
7932 | 7949 | | |
7933 | 7950 | | |
| |||
7950 | 7967 | | |
7951 | 7968 | | |
7952 | 7969 | | |
7953 | | - | |
7954 | | - | |
| 7970 | + | |
| 7971 | + | |
| 7972 | + | |
7955 | 7973 | | |
7956 | 7974 | | |
7957 | 7975 | | |
| |||
8037 | 8055 | | |
8038 | 8056 | | |
8039 | 8057 | | |
| 8058 | + | |
8040 | 8059 | | |
8041 | 8060 | | |
8042 | 8061 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9457 | 9457 | | |
9458 | 9458 | | |
9459 | 9459 | | |
9460 | | - | |
| 9460 | + | |
| 9461 | + | |
9461 | 9462 | | |
9462 | 9463 | | |
9463 | 9464 | | |
| |||
9466 | 9467 | | |
9467 | 9468 | | |
9468 | 9469 | | |
9469 | | - | |
| 9470 | + | |
| 9471 | + | |
9470 | 9472 | | |
9471 | 9473 | | |
9472 | 9474 | | |
| |||
10627 | 10629 | | |
10628 | 10630 | | |
10629 | 10631 | | |
| 10632 | + | |
| 10633 | + | |
| 10634 | + | |
| 10635 | + | |
| 10636 | + | |
10630 | 10637 | | |
| 10638 | + | |
10631 | 10639 | | |
10632 | 10640 | | |
10633 | 10641 | | |
| |||
10764 | 10772 | | |
10765 | 10773 | | |
10766 | 10774 | | |
| 10775 | + | |
| 10776 | + | |
| 10777 | + | |
| 10778 | + | |
| 10779 | + | |
| 10780 | + | |
| 10781 | + | |
10767 | 10782 | | |
10768 | 10783 | | |
10769 | 10784 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
829 | | - | |
| 829 | + | |
830 | 830 | | |
831 | 831 | | |
832 | 832 | | |
| |||
0 commit comments