##// END OF EJS Templates
fixed honoring custom repr for NamedTuple if assigned by partialmethod
Randolf Scholz -
Show More
@@ -529,3 +529,18 b' def test_repr_mime_failure():'
529 obj = BadReprMime()
529 obj = BadReprMime()
530 d, md = f.format(obj)
530 d, md = f.format(obj)
531 assert "text/plain" in d
531 assert "text/plain" in d
532
533
534 def test_custom_repr_namedtuple_partialmethod():
535 from functools import partialmethod
536 from typing import NamedTuple
537
538 class Foo(NamedTuple):
539 ...
540
541 Foo.__repr__ = partialmethod(lambda obj: "Hello World")
542 foo = Foo()
543
544 f = PlainTextFormatter()
545 assert f.pprint
546 assert f(foo) == "Hello World"
@@ -406,8 +406,7 b' class RepresentationPrinter(PrettyPrinter):'
406 meth = cls._repr_pretty_
406 meth = cls._repr_pretty_
407 if callable(meth):
407 if callable(meth):
408 return meth(obj, self, cycle)
408 return meth(obj, self, cycle)
409 if cls is not object \
409 if cls is not object and callable(getattr(cls, '__repr__', None)):
410 and callable(cls.__dict__.get('__repr__')):
411 return _repr_pprint(obj, self, cycle)
410 return _repr_pprint(obj, self, cycle)
412
411
413 return _default_pprint(obj, self, cycle)
412 return _default_pprint(obj, self, cycle)
General Comments 0
You need to be logged in to leave comments. Login now