MagicStack / immutables

A high-performance immutable mapping type for Python.
Other
1.14k stars 57 forks source link

Make __repr__ more similar to other mapping types #58

Closed ofek closed 3 years ago

ofek commented 3 years ago

Resolves #17

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections import ChainMap, OrderedDict, defaultdict
>>>
>>> d = {'one': 1, 'two': 2}
>>> d
{'one': 1, 'two': 2}
>>> ChainMap({'one': 1}, {'two': 2})
ChainMap({'one': 1}, {'two': 2})
>>> OrderedDict((('one', 1), ('two', 2)))
OrderedDict([('one', 1), ('two', 2)])
>>> dd = defaultdict(int)
>>> dd.update(d)
>>> dd
defaultdict(<class 'int'>, {'one': 1, 'two': 2})
ofek commented 3 years ago

cc @1st1 😄

1st1 commented 3 years ago

Hm, I'm not sure I like this change. The immutables. prefix gives the user an immediate idea of what particular Map they're looking at, which is super important when you're debugging things.

ofek commented 3 years ago

@1st1 Addressed!

1st1 commented 3 years ago

@elprans Do you like this proposal? I know that you like to see object IDs in repr. Would this make your debug experience worse?

elprans commented 3 years ago

Since the content is included in the repr, the id is less important, so I'm fine with this.