Repository navigation
Commit 2fc445f
authored
[ty] Diagnose invalid __getattr__ calls (#27502)
## Summary
Previously, an invalid `__getattr__` method caused us to report that the
requested attribute was missing, even though Python actually invokes the
method and raises `TypeError`:
```py
class Example:
def __getattr__(self) -> str:
return "fallback"
Example().missing # error: [invalid-attribute-access]
```
We now propagate failed implicit `__getattr__` calls through the
generalized member-lookup error introduced in #27400, so the diagnostic
identifies the invalid call and preserves the method's return type for
error recovery.
This applies to instance and metaclass attribute lookup, including
incompatible attribute-name parameters. Literal-restricted `__getattr__`
methods continue to treat unsupported names as missing attributes, and
already-defined attributes still bypass the fallback.
Closes astral-sh/ty#135.1 parent 22c7823 commit 2fc445f
3 files changed
Lines changed: 141 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2706 | 2706 | | |
2707 | 2707 | | |
2708 | 2708 | | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
2709 | 2754 | | |
2710 | 2755 | | |
2711 | 2756 | | |
| |||
2724 | 2769 | | |
2725 | 2770 | | |
2726 | 2771 | | |
2727 | | - | |
2728 | | - | |
| 2772 | + | |
| 2773 | + | |
2729 | 2774 | | |
2730 | 2775 | | |
2731 | 2776 | | |
| |||
2817 | 2862 | | |
2818 | 2863 | | |
2819 | 2864 | | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
2820 | 2881 | | |
2821 | 2882 | | |
2822 | 2883 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
609 | 611 | | |
610 | 612 | | |
611 | 613 | | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
612 | 622 | | |
613 | 623 | | |
614 | 624 | | |
| |||
652 | 662 | | |
653 | 663 | | |
654 | 664 | | |
655 | | - | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
656 | 680 | | |
657 | 681 | | |
658 | 682 | | |
| |||
6528 | 6552 | | |
6529 | 6553 | | |
6530 | 6554 | | |
6531 | | - | |
| 6555 | + | |
| 6556 | + | |
6532 | 6557 | | |
6533 | 6558 | | |
6534 | 6559 | | |
6535 | | - | |
| 6560 | + | |
6536 | 6561 | | |
6537 | | - | |
6538 | | - | |
6539 | | - | |
6540 | | - | |
6541 | | - | |
| 6562 | + | |
| 6563 | + | |
| 6564 | + | |
| 6565 | + | |
| 6566 | + | |
| 6567 | + | |
| 6568 | + | |
| 6569 | + | |
| 6570 | + | |
| 6571 | + | |
| 6572 | + | |
| 6573 | + | |
| 6574 | + | |
| 6575 | + | |
6542 | 6576 | | |
6543 | 6577 | | |
6544 | 6578 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1795 | 1795 | | |
1796 | 1796 | | |
1797 | 1797 | | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
1798 | 1833 | | |
1799 | 1834 | | |
1800 | 1835 | | |
| |||
0 commit comments