The goal of this enhancement is to make the shelve module more usable by accepting custom types of pickler and unpickler.
The lambda functions can not be pickled by Python's pickle module. So, for that reason the shelve library also can’t do that.
The shelve module was unable to handle this situation.
import shelve with shelve.open("test_file") as sh: squared = lambda x: x ** 2 sh['test_key'] = squared
With the changes made here, the shelve module can easily overcome this issue.
import dill import shelve with shelve.open("test_file_2", pickler=dill.Pickler, unpickler=dill.Unpickler) as sh: squared = lambda x: x ** 2 sh['test_key'] = squared
gh-99631: Add custom `loads` and `dumps` support for the `shelve` mod…
pythongh-99631: Add custom `loads` and `dumps` support for the `shelv…
gh-99631: Add shelve custom serialization to What's New in 3.15 (#145253
pythongh-99631: Add shelve custom serialization to What's New in 3.15 (…
Activity
gh-99631: Add custom `loads` and `dumps` support for the `shelve` mod…
pythongh-99631: Add custom `loads` and `dumps` support for the `shelv…
pythongh-99631: Add custom `loads` and `dumps` support for the `shelv…
pythongh-99631: Add custom `loads` and `dumps` support for the `shelv…
pythongh-99631: Add custom `loads` and `dumps` support for the `shelv…
gh-99631: Add shelve custom serialization to What's New in 3.15 (#145253
pythongh-99631: Add shelve custom serialization to What's New in 3.15 (…