Code review comment for lp:~vila/bzr/712474-module-available

Revision history for this message
John A Meinel (jameinel) wrote :

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

On 2/3/2011 9:44 AM, Martin [gz] wrote:
> I think checking sys.modules should do instead, something like:
>
> sentinel = object()
> module = sys.modules.get(self.module_name)
> if module is None:
> return False
> if module is sentinel:
> try:
> module = __import__(self.module_name, {}, {}, [''])
> except ImportError: # import can raise other things, but that's a bug
> return False
> return True
>
> That should save me worrying needlessly about exec on an interpolated string.

I think you wanted

module = sys.modules.get(self.module_name, sentinel)

And regardless, this should probably be pulled out into a separate
helper function. I think the bzrlib.plugin code would like something
like this. Though we can see how related it is.

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

iEYEARECAAYFAk1Kz4sACgkQJdeBCYSNAAPLjgCfaPi842OVTWonJ6f9yKDI6gCg
udAAoKV/XVWEaH+Srs7NS/bsm0VqwA+u
=ZTnz
-----END PGP SIGNATURE-----

« Back to merge proposal