Skip to content

Commit

Permalink
Check attrs in m_copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Feb 15, 2023
1 parent c5aced3 commit e832631
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lib/test/test_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ def clean_up():
if lookedup is not _testsinglephase:
raise Exception((_testsinglephase, lookedup))
# Attrs set in the module init func are in m_copy.
_initialized = _testsinglephase._initialized
initialized = _testsinglephase.initialized()
if _initialized != initialized:
raise Exception((_initialized, initialized))
# Attrs set after loading are not in m_copy.
if hasattr(_testsinglephase, 'spam'):
raise Exception(_testsinglephase.spam)
Expand Down
10 changes: 10 additions & 0 deletions Modules/_testsinglephase.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ init_module(PyObject *module, module_state *state)
if (PyModule_AddObjectRef(module, "str_const", state->str_const) != 0) {
return -1;
}

double d = _PyTime_AsSecondsDouble(state->initialized);
PyObject *initialized = PyFloat_FromDouble(d);
if (initialized == NULL) {
return -1;
}
if (PyModule_AddObjectRef(module, "_initialized", initialized) != 0) {
return -1;
}

return 0;
}

Expand Down

0 comments on commit e832631

Please sign in to comment.