Add _PyType_GetModuleByDef (GH-22835) · python/cpython@57aaaa8 · GitHub
Skip to content

Commit 57aaaa8

Browse files
authored
1 parent a603c3d commit 57aaaa8

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

Include/cpython/object.h

Lines changed: 2 additions & 0 deletions

Modules/_testmultiphase.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,30 @@ static PyType_Spec Example_Type_spec = {
121121
};
122122

123123

124+
static PyModuleDef def_meth_state_access;
125+
124126
/*[clinic input]
125127
_testmultiphase.StateAccessType.get_defining_module
126128
127129
cls: defining_class
128130
129131
Return the module of the defining class.
132+
133+
Also tests that result of _PyType_GetModuleByDef matches defining_class's
134+
module.
130135
[clinic start generated code]*/
131136

132137
static PyObject *
133138
_testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *self,
134139
PyTypeObject *cls)
135-
/*[clinic end generated code: output=ba2a14284a5d0921 input=946149f91cf72c0d]*/
140+
/*[clinic end generated code: output=ba2a14284a5d0921 input=356f999fc16e0933]*/
136141
{
137142
PyObject *retval;
138143
retval = PyType_GetModule(cls);
139144
if (retval == NULL) {
140145
return NULL;
141146
}
147+
assert(_PyType_GetModuleByDef(Py_TYPE(self), &def_meth_state_access) == retval);
142148
Py_INCREF(retval);
143149
return retval;
144150
}

Modules/clinic/_testmultiphase.c.h

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/typeobject.c

Lines changed: 38 additions & 0 deletions

0 commit comments

Comments
 (0)