Add defaultdict to collections; add pprint.py #1134
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ok, so I did it in Python because I encountered a ton of broken/fragile class machinery when I tried to do it in Rust: subclassing a built-in class but also being a
PyValue
itself weirdness, inconsistency with CPython in how__new__
vs__init__
works (it was calling__new__
with arguments intended for__init__
, and I still had to work around that in Python), and the final straw,__missing__
not being detected fromdict.__getitem__
, while__missing__
did work in Python. In any casedefaultdict
being a native class is mostly just an implementation detail, and there's really no reason why it can't be implemented in Python. We can look at all that at some point later, but we're really close to unittest and I'm focusing on that at the moment.