changeset 14942:5b072d4b62f2

safehasattr: new function to work around hasattr being broken
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 14:59:55 -0500
parents 4a28cb4df1f8
children d3bb825ddae3
files mercurial/util.py
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Mon Jul 25 16:14:02 2011 -0500
+++ b/mercurial/util.py	Mon Jul 25 14:59:55 2011 -0500
@@ -75,6 +75,10 @@
 def sha1(s):
     return _fastsha1(s)
 
+_notset = object()
+def safehasattr(thing, attr):
+    return getattr(thing, attr, _notset) is not _notset
+
 def _fastsha1(s):
     # This function will import sha1 from hashlib or sha (whichever is
     # available) and overwrite itself with it on the first call.