pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.71k stars 263 forks source link

in update_in(), option to disable upsert #515

Open fenom opened 3 years ago

fenom commented 3 years ago

I'm doing an update that is completely meaningless when the key doesn't already exist. I don't even want to use a default value. I just want to leave the key nonexistent. I know I can first see if get_in() is not None, but an option to disable upsert seems too natural to not have in an update function.

groutr commented 3 years ago

@fenom I agree. The correct place to disable upserts is by subclassing dict and replacing its update method to disable upserts. Then you would pass your new subclass using the factory=MySubclass keyword argument. dicttoolz.update_in essentially delegates to the update method of the mapping container.