[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-30 Thread Eric V. Smith


Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-30 Thread Irit Katriel


Irit Katriel  added the comment:

Thank you Serhiy.  This ticket can be closed now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-30 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 582f13786bb75c73d609790967fea03a5b50148a by Irit Katriel in 
branch 'master':
bpo-39994: Fix pprint handling of dict subclasses that override __repr__ 
(GH-21892)
https://github.com/python/cpython/commit/582f13786bb75c73d609790967fea03a5b50148a


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Eric V. Smith


Eric V. Smith  added the comment:

Only 3.8 - 3.10 would be eligible for this fix. 3.7 is getting only security 
fixes.

--
versions:  -Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Irit Katriel


Change by Irit Katriel :


--
versions: +Python 3.10, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Irit Katriel


Irit Katriel  added the comment:

I've created a new PR, with two commits. The first has just tests added, which 
show the problems and assert that the bug is there. The second has the fix and 
update to the tests. Let me know what you think.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Irit Katriel


Change by Irit Katriel :


--
pull_requests: +21011
pull_request: https://github.com/python/cpython/pull/21892

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Irit Katriel


Irit Katriel  added the comment:

import pprint

class MyDict(dict):
def __repr__(self):
return '*'*len(dict.__repr__(self))

if __name__ == '__main__':
d=MyDict({})
print('pprint.pformat(d):\n%s' % pprint.pformat(d))
print('pprint.pformat(d, width=1, indent=0):\n%s' % pprint.pformat(d, 
width=1, indent=0))



Output:

pprint.pformat(d):
**
pprint.pformat(d, width=1, indent=0):
{}

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Eric V. Smith


Eric V. Smith  added the comment:

I realize it might break some corner cases, but I really think we should 
re-write pprint to use functools.singledispatch. Or if the breakage isn't 
acceptable, abandon it and create a new module that does use singledispatch. 
That way it would be easily extensible.

pprint currently works with a dispatch table (_dispatch), it's just hidden.

@fdrake: From the comments: "If you find it useful, thank small children who 
sleep at night". I assume they're not small anymore!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Fred Drake


Fred Drake  added the comment:

And that is why the original code was checking not only for the type, but the 
actual __repr__ method itself.

I think the current behavior is broken.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Irit Katriel


Irit Katriel  added the comment:

While writing the tests I see that it's even more interesting:

(Pdb) dd = MyDict()
(Pdb) pprint.pformat(dd)
'{}'
(Pdb) pprint.saferepr(dd)
'I do my own thing '

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39994] pprint handling of dict subclasses that override __repr__

2020-08-15 Thread Irit Katriel


Change by Irit Katriel :


--
components: +Library (Lib)
title: Redundant code in pprint module. -> pprint handling of dict subclasses 
that override __repr__
type: enhancement -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com