# HG changeset patch # User Augie Fackler # Date 2011-07-26 02:15:48 # Node ID 1dbd42a02153b9a6c757673d16eff373ff5bf32d # Parent 04a950b1c2adba3327da726807b6a467aa38f0e5 demandimport: use getattr instead of hasattr We don't use util.safehasattr() here to avoid adding new dependencies for demandimport. This change may expose previously-silenced deprecation warnings to appear, as hasattr silently hides warnings that occur during module import when using demandimport. diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py --- a/mercurial/demandimport.py +++ b/mercurial/demandimport.py @@ -27,6 +27,8 @@ These imports will not be delayed: import __builtin__ _origimport = __import__ +nothing = object() + class _demandmod(object): """module demand-loader and proxy""" def __init__(self, name, globals, locals): @@ -50,7 +52,7 @@ class _demandmod(object): h, t = p, None if '.' in p: h, t = p.split('.', 1) - if not hasattr(mod, h): + if getattr(mod, h, nothing) is nothing: setattr(mod, h, _demandmod(p, mod.__dict__, mod.__dict__)) elif t: subload(getattr(mod, h), t) @@ -109,12 +111,12 @@ def _demandimport(name, globals=None, lo mod = _origimport(name, globals, locals) # recurse down the module chain for comp in name.split('.')[1:]: - if not hasattr(mod, comp): + if getattr(mod, comp, nothing) is nothing: setattr(mod, comp, _demandmod(comp, mod.__dict__, mod.__dict__)) mod = getattr(mod, comp) for x in fromlist: # set requested submodules for demand load - if not hasattr(mod, x): + if getattr(mod, x, nothing) is nothing: setattr(mod, x, _demandmod(x, mod.__dict__, locals)) return mod @@ -148,4 +150,3 @@ def enable(): def disable(): "disable global demand-loading of modules" __builtin__.__import__ = _origimport -