comparison mercurial/templatefilters.py @ 50605:046b9cce5850

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:02 +0100
parents c96ed4029fda
children 90945014f4e4
comparison
equal deleted inserted replaced
50604:bf7ad17b0a58 50605:046b9cce5850
337 return b'"%s"' % encoding.jsonescape(obj, paranoid=paranoid) 337 return b'"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
338 elif isinstance(obj, type(u'')): 338 elif isinstance(obj, type(u'')):
339 raise error.ProgrammingError( 339 raise error.ProgrammingError(
340 b'Mercurial only does output with bytes: %r' % obj 340 b'Mercurial only does output with bytes: %r' % obj
341 ) 341 )
342 elif util.safehasattr(obj, b'keys'): 342 elif util.safehasattr(obj, 'keys'):
343 out = [ 343 out = [
344 b'"%s": %s' 344 b'"%s": %s'
345 % (encoding.jsonescape(k, paranoid=paranoid), json(v, paranoid)) 345 % (encoding.jsonescape(k, paranoid=paranoid), json(v, paranoid))
346 for k, v in sorted(obj.items()) 346 for k, v in sorted(obj.items())
347 ] 347 ]