Add fickling.loads() public API function#173
Merged
thomas-chauchefoin-tob merged 3 commits intomasterfrom Nov 28, 2025
Merged
Conversation
This commit adds a new public API function `fickling.loads()` that mirrors Python's `pickle.loads()` signature while providing the same safety analysis as the existing `fickling.load()` function. Changes: - Added loads() function to fickling/loader.py that wraps bytes in io.BytesIO and delegates to the existing load() function - Exported loads from fickling/__init__.py alongside load - Created comprehensive test suite in test/test_loads_api.py with 4 test cases covering safe data, unsafe data, pickle signature compatibility, and custom severity levels The implementation reuses the existing load() function to avoid code duplication while maintaining identical safety guarantees. This completes the public API to match Python's pickle module (both load and loads functions). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
thomas-chauchefoin-tob
approved these changes
Nov 28, 2025
Collaborator
thomas-chauchefoin-tob
left a comment
There was a problem hiding this comment.
I fixed the logic of the last test, let's merge this one as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add fickling.loads() Public API Function
Summary
This PR adds a new public API function
fickling.loads()that provides safe loading of pickle data from bytes, completing the API to match Python'spicklemodule.Problem
The fickling library currently only exposes
fickling.load(file)for loading from file objects. While hooks forpickle.loads()exist internally, there's no corresponding publicfickling.loads(data)API function for loadingfrom bytes data. This creates an incomplete API compared to Python's pickle module, which provides both
load()andloads().Solution
Added
fickling.loads()function that:pickle.loads()signature)io.BytesIOand delegates to existingload()functionfickling.load()Changes
Core Implementation
loads()function (42 lines) after existingload()functionloadsalongsideloadand updated documentation commentTests
test_loads_safe_data- Verifies safe pickle data loads correctlytest_loads_unsafe_data- Verifies unsafe data is rejected with UnsafeFileErrortest_loads_matches_pickle_signature- Tests compatibility with pickle.loads() argumentstest_loads_with_custom_severity- Tests custom severity level supportDesign Rationale
load()function to avoid duplication and maintain consistencyio.BytesIO- all security logic remains inload()Testing
All new tests pass: