[Python-Dev] Choosing a best practice solution for Python/extension modules (original) (raw)

Brett Cannon brett at python.org
Fri Feb 20 21:45:08 CET 2009


On Fri, Feb 20, 2009 at 12:37, Brett Cannon <brett at python.org> wrote:

On Fri, Feb 20, 2009 at 12:31, Daniel Stutzbach <_ _daniel at stutzbachenterprises.com> wrote: On Fri, Feb 20, 2009 at 1:44 PM, Brett Cannon <brett at python.org> wrote:

Now, from what I can tell, Antoine is suggesting having pyio and a io and then io is simply:

try: from io import * except ImportError: from pyio import * That works for testing as you can then have test classes have an attribute for the module to use and then create two subclasses which set what module to use (kind of like how testwarnings currently does it). But this only really works for complete module replacements, not modules like pickle where only key portions have been rewritten (which happens more often than the complete rewrite).

A slight change would make it work for modules where only key functions have been rewritten. For example, pickle.py could read: from pypickle import * try: from pickle import * except ImportError: pass True, although that still suffers from the problem of overwriting things like name, file, etc.

Actually, I take that back; the IMPORT_STAR opcode doesn't pull in anything starting with an underscore. So while this alleviates the worry above, it does mean that anything that gets rewritten needs to have a name that does not lead with an underscore for this to work. Is that really an acceptable compromise for a simple solution like this?

-Brett -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20090220/808fe18e/attachment.htm>



More information about the Python-Dev mailing list