Commit 1d0f713
pythongh-113320: Reduce the number of dangerous
- 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!getattr() calls when constructing protocol classes (python#113401)1 parent 3fedf61 commit 1d0f713
File tree
3 files changed
+68
-20
lines changed- Lib
- test
- Misc/NEWS.d/next/Library
3 files changed
+68
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3448 | 3448 | | |
3449 | 3449 | | |
3450 | 3450 | | |
3451 | | - | |
3452 | | - | |
| 3451 | + | |
| 3452 | + | |
3453 | 3453 | | |
3454 | 3454 | | |
3455 | 3455 | | |
| |||
4105 | 4105 | | |
4106 | 4106 | | |
4107 | 4107 | | |
| 4108 | + | |
4108 | 4109 | | |
4109 | 4110 | | |
4110 | 4111 | | |
| |||
4120 | 4121 | | |
4121 | 4122 | | |
4122 | 4123 | | |
| 4124 | + | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
| 4133 | + | |
| 4134 | + | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
4123 | 4157 | | |
4124 | 4158 | | |
4125 | 4159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1670 | 1670 | | |
1671 | 1671 | | |
1672 | 1672 | | |
1673 | | - | |
| 1673 | + | |
1674 | 1674 | | |
1675 | 1675 | | |
1676 | 1676 | | |
| |||
1833 | 1833 | | |
1834 | 1834 | | |
1835 | 1835 | | |
1836 | | - | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
1841 | 1836 | | |
1842 | 1837 | | |
1843 | 1838 | | |
| |||
1846 | 1841 | | |
1847 | 1842 | | |
1848 | 1843 | | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
1849 | 1850 | | |
1850 | | - | |
| 1851 | + | |
| 1852 | + | |
1851 | 1853 | | |
1852 | 1854 | | |
1853 | 1855 | | |
1854 | | - | |
1855 | | - | |
1856 | | - | |
1857 | | - | |
| 1856 | + | |
1858 | 1857 | | |
1859 | 1858 | | |
1860 | 1859 | | |
1861 | 1860 | | |
1862 | | - | |
1863 | | - | |
1864 | | - | |
1865 | | - | |
1866 | | - | |
1867 | | - | |
1868 | 1861 | | |
1869 | 1862 | | |
1870 | 1863 | | |
| |||
1892 | 1885 | | |
1893 | 1886 | | |
1894 | 1887 | | |
1895 | | - | |
| 1888 | + | |
| 1889 | + | |
1896 | 1890 | | |
1897 | 1891 | | |
1898 | 1892 | | |
| |||
2114 | 2108 | | |
2115 | 2109 | | |
2116 | 2110 | | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
2117 | 2127 | | |
2118 | 2128 | | |
2119 | 2129 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments