changeset 14977:1dbd42a02153

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.
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 21:15:48 -0500
parents 04a950b1c2ad
children 5a0fdc715769
files mercurial/demandimport.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/demandimport.py	Tue Mar 01 23:35:22 2011 -0600
+++ b/mercurial/demandimport.py	Mon Jul 25 21:15:48 2011 -0500
@@ -27,6 +27,8 @@
 import __builtin__
 _origimport = __import__
 
+nothing = object()
+
 class _demandmod(object):
     """module demand-loader and proxy"""
     def __init__(self, name, globals, locals):
@@ -50,7 +52,7 @@
                 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 @@
         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 disable():
     "disable global demand-loading of modules"
     __builtin__.__import__ = _origimport
-