Ian Bicking: the old part of his blog


I think about this a lot. I disagree with the way you're conceptualizing it though.

IMHO ">=" is a useless operator for imports. The only useful thing is to say, "I want interface version X" - any package that provides version X may then claim to *be* version X. "1 < x < 5" may be useful for some kind of packaging metadata - for example, to say that versions 1 - 7 claim to implement interface version 1, but only versions 1 - 5 actually do.

This can already be done simply by having a rigorous naming convention for packages, and providing some kind of implementation-hiding for python packages, so you can be sure of some narrow band that your program is implemented in terms of, and that your understanding of what is used publicly is the same as that of the module maintainer.

"Only what is hidden can be changed without risk." A module can only be expressed in terms of one version of an interface - although it may be a locally-defined subset which actually exists in multiple other interfaces, that itself should be encapsulated somewhere, so you don't accidentally import stuff you shouldn't be. If it is expressed in terms of more than one, then you need something like:

from foo_api_1 import thingy
except ImportError:
from foo_api_2 import thing1, thing2
from my_compat_hacks import frobnicate
def thingy():
return frobnicate(thing1(),thing2())
Comment on Versioned Imports
by Glyph Lefkowitz