Code review comment for lp:~jml/bzr/lp-login-oauth-2

Revision history for this message
Andrew Bennetts (spiv) wrote :

John A Meinel wrote:
[...]
> The problem is that you are assigning a lazily imported object to
> another reference, which we can't trap, and we can't replace the new
> object. As an example

I don't think so, at least not exactly. My hypothesis is that actually
the problem is that normally this is a reasonable thing to do:

foo.py:
----
from x.y import z # x.y.z is a submodule that defines SomeClass, etc.
...
class Foo(z.SomeClass): ... # etc
----

That's not making a new reference to a lazy import placeholder, right?

But consider this:

x/y/__init__.py:
----
lazy_import(globals(), """
    from x.y import z
""")
----

Now foo.py will be importing the lazy 'z' reference that belongs to
x/y/__init__.py.

Hence my suggestion for that __init__.py to import and use it as _mod_z,
so that Python's import logic will find the z module rather than the
lazy import placeholder.

But it's a pretty nasty situation, because both files look utterly
reasonable and idiomatic in isolation, and the errors from lazy_import
tend to be pretty confusing.

-Andrew.

« Back to merge proposal