Skip to content

gh-113093: Add mode parameter to shelve.open#148807

Open
algonix01w-ai wants to merge 3 commits intopython:mainfrom
algonix01w-ai:fix-shelve-mode
Open

gh-113093: Add mode parameter to shelve.open#148807
algonix01w-ai wants to merge 3 commits intopython:mainfrom
algonix01w-ai:fix-shelve-mode

Conversation

@algonix01w-ai
Copy link
Copy Markdown

@algonix01w-ai algonix01w-ai commented Apr 20, 2026

Description

This PR adds the missing mode parameter to shelve.open() and the DbfilenameShelf class.

Currently, shelve.open does not allow users to specify file permissions, even though the underlying dbm.open supports a mode parameter. This change ensures consistency between the shelve and dbm modules, allowing users to set custom file permissions (e.g., restricted access) when creating a shelf database.

Changes

  • Lib/shelve.py:
    • Updated DbfilenameShelf.__init__ to accept mode as a keyword-only argument.
    • Updated shelve.open to accept mode and pass it to DbfilenameShelf.
  • Lib/test/test_shelve.py:
    • Added test_mode using tempfile.TemporaryDirectory to verify that the mode parameter is accepted and correctly passed through without errors.
  • Doc/library/shelve.rst:
    • Updated documentation signature for open() and added a versionchanged notice for 3.15.

Linked Issue

Fixes gh-113093

Tests

Ran python.bat -m test test_shelve on Windows 11. All tests passed successfully.


📚 Documentation preview 📚: https://cpython-previews--148807.org.readthedocs.build/

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 20, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 20, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@da-woods
Copy link
Copy Markdown
Contributor

There looks to be another recent PR on this #148662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "mode" parameter to shelve.open

2 participants