[issue15651] PEP 3121, 384 refactoring applied to elementtree module

Eli Bendersky report at bugs.python.org
Thu Aug 8 15:56:34 CEST 2013


Eli Bendersky added the comment:

Thanks Antoine. I think I understand the patch better now. Just a couple small questions and otherwise LGTM

This code in the beginning in PyInit__elementtree:

    m = PyState_FindModule(&elementtreemodule);
    if (m) {
        Py_INCREF(m);
        return m;
    }

Can you explain what use case it tries to cover? I couldn't find similar code in other modules we have that implement PEP 3121 (_csv, readline, io, etc.)

This code has at least one adverse effect, for testing. The problem with re-importing _elementtree I raised in http://mail.python.org/pipermail/python-dev/2013-August/127766.html is solved by moving to PEP 3121, but this piece of code above ruins it. This is because I want to set sys.modules['pyexpat'] = None and re-import _elementtree (this is what support.import_fresh_module does). But with this code in place, if _elementtree was imported any time in the past (say, in a previous test), I'll just get the instance back without attempting to do the full module initialization.


>> I don't see a call to PyState_AddModule. What am I missing?
>It is called implicitly when an extension module is imported.

Do you think this should be documented in the C API docs? The way they read now, it seems that calling PyState_AddModule is needed manually by extension writers.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15651>
_______________________________________


More information about the Python-bugs-list mailing list