Commit 18396d9
committed
gh-156399: Don't specialize LOAD_ATTR_MODULE for module subclasses
Attribute loads on a types.ModuleType subclass were specialized to
LOAD_ATTR_MODULE, which reads the module dictionary directly. Both the
specialization site and the runtime guard tested
Py_TYPE(owner)->tp_getattro == PyModule_Type.tp_getattro
which a subclass inherits unless it overrides __getattr__, so subclasses
took the path. A data descriptor defined on the subclass was then
silently bypassed once the instruction had specialized, and the value
from the module dictionary was returned instead. Before 3.14 the guard
was PyModule_CheckExact, so subclasses never specialized.
Require the exact module type in both places. The runtime guard matters
independently of the specialization site, because one instruction can be
specialized on an exact module and later executed against a subclass
instance.1 parent eb08902 commit 18396d9
7 files changed
Lines changed: 38 additions & 5 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Modules/_testinternalcapi
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2209 | 2209 | | |
2210 | 2210 | | |
2211 | 2211 | | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
2212 | 2241 | | |
2213 | 2242 | | |
2214 | 2243 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2928 | 2928 | | |
2929 | 2929 | | |
2930 | 2930 | | |
2931 | | - | |
| 2931 | + | |
2932 | 2932 | | |
2933 | 2933 | | |
2934 | 2934 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1010 | 1010 | | |
1011 | 1011 | | |
1012 | 1012 | | |
1013 | | - | |
| 1013 | + | |
1014 | 1014 | | |
1015 | 1015 | | |
1016 | 1016 | | |
| |||
0 commit comments