Skip to content

shelve returns the rejected value after a failed assignment #163192

Backlog

Description

@tonghuaroot

Bug report

with writeback enabled, assigning an unpicklable value raises an exception, but reading the same key returns that value.

import shelve

with shelve.Shelf({}, writeback=True) as db:
    original = []
    db['key'] = original
    try:
        db['key'] = memoryview(b'')
    except TypeError:
        pass
    actual = db['key']
    del db['key']
    assert actual is original

CPython versions tested on:

3.16

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bug
    stdlib
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions