-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Implement dict setdefault primitive #10286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Failed in mypyc compiled version. |
The compiled mypy fails usually because the newly added primitive breaks sth. Try to comment out the new op and see if the error disappears. If that's the case, you need to double-check if your implementation matches cpython |
@TH3CHARLie thanks! I just found that the second parameter of |
Actually for |
assert d['c'] == 3 | ||
assert d.setdefault('a') == 1 | ||
assert d.setdefault('e') == None | ||
assert d.setdefault('e', 100) == None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test a subclass of dict
that overrides setdefault
. We should use the overridden method (example where this probably matters: OrderedDict
). You can create a dict
subclass that overrides setdefault
that behaves differently and use that in the test. If this doesn't work correctly right now, you'll probably need to add a helper similar to CPyDict_KeysView
that has a generic fallback implementation for dict
subclasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, looks good now! This made a microbenchmark I came up with over 2x faster, which is a great result.
Description
Related issue: mypyc/mypyc#644
Dict.setdefault()
.dict_ops.py
for better code structure.Test Plan
Please refer to the test-data changes