Open jml opened 9 years ago
I agree, would be nice! I'll look into it.
This seems difficult: in Python 2.7 and 3.4 pprint
basically hardcodes the stdlib data structures (with issubclass
check). One could monkey-patch the stdlib, as proposed here (http://stackoverflow.com/a/15417704) but that seems not great.
Yes, I read that SO post as well when looking at this issue the first time. If it is implemented through monkey patching (I have not found any good alternatives) that would probably be done through an explicit call to some function (eg. pyrsistent.enable_pprint()). I wouldn't want to mess with the stdlib functionality without making it very explicit.
Python 3.5 appears to have a more extensible implementation of pprint (https://github.com/python/cpython/blob/master/Lib/pprint.py). I don't know if it works out of the box w/ pyrsistent (I guess it ought to if pyrsistent uses the collections abstract base classes?).
I think a good way to start would be to avoid the question of monkey-patching altogether by providing alternative functions that pretty-format and pretty-print regular Python objects and pyrsistent objects. If it turns out that they are useful, then monkey-patching can be implemented separately.
It'd be great if
pprint
andpformat
worked "properly" on pyrsistent objects. That is, if the output ofpformat(some_pmap)
were comparable topformat(some_dict)
.That is, the following Python code...
... produces this output ...
Whereas it should produce:
... or something similar
(Related to #69, but this is a request for enhancement, rather than a defect report. Fixing this would probably also fix #69)