Skip to content

confirm_overwrite preset function for wrap_kvs #13

@thorwhalen

Description

@thorwhalen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions