##// END OF EJS Templates
Ensure that __repr__() methods override pretty printers for parent classes...
Thomas Kluyver -
Show More
@@ -392,6 +392,10 b' class RepresentationPrinter(PrettyPrinter):'
392 meth = cls._repr_pretty_
392 meth = cls._repr_pretty_
393 if callable(meth):
393 if callable(meth):
394 return meth(obj, self, cycle)
394 return meth(obj, self, cycle)
395 if cls is not object \
396 and callable(cls.__dict__.get('__repr__')):
397 return _repr_pprint(obj, self, cycle)
398
395 return _default_pprint(obj, self, cycle)
399 return _default_pprint(obj, self, cycle)
396 finally:
400 finally:
397 self.end_group()
401 self.end_group()
@@ -421,3 +421,17 b' def test_function_pretty():'
421
421
422 nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life))
422 nt.assert_in('meaning_of_life(question=None)', pretty.pretty(meaning_of_life))
423
423
424
425 class OrderedCounter(Counter, OrderedDict):
426 'Counter that remembers the order elements are first encountered'
427
428 def __repr__(self):
429 return '%s(%r)' % (self.__class__.__name__, OrderedDict(self))
430
431 def __reduce__(self):
432 return self.__class__, (OrderedDict(self),)
433
434 def test_custom_repr():
435 """A custom repr should override a pretty printer for a parent type"""
436 oc = OrderedCounter("abracadabra")
437 nt.assert_in("OrderedCounter(OrderedDict", pretty.pretty(oc))
General Comments 0
You need to be logged in to leave comments. Login now