Skip to content

Custom unpickler and pickler for the shelve module  #99631

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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 28, 2023
  2. self-assigned this
    on Apr 21, 2024
  3. added
    3.14bugs and security fixes
    and removed
    3.13only security fixes
    on Mar 22, 2025
  4. added a commit that references this issue on Jul 12, 2025
  5. added a commit that references this issue on Jul 12, 2025
  6. added a commit that references this issue on Jul 13, 2025
  7. added a commit that references this issue on Aug 4, 2025
  8. added a commit that references this issue on Aug 19, 2025
  9. added a commit that references this issue on Mar 13, 2026
  10. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions