classification
Title: Inconsistent __repr__s for _collections objects
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Repr of collection's subclasses
View: 27541
Assigned To: rhettinger Nosy List: bup, r.david.murray, rhettinger, serhiy.storchaka, veky
Priority: low Keywords:

Created on 2017-08-13 16:12 by bup, last changed 2017-08-15 14:54 by r.david.murray. This issue is now closed.

Messages (4)
msg300222 - (view) Author: Dan Snider (bup) * Date: 2017-08-13 16:12
With the new C implementation of collections.OrderedDict, its repr correctly uses the subclass's name, unlike deque and defaultdict.

class Thing(_collections.OrderedDict):
    pass
>>> Thing()
Thing([])

class Thing(_collections.deque):
    pass
>>> Thing()
deque([])
msg300272 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-08-15 01:03
IIRC, deque() did this to better match the behavior of list().  Not everything in Python is consistent and sometimes we have to pick and choose between what we want to be consistent with.  For the most part, the decisions have worked out well in practice (deque.__repr__ hasn't seemed to bother anyone in its dozen year history).
msg300297 - (view) Author: Vedran Čačić (veky) * Date: 2017-08-15 14:50
More and more, Python looks to me like a certain language that I thought I had left behind a long time ago.

       [...] Each  operator  decides  which sort of scalar it
       would be  most  appropriate  to  return.   
       [...] In  general, they do what you want,
       unless you want consistency.

Maybe it's just a sign of growing up. :-)
msg300298 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-15 14:54
This is a duplicate of issue 27541.
History
Date User Action Args
2017-08-15 14:54:52r.david.murraysetstatus: open -> closed

superseder: Repr of collection's subclasses

nosy: + r.david.murray
messages: + msg300298
resolution: duplicate
stage: resolved
2017-08-15 14:50:14vekysetnosy: + veky
messages: + msg300297
2017-08-15 01:03:28rhettingersetmessages: + msg300272
2017-08-15 00:58:54rhettingersetpriority: normal -> low
assignee: rhettinger
versions: + Python 3.7, - Python 3.6
2017-08-13 16:55:29serhiy.storchakasetnosy: + rhettinger, serhiy.storchaka
2017-08-13 16:12:55bupcreate