feat: Enhance ascleandict to handle non-picklable fields#14
Merged
MrKevinWeiss merged 1 commit intomasterfrom Apr 8, 2026
Merged
feat: Enhance ascleandict to handle non-picklable fields#14MrKevinWeiss merged 1 commit intomasterfrom
MrKevinWeiss merged 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors LobHlpr.ascleandict to avoid dataclasses.asdict()/deepcopy issues with non-picklable fields and adds an option intended to ensure JSON-safe output, along with tests for the new behavior.
Changes:
- Replaced
dataclasses.asdict()usage with a custom recursive converter to avoid deepcopy/pickling failures. - Added
json_serializableoption intended to coerce non-JSON-serializable values to strings. - Added a regression test covering dataclasses containing a thread lock and JSON serialization behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/lob_hlpr/hlpr.py |
Reimplements ascleandict conversion/cleanup logic and introduces json_serializable. |
tests/test_lob_hlpr.py |
Adds a new test for non-picklable fields and JSON serialization compatibility. |
9222528 to
008e9ea
Compare
008e9ea to
e25f4de
Compare
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.
This pull request refactors the
ascleandictutility inhlpr.pyto improve its handling of dataclass-to-dictionary conversion, especially for non-serializable and non-picklable fields. The update introduces a newjson_serializableoption to ensure all returned dictionaries can be safely serialized to JSON, and includes new tests to verify this behavior.Improvements to dataclass conversion:
ascleandictmethod to avoid usingdataclasses.asdict, preventing errors with non-picklable fields such as thread locks, by implementing a custom recursive converter.json_serializableparameter toascleandict, which converts non-JSON-serializable types to strings, ensuring compatibility with JSON serialization.hlpr.pyto support the new implementation, including addingjson,fields, andis_dataclass.Testing enhancements:
test_ascleandict_non_picklable_field) to verify thatascleandictcorrectly handles dataclasses containing non-picklable fields and that thejson_serializableoption enables JSON serialization without errors.jsonintests/test_lob_hlpr.pyto support new test cases for JSON serialization.