Skip to content

feat: Enhance ascleandict to handle non-picklable fields#14

Merged
MrKevinWeiss merged 1 commit intomasterfrom
pr/fix/ascleandict2
Apr 8, 2026
Merged

feat: Enhance ascleandict to handle non-picklable fields#14
MrKevinWeiss merged 1 commit intomasterfrom
pr/fix/ascleandict2

Conversation

@MrKevinWeiss
Copy link
Copy Markdown
Collaborator

This pull request refactors the ascleandict utility in hlpr.py to improve its handling of dataclass-to-dictionary conversion, especially for non-serializable and non-picklable fields. The update introduces a new json_serializable option to ensure all returned dictionaries can be safely serialized to JSON, and includes new tests to verify this behavior.

Improvements to dataclass conversion:

  • Refactored the ascleandict method to avoid using dataclasses.asdict, preventing errors with non-picklable fields such as thread locks, by implementing a custom recursive converter.
  • Added the json_serializable parameter to ascleandict, which converts non-JSON-serializable types to strings, ensuring compatibility with JSON serialization.
  • Updated imports in hlpr.py to support the new implementation, including adding json, fields, and is_dataclass.

Testing enhancements:

  • Added a test (test_ascleandict_non_picklable_field) to verify that ascleandict correctly handles dataclasses containing non-picklable fields and that the json_serializable option enables JSON serialization without errors.
  • Imported json in tests/test_lob_hlpr.py to support new test cases for JSON serialization.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_serializable option 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@MrKevinWeiss MrKevinWeiss force-pushed the pr/fix/ascleandict2 branch from 008e9ea to e25f4de Compare April 8, 2026 13:07
@MrKevinWeiss MrKevinWeiss requested a review from Copilot April 8, 2026 13:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

@MrKevinWeiss MrKevinWeiss merged commit beb7edc into master Apr 8, 2026
10 checks passed
@MrKevinWeiss MrKevinWeiss deleted the pr/fix/ascleandict2 branch April 8, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants