msg43908 - (view) |
Author: Gerrit Holl (gerrit) |
Date: 2003-06-07 13:11 |
Hi, subclasses of dict, list, tuple etc. should be pretty-printed according to the same rules as dict, list and tuple themselves. Because of that, this patch changes pprint.py so that rather than checking types using 'typ is list', pprint checks types using 'issubclass(typ, list)'. Gerrit Holl Patched against latest CVS ( 07/06/2003 13:11:24 UTC) |
|
|
msg43909 - (view) |
Author: Fred Drake (fdrake)  |
Date: 2003-06-07 20:30 |
Logged In: YES user_id=3066 From python-dev: http://mail.python.org/pipermail/python-dev/2003-June/036008.html Hmm; this patch was never assigned to me, so I was unaware that anyone thought there was a problem with this. I specifically considered making changes like these when subclassing built-in types became possible, but decided against it since it didn't appear reasonable to assume that __repr__() hadn't been redefined. I'm sure it's possible to check, but to do so cleanly and efficiently seems like a huge change to the module for little value. I think the patch, as it stands, should be reverted. If another patch appears that addresses the issue of overridden __repr__() methods, it should be considered again. -1 for the patch as applied. |
|
|
msg43910 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2003-06-07 20:31 |
Logged In: YES user_id=21627 Thanks for the patch. Applied as pprint.py 1.25. |
|
|
msg43911 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2003-06-07 20:49 |
Logged In: YES user_id=21627 I have reverted the patch on Fred's request. The patch does not support an overridden __repr__ implementation, and thus has to be rejected. |
|
|
msg43912 - (view) |
Author: Gerrit Holl (gerrit) |
Date: 2003-06-08 20:06 |
Logged In: YES user_id=13298 I have changed the patch. Instead of replacing 'typ is list' with 'issubclass(typ, list)', it is now replaced with 'issubclass(typ, list) and typ.__repr__ is typ.__list__'. This way, classes overriding __repr__ keep the current behaviour and classes that don't get the new behaviour. See also the thread on python-dev. BTW, I also expanded 2 of the 3 assert statements, so they explain what's wrong is somethings wrong. |
|
|
msg43913 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2003-06-08 23:06 |
Logged In: YES user_id=21627 Assigning to Fred. |
|
|
msg43914 - (view) |
Author: Walter Dörwald (doerwalter) *  |
Date: 2003-12-02 22:53 |
Logged In: YES user_id=89016 I've updated the patch (pprint.diff) so subclasses work in _safe_repr() too and I've added a few tests to test_pprint.py. IMHO the patch is OK and could be applied. |
|
|
msg43915 - (view) |
Author: Walter Dörwald (doerwalter) *  |
Date: 2003-12-03 20:16 |
Logged In: YES user_id=89016 Checked in as: Lib/pprint.py 1.27 Lib/test/test_pprint.py 1.12 |
|
|