Content-Length: 288930 | pFad | https://github.com/python/cpython/issues/99631

84 Custom unpickler and pickler for the shelve module · Issue #99631 · python/cpython · GitHub
Skip to content

Custom unpickler and pickler for the shelve module  #99631

@furkanonder

Description

@furkanonder

The goal of this enhancement is to make the shelve module more usable by accepting custom types of pickler and unpickler.

Example

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

Previous discussion

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/99631

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy