Mercurial > hg
comparison mercurial/templatefilters.py @ 50928:d718eddf01d9
safehasattr: drop usage in favor of hasattr
The two functions should now be equivalent at least in their usage in core.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 31 Aug 2023 23:56:15 +0200 |
parents | 90945014f4e4 |
children | f4733654f144 |
comparison
equal
deleted
inserted
replaced
50927:7a8ea1397816 | 50928:d718eddf01d9 |
---|---|
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, 'keys'): | 342 elif hasattr(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 ] |
348 return b'{' + b', '.join(out) + b'}' | 348 return b'{' + b', '.join(out) + b'}' |
349 elif util.safehasattr(obj, '__iter__'): | 349 elif hasattr(obj, '__iter__'): |
350 out = [json(i, paranoid) for i in obj] | 350 out = [json(i, paranoid) for i in obj] |
351 return b'[' + b', '.join(out) + b']' | 351 return b'[' + b', '.join(out) + b']' |
352 raise error.ProgrammingError(b'cannot encode %r' % obj) | 352 raise error.ProgrammingError(b'cannot encode %r' % obj) |
353 | 353 |
354 | 354 |