Commit 8435fbf
authored
- Only attempt to figure out whether protocol members are "method members" or not if the class is marked as a runtime protocol. This information is irrelevant for non-runtime protocols; we can safely skip the risky introspection for them.
- Only do the risky getattr() calls in one place (the runtime_checkable class decorator), rather than in three places (_ProtocolMeta.__init__, _ProtocolMeta.__instancecheck__ and _ProtocolMeta.__subclasscheck__). This reduces the number of locations in typing.py where the risky introspection could go wrong.
- For runtime protocols, if determining whether a protocol member is callable or not fails, give a better error message. I think it's reasonable for us to reject runtime protocols that have members which raise strange exceptions when you try to access them. PEP-544 clearly states that all protocol member must be callable for issubclass() calls against the protocol to be valid -- and if a member raises when we try to access it, there's no way for us to figure out whether it's a callable member or not!
(cherry-picked from commit ed6ea3e)
1 parent 6f90399 commit 8435fbf
File tree
3 files changed
+66
-15
lines changed- Lib
- test
- Misc/NEWS.d/next/Library
3 files changed
+66
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3449 | 3449 | | |
3450 | 3450 | | |
3451 | 3451 | | |
3452 | | - | |
3453 | | - | |
| 3452 | + | |
| 3453 | + | |
3454 | 3454 | | |
3455 | 3455 | | |
3456 | 3456 | | |
| |||
3995 | 3995 | | |
3996 | 3996 | | |
3997 | 3997 | | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
3998 | 4032 | | |
3999 | 4033 | | |
4000 | 4034 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1683 | 1683 | | |
1684 | 1684 | | |
1685 | 1685 | | |
1686 | | - | |
| 1686 | + | |
1687 | 1687 | | |
1688 | 1688 | | |
1689 | 1689 | | |
| |||
1820 | 1820 | | |
1821 | 1821 | | |
1822 | 1822 | | |
1823 | | - | |
1824 | | - | |
1825 | | - | |
1826 | | - | |
1827 | | - | |
1828 | 1823 | | |
1829 | 1824 | | |
1830 | 1825 | | |
| |||
1836 | 1831 | | |
1837 | 1832 | | |
1838 | 1833 | | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
1839 | 1839 | | |
1840 | | - | |
| 1840 | + | |
| 1841 | + | |
1841 | 1842 | | |
1842 | 1843 | | |
1843 | 1844 | | |
1844 | 1845 | | |
1845 | 1846 | | |
1846 | | - | |
1847 | | - | |
1848 | | - | |
1849 | | - | |
1850 | | - | |
1851 | 1847 | | |
1852 | 1848 | | |
1853 | 1849 | | |
| |||
1875 | 1871 | | |
1876 | 1872 | | |
1877 | 1873 | | |
1878 | | - | |
| 1874 | + | |
| 1875 | + | |
1879 | 1876 | | |
1880 | 1877 | | |
1881 | 1878 | | |
| |||
2113 | 2110 | | |
2114 | 2111 | | |
2115 | 2112 | | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
2116 | 2129 | | |
2117 | 2130 | | |
2118 | 2131 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments