[Python-ideas] import fallback syntax

Chris Withers chris at simplistix.co.uk
Thu Mar 8 19:14:36 CET 2012

On 08/03/2012 10:03, Guido van Rossum wrote:
> We used to have a lot more of these. The agreed-upon solution is to
> have this hidden inside (for instance) the decimal module. E.g. if you
> import heapq, you get heapq.py which attempts to import _heapq but
> gives you the Python implementation if that fails.

Okay, but I'm thinking about the situation where there are genuinely 
several possible import sources, with no clear order of fallbacks and 
where not all of the packages know about each other. The ElementTree 
example is currently a good one...

This seems particularly relevant with things like argparse, unittest2, 
distutils2, packaging...

I suspect it'll also be relevant where code uses libraries where the 
author has chosen to have differently named packages for Python 2 and 3.

It would also be extremely relevant if any of the misguided "provisional 
packages in stdlib" PEPs make it through...


Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk

More information about the Python-ideas mailing list