Commit 307fe8f
gh-156413: Let a None-valued non-callable member keep the Protocol fast path
`_ProtocolMeta.__instancecheck__` treats a member set to `None` as
"explicitly not implemented" only for callable members, but `_proto_hook`
treated any `None` in a class `__dict__` that way. A class that set a
non-callable protocol member to `None` therefore passed `isinstance()` but
was rejected by the subclass hook, so it never entered `ABCMeta`'s cache
and re-walked every protocol member on every call.
Give `_proto_hook` the same rule, so such a class is cached like any other.
`None`-valued *method* members are still rejected.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016TM2nkuPFj6FFmZyUJZYUQ1 parent fe3a26f commit 307fe8f
3 files changed
Lines changed: 33 additions & 1 deletion
File tree
- Lib
- test
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3888 | 3888 | | |
3889 | 3889 | | |
3890 | 3890 | | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
3891 | 3914 | | |
3892 | 3915 | | |
3893 | 3916 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2127 | 2127 | | |
2128 | 2128 | | |
2129 | 2129 | | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
2130 | 2133 | | |
2131 | 2134 | | |
2132 | 2135 | | |
2133 | 2136 | | |
2134 | | - | |
| 2137 | + | |
| 2138 | + | |
2135 | 2139 | | |
2136 | 2140 | | |
2137 | 2141 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments