[BUG][MERGE] 'bzr upgrade' broken by lazy imports
Aaron Bentley
aaron.bentley at utoronto.ca
Wed Nov 8 15:28:21 GMT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Wouter van Heyst wrote:
> On Tue, Nov 07, 2006 at 12:18:45PM -0600, John Arbash Meinel wrote:
>>My initial feeling is to just change most code paths that use
>>'bzrilb.foo' to being 'from bzrlib import foo' at the beginning, and use
>>'foo.bar' later on.
>
>
> The fully explicit form can't be used with lazy importing?
I think it can be done, but the problem is that missing dependencies
will not be caught. This is a failing of Python that is exacerbated by
lazy importing.
When you import a package, it doesn't import its sub-modules. So
'import bzrlib' does not import 'bzrlib.workingtree'. So if you try to
use 'bzrlib.workingtree' later, you get an AttributeError.
But if you first import another package, and that package imports
workingtree, then the bzrlib package will get a 'workingtree' attribute.
(It can do 'from bzrlib import workingtree' or 'import bzrlib.workingtree'.)
So in general, using packagename.module leaves you blind to possible
missing imports. And with lazy importing, the number of imports is
reduced, which exposes this kind of issue.
Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFFUfeV0F+nu1YWqI0RApKLAJ9vex5P1VYnhpO5IlM5eg6t23fJlgCeOH69
kyIg/kRFkSwdPTIQvfCT4wQ=
=dtmK
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list