comparison piecrust/data/debug.py @ 591:eedd63b7cf42

debug: Don't show parentheses on redirected properties.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 17 Jan 2016 23:09:08 -0800
parents 93b656f0af54
children d91e013b586a
comparison
equal deleted inserted replaced
590:3cca1f6bd610 591:eedd63b7cf42
307 rendered_count = 0 307 rendered_count = 0
308 for name in attr_names: 308 for name in attr_names:
309 value = None 309 value = None
310 render_name = name 310 render_name = name
311 should_call = name in invoke_attrs 311 should_call = name in invoke_attrs
312 is_redirect = False
312 313
313 if name in redirects: 314 if name in redirects:
314 name = redirects[name] 315 name = redirects[name]
316 is_redirect = True
315 317
316 query_instance = False 318 query_instance = False
317 try: 319 try:
318 attr = getattr(data.__class__, name) 320 attr = getattr(data.__class__, name)
319 except AttributeError: 321 except AttributeError:
327 if isinstance(attr, collections.Callable): 329 if isinstance(attr, collections.Callable):
328 attr_func = getattr(data, name) 330 attr_func = getattr(data, name)
329 argcount = attr_func.__code__.co_argcount 331 argcount = attr_func.__code__.co_argcount
330 var_names = attr_func.__code__.co_varnames 332 var_names = attr_func.__code__.co_varnames
331 if argcount == 1 and should_call: 333 if argcount == 1 and should_call:
332 render_name += '()' 334 if not is_redirect:
335 # Most of the time, redirects are for making a
336 # property render better. So don't add parenthesis.
337 render_name += '()'
333 value = attr_func() 338 value = attr_func()
334 else: 339 else:
335 if should_call: 340 if should_call:
336 logger.warning("Method '%s' should be invoked for " 341 logger.warning("Method '%s' should be invoked for "
337 "rendering, but it has %s arguments." % 342 "rendering, but it has %s arguments." %