[rfc] use absolute imports

John Arbash Meinel john at arbash-meinel.com
Thu Feb 22 00:26:17 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
> John Arbash Meinel wrote:
>> Martin Pool wrote:
>>> After a conversation with John I thought I'd try enabling absolute
>>> imports.  However, it looks like there's no clean way to turn these on
>>> only on python2.5, since they can't be guarded by an if or try/except
>>> block.  Nevertheless I think our code should always use 'import
>>> bzrlib.foo' not 'import foo'.
>> I would be for this, since it is something we would like to do.
>>
>> The only downside is plugins. Because they don't always know where they
>> are installed, so I've taken to using local imports there.
> 
> Can't the plugins do "from bzrlib.plugins.foo import ..."?

Only if they are installed as "foo" and not foo_jam, or foo_bar, or
fooXXYY. Up until recently they could be installed as foo-0.5.6.

> 
>> If this only changes it for a specific file we don't affect plugins, but
>> then again we don't affect the rest of our code base either. (And I
>> don't think we want to add that line to every file).
> 
> I think whenever we require python2.5 ideally we would add this to every file in
> bzr.  Ugly though it is to have a __future__ statement in every file, it will
> enforce the right sort of behaviour (and make sure we're compatible with future
> releases of python that will do this by default).
> 
> I wonder if we can make lazy_import refuse to do a relative import?
> 
> -Andrew.

Probably not. Simply because it just hands off to __import__(). Now, if
there is a way to do it at the __import__() level, (like if we do
__future__ in lazy_import does it re-define the semantics of __import__()?)

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF3OMpJdeBCYSNAAMRAnQHAKCZI0cEwbnHc7WqQT9yIGGLorodMQCeOgnY
wnB1isNFXGeHTo7Fa5utW0M=
=soS+
-----END PGP SIGNATURE-----



More information about the bazaar mailing list