Commit fa56c15
authored
[ty] Fix bound method access on
## Summary
Just a small quick win that should fix the last remaining conformance
test in
[`specialtypes_none.py`](https://shark.fish/typing-conformance-report/specialtypes_none.html).
`types.FunctionType` has the following overloads for `__get__` to model
accessing functions on a class vs. on an instance:
```py
class FunctionType:
@overload
def __get__(self, instance: None, owner: type, /) -> FunctionType:
"""Return an attribute of instance, which is of type owner."""
@overload
def __get__(self, instance: object, owner: type | None = None, /) -> MethodType: ...
```
The `instance: None` sentinel of the descriptor protocol is problematic
when we're actually accessing something on an instance of type `None`.
Here, we simply add a special case to fix this. Also, instead of using
`Type::none(db)` as a sentinel in the Rust code, we now use
`Optional<Type<…>>` such that we can use the Rust `None` if we want to
call `__get__` on a non-instance.
Fixes astral-sh/ty#737
## Ecosystem
Looks good. Some strange-looking new diagnostics because symbols were
inferred as `None` where users did not intend that (but no wrong
behavior of ty).
## Test Plan
Adapted existing tests.None (#23246)1 parent 4fd07d0 commit fa56c15
5 files changed
Lines changed: 35 additions & 40 deletions
File tree
- crates/ty_python_semantic
- resources/mdtest/call
- src
- types
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
233 | | - | |
234 | | - | |
| 232 | + | |
| 233 | + | |
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2750 | 2750 | | |
2751 | 2751 | | |
2752 | 2752 | | |
2753 | | - | |
| 2753 | + | |
2754 | 2754 | | |
2755 | 2755 | | |
2756 | 2756 | | |
2757 | 2757 | | |
2758 | 2758 | | |
2759 | | - | |
| 2759 | + | |
2760 | 2760 | | |
2761 | 2761 | | |
2762 | 2762 | | |
| |||
2776 | 2776 | | |
2777 | 2777 | | |
2778 | 2778 | | |
2779 | | - | |
| 2779 | + | |
2780 | 2780 | | |
2781 | 2781 | | |
2782 | | - | |
2783 | | - | |
| 2782 | + | |
| 2783 | + | |
2784 | 2784 | | |
2785 | | - | |
2786 | | - | |
2787 | | - | |
| 2785 | + | |
2788 | 2786 | | |
2789 | 2787 | | |
2790 | 2788 | | |
2791 | 2789 | | |
2792 | 2790 | | |
2793 | 2791 | | |
2794 | 2792 | | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
2795 | 2809 | | |
2796 | 2810 | | |
2797 | 2811 | | |
| |||
2803 | 2817 | | |
2804 | 2818 | | |
2805 | 2819 | | |
| 2820 | + | |
2806 | 2821 | | |
2807 | | - | |
| 2822 | + | |
2808 | 2823 | | |
2809 | 2824 | | |
2810 | 2825 | | |
| |||
2834 | 2849 | | |
2835 | 2850 | | |
2836 | 2851 | | |
2837 | | - | |
| 2852 | + | |
2838 | 2853 | | |
2839 | 2854 | | |
2840 | 2855 | | |
| |||
3023 | 3038 | | |
3024 | 3039 | | |
3025 | 3040 | | |
3026 | | - | |
| 3041 | + | |
3027 | 3042 | | |
3028 | 3043 | | |
3029 | 3044 | | |
| |||
3498 | 3513 | | |
3499 | 3514 | | |
3500 | 3515 | | |
3501 | | - | |
3502 | | - | |
3503 | | - | |
3504 | | - | |
3505 | | - | |
3506 | | - | |
3507 | | - | |
| 3516 | + | |
| 3517 | + | |
3508 | 3518 | | |
3509 | 3519 | | |
3510 | 3520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
| 694 | + | |
701 | 695 | | |
702 | 696 | | |
703 | 697 | | |
704 | 698 | | |
705 | 699 | | |
706 | 700 | | |
707 | 701 | | |
708 | | - | |
| 702 | + | |
709 | 703 | | |
710 | 704 | | |
711 | 705 | | |
712 | 706 | | |
713 | 707 | | |
714 | 708 | | |
715 | 709 | | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
| 710 | + | |
725 | 711 | | |
726 | 712 | | |
727 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3266 | 3266 | | |
3267 | 3267 | | |
3268 | 3268 | | |
3269 | | - | |
| 3269 | + | |
3270 | 3270 | | |
3271 | 3271 | | |
3272 | 3272 | | |
| |||
0 commit comments