This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Let pprint.py use issubclass instead of is for type checking
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: fdrake Nosy List: doerwalter, fdrake, gerrit, loewis
Priority: normal Keywords: patch

Created on 2003-06-07 13:11 by gerrit, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issubclass.diff gerrit, 2003-06-07 13:11 Patch created with "cvs diff -c pprint.py"
issubclass2.diff gerrit, 2003-06-08 20:06 Patch created with "cvs diff -c pprint.py"
pprint.diff doerwalter, 2003-12-02 22:53
Messages (8)
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) (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2003-06-08 23:06
Logged In: YES 
user_id=21627

Assigning to Fred.
msg43914 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) 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) * (Python committer) 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
History
Date User Action Args
2022-04-10 16:09:03adminsetgithub: 38604
2003-06-07 13:11:36gerritcreate