-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-77566: Make setdefault methods require explicit default argument for dbm backends #138358
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
base: main
Are you sure you want to change the base?
Conversation
By the way, if we want to use the same error messages for all DBM backends, we can follow these changes;
|
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.
Thank you for your PR. Please add more tests for setdefault()
.
- with non-existing key (this case is currently tested in the form
self.assertEqual(f.setdefault(b'xxx', b'foo'), b'foo')
) - with existing key
- with wrong number of arguments (with non-existing and existing key)
- with wrong type of default (with non-existing and existing key)
- with read-only DB (with non-existing and existing key)
if key in self: | ||
return self[key] | ||
else: | ||
self[key] = default | ||
return default |
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.
This can be optimized to two _execute()
if inline __getitem__()
and __setitem__()
. Could it be done with a single _execute()
? cc @erlend-aasland
Uh oh!
There was an error while loading. Please reload this page.