Skip to content
This repository has been archived by the owner. It is now read-only.

Implement collections.defaultdict #874

Merged
merged 16 commits into from Aug 7, 2018

Conversation

@BPYap
Copy link
Contributor

@BPYap BPYap commented Jul 25, 2018

No description provided.

@BPYap BPYap changed the title Implement collections.defaultdict [WIP] Implement collections.defaultdict Jul 26, 2018
Copy link
Member

@freakboy3742 freakboy3742 left a comment

As discussed on our call - it would be preferable to make __missing__ a method that exists on org.python.types.Dict, but not exposed as a org.python.Method, so you can use classical OO patterns in __getitem__

@BPYap
Copy link
Contributor Author

@BPYap BPYap commented Jul 27, 2018

@freakboy3742 Sorry my brain got short-circuited just now 😅. Actually the reason I make a private __getitem__ on org.python.types.Dict is to preserve dict behavior on defaultdict. You see, other than __getitem__, defaultdict has exactly the same behavior as dict when other methods are call.

e.g. defaultdict.get(x) should return None (same as dict) when x is not a key instead of invoking the default_factory for missing value.
However the implementation of get(x) in voc calls __getitem__(x) which indirectly calls __missing__(x), causing defaultdict to return default_factory value instead of None, hence the need of another 'internal use' __getitem__ without calls to __missing__.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

👍 Looks good!

@freakboy3742 freakboy3742 merged commit 2b781d1 into beeware:master Aug 7, 2018
5 checks passed
@BPYap BPYap deleted the collections-module-defaultdict branch Aug 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants