[Python-Dev] Change PEP 399 import recommendation

Stefan Behnel stefan_ml at behnel.de
Sun Oct 13 20:18:14 CEST 2013


Oscar Benjamin, 13.10.2013 18:35:
> CPython preferentially imports extension modules over .py modules with
> the same name. This is what happens when you use Cython in "pure"
> mode: You have a pure mod.py file and an "augmenting" mod.pxd that
> contains the annotations relevant to Cython. The resulting extension
> module is mod.{pyd,so} and is imported by CPython if present. This way
> you don't need an additional directory/module.

While it may work, I wouldn't really recommend that for manually written
modules. For Cython, it's a nice feature because you get the same thing,
just in native code. It also helps with stack traces because Python can
extract the source code lines for exceptions raised in native code from the
original .py file.

For manually written modules, the source code is naturally unrelated
between both implementations. You want to test both separately and may even
want to import one or the other specifically for other reasons. Explicitly
given them different names is very helpful here.

Stefan




More information about the Python-Dev mailing list