[issue31563] Change repr of dict_keys, dict_values, and dict_items to use curly braces

Raymond Hettinger report at bugs.python.org
Sat Sep 23 17:22:05 EDT 2017


Raymond Hettinger added the comment:

Some of these were Guido's design decisions made over a decade ago.  He explicitly choose not have the spelled-out method names (both here in the concrete class and in the corresponding abstract base classes).  It usually isn't a good idea to second guess his long standing decisions which have worked out well in practice.

>From my own point-of-view, I prefer not to use the set curly brace notation in the repr for several reasons.

1) Ideally, the reprs for the keys(), values(), and items() should all have a similar look.   The list notation is equally applicable to all of three, but the set notation isn't applicable to the values() which can have duplicates and may have non-hashable values.

2) The keys(), values(), and items() are guaranteed to be in the same order.  The list notation reinforces this fact while the set notation does not.

3) There may be unforeseen usability issues (perhaps the change might falsely imply that there is an underlying set rather than a view of the dict, or perhaps it would imply that the full set() API is supported which it is not).

4) In Python 2, all three methods actually returned lists even though it would have been possible to return a set() for the keys.  Though it isn't required, I do like the continuity in thought between the versions.

----------
components: +Interpreter Core
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31563>
_______________________________________


More information about the Python-bugs-list mailing list