Skip to content
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

confirm_overwrite preset function for wrap_kvs #13

Open
thorwhalen opened this issue Jun 17, 2022 · 0 comments
Open

confirm_overwrite preset function for wrap_kvs #13

thorwhalen opened this issue Jun 17, 2022 · 0 comments

Comments

@thorwhalen
Copy link
Member

thorwhalen commented Jun 17, 2022

A preset function you can use in wrap_kvs to ask the user to confirm if they're writing a value in a key that already has a different value under it.

from dol import wrap_kvs

d = {'a': 'apple', 'b': 'banana'}
d = wrap_kvs(d, preset=confirm_overwrite)
d['a'] = 'apple'
d['c'] = 'coconut'
assert d == {'a': 'apple', 'b': 'banana', 'c': 'coconut'}

But

d['a'] = 'alligator'

would lead to a user input request:

The key a already exists and has value apple. If you want to overwrite it with alligator, confirm by typing alligator here: 

which would only perform the write if the user types alligator and hits return

┆Issue is synchronized with this Asana task by Unito

thorwhalen added a commit that referenced this issue Jun 17, 2022
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

No branches or pull requests

1 participant