Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templateutil.py @ 50644:ae2de4cb7869
safehasattr: pass attribute name as string instead of bytes
This is a step toward replacing `util.safehasattr` usage with plain `hasattr`.
The builtin function behave poorly in Python2 but this was fixed in Python3.
These change are done one by one as they tend to have a small odd to trigger
puzzling breackage.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 02 Feb 2023 17:37:44 +0100 |
parents | f013e790d8bf |
children | 26e63204c31e |
comparison
equal
deleted
inserted
replaced
50643:f013e790d8bf | 50644:ae2de4cb7869 |
---|---|
339 return bool(self._values) | 339 return bool(self._values) |
340 | 340 |
341 def tovalue(self, context, mapping): | 341 def tovalue(self, context, mapping): |
342 # TODO: make it non-recursive for trivial lists/dicts | 342 # TODO: make it non-recursive for trivial lists/dicts |
343 xs = self._values | 343 xs = self._values |
344 if util.safehasattr(xs, b'get'): | 344 if util.safehasattr(xs, 'get'): |
345 return {k: unwrapvalue(context, mapping, v) for k, v in xs.items()} | 345 return {k: unwrapvalue(context, mapping, v) for k, v in xs.items()} |
346 return [unwrapvalue(context, mapping, x) for x in xs] | 346 return [unwrapvalue(context, mapping, x) for x in xs] |
347 | 347 |
348 | 348 |
349 class hybriditem(mappable, wrapped): | 349 class hybriditem(mappable, wrapped): |