Skip to content

Make __repr__ more similar to other mapping types#58

Merged
fantix merged 2 commits into
MagicStack:masterfrom
ofek:pretty-repr
Feb 9, 2021
Merged

Make __repr__ more similar to other mapping types#58
fantix merged 2 commits into
MagicStack:masterfrom
ofek:pretty-repr

Conversation

@ofek

@ofek ofek commented Feb 8, 2021

Copy link
Copy Markdown
Contributor

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

ofek commented Feb 8, 2021

Copy link
Copy Markdown
Contributor Author

cc @1st1 😄

@1st1

1st1 commented Feb 8, 2021

Copy link
Copy Markdown
Member

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

ofek commented Feb 8, 2021

Copy link
Copy Markdown
Contributor Author

@1st1 Addressed!

@1st1

1st1 commented Feb 8, 2021

Copy link
Copy Markdown
Member

@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

elprans commented Feb 9, 2021

Copy link
Copy Markdown
Member

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

@fantix fantix merged commit 8af1502 into MagicStack:master Feb 9, 2021
@ofek ofek deleted the pretty-repr branch February 9, 2021 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

immutables.Map.__str__ doesn't match dict.__str__

4 participants