Mercurial > hg
comparison mercurial/util.py @ 37099:6ca5f825a0ca
util: make safehasattr() a pycompat function
So safehasattr() can be imported by utils.* modules. util.safehasattr() still
remains as an alias since it is pretty basic utility available for years.
On current Python 3, the builtin hasattr() should have no problem.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 24 Mar 2018 14:24:32 +0900 |
parents | a9ea2b1e5c4b |
children | 49d6ba67c93f |
comparison
equal
deleted
inserted
replaced
37098:a9ea2b1e5c4b | 37099:6ca5f825a0ca |
---|---|
65 cookielib = pycompat.cookielib | 65 cookielib = pycompat.cookielib |
66 empty = pycompat.empty | 66 empty = pycompat.empty |
67 httplib = pycompat.httplib | 67 httplib = pycompat.httplib |
68 pickle = pycompat.pickle | 68 pickle = pycompat.pickle |
69 queue = pycompat.queue | 69 queue = pycompat.queue |
70 safehasattr = pycompat.safehasattr | |
70 socketserver = pycompat.socketserver | 71 socketserver = pycompat.socketserver |
71 stderr = pycompat.stderr | 72 stderr = pycompat.stderr |
72 stdin = pycompat.stdin | 73 stdin = pycompat.stdin |
73 stdout = pycompat.stdout | 74 stdout = pycompat.stdout |
74 bytesio = pycompat.bytesio | 75 bytesio = pycompat.bytesio |
174 pass | 175 pass |
175 | 176 |
176 # Python compatibility | 177 # Python compatibility |
177 | 178 |
178 _notset = object() | 179 _notset = object() |
179 | |
180 def safehasattr(thing, attr): | |
181 return getattr(thing, attr, _notset) is not _notset | |
182 | 180 |
183 def _rapply(f, xs): | 181 def _rapply(f, xs): |
184 if xs is None: | 182 if xs is None: |
185 # assume None means non-value of optional data | 183 # assume None means non-value of optional data |
186 return xs | 184 return xs |