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.
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/
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 2/3/2011 9:44 AM, Martin [gz] wrote: get(self. module_ name) _(self. module_ name, {}, {}, [''])
> I think checking sys.modules should do instead, something like:
>
> sentinel = object()
> module = sys.modules.
> if module is None:
> return False
> if module is sentinel:
> try:
> module = __import_
> 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 enigmail. mozdev. org/
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAk1 Kz4sACgkQJdeBCY SNAAPLjgCfaPi84 2OVTWonJ6f9yKDI 6gCg XVWEaH+ Srs7NS/ bsm0VqwA+ u
udAAoKV/
=ZTnz
-----END PGP SIGNATURE-----