Skip to content

Commit 6637bb6

Browse files
skirpichevntessore
authored andcommitted
pythongh-103951: enable optimization for fast attribute access on module subclasses (pythonGH-126264)
Co-authored-by: Nicolas Tessore <[email protected]>
1 parent 84d83a0 commit 6637bb6

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Relax optimization requirements to allow fast attribute access to module
2+
subclasses.

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ dummy_func(
21322132

21332133
op(_CHECK_ATTR_MODULE, (dict_version/2, owner -- owner)) {
21342134
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
2135-
DEOPT_IF(!PyModule_CheckExact(owner_o));
2135+
DEOPT_IF(Py_TYPE(owner_o)->tp_getattro != PyModule_Type.tp_getattro);
21362136
PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner_o)->md_dict;
21372137
assert(dict != NULL);
21382138
DEOPT_IF(dict->ma_keys->dk_version != dict_version);

Python/executor_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ _Py_Specialize_LoadAttr(_PyStackRef owner_st, _Py_CODEUNIT *instr, PyObject *nam
12191219
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OTHER);
12201220
fail = true;
12211221
}
1222-
else if (PyModule_CheckExact(owner)) {
1222+
else if (Py_TYPE(owner)->tp_getattro == PyModule_Type.tp_getattro) {
12231223
fail = specialize_module_load_attr(owner, instr, name);
12241224
}
12251225
else if (PyType_Check(owner)) {

0 commit comments

Comments
 (0)