Skip to content

Conversation

@hf-kklein
Copy link
Contributor

@hf-kklein hf-kklein commented Oct 27, 2025

Instead of TreeSchema().dump(t) use model_dump_tree(t).
Instead of ConciseTreeSchema().dump(t) use model_dump_tree(t, mode="concise")
Instead of ConciseConditionKeyTreeSchema().dump(t) use model_dump_tree(t, mode="compress-conditions-only").

Python 3.9 EOL is end of this month and 3.9 didn't have TypeAlias yet.

finally fixes #478

Konstantin added 8 commits October 27, 2025 08:13
…tead (breaking)

Instead of `TreeSchema().dump(t)` use `model_dump_tree(t)`.
Instead of `ConciseTreeSchema().dump(t)` use `model_dump_tree(t, mode="concise")`
Instead of `ConciseConditionKeyTreeSchema().dump(t)` use `model_dump_tree(t, mode="compress-conditions-only")`.

finally fixes #478
…dDict` instead of `typing.TypedDict` on Python < 3.12.
@hf-kklein hf-kklein changed the title Drop marshmallow (Concise)TreeSchemas, use pydantic TypeAdapter instead (breaking) Drop (Concise)TreeSchemas, use pydantic TypeAdapter instead; Remove marshmallow dependency; Drop 3.9 support (breaking) Oct 27, 2025
@hf-kklein hf-kklein changed the title Drop (Concise)TreeSchemas, use pydantic TypeAdapter instead; Remove marshmallow dependency; Drop 3.9 support (breaking) Drop (Concise)TreeSchemas, use pydantic TypeAdapter instead; Remove marshmallow dependency; Drop Python 3.9 support (breaking) Oct 27, 2025
@hf-krechan hf-krechan requested a review from Copilot October 28, 2025 16:43
Copy link
Contributor

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

This PR migrates from marshmallow to pydantic for JSON serialization of tree structures, replaces the deprecated TreeSchema, ConciseTreeSchema, and ConciseConditionKeyTreeSchema classes with a single model_dump_tree() function using pydantic's TypeAdapter, and drops support for Python 3.9.

Key changes:

  • Replaced marshmallow-based schemas with pydantic TypeAdapter and custom serialization functions
  • Introduced model_dump_tree() function with mode parameter to handle different serialization behaviors
  • Removed Python 3.9 support (minimum now 3.10) to enable use of TypeAlias

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
unittests/test_tree_schemas.py Updated test imports and replaced schema .dump() calls with model_dump_tree() function calls
unittests/test_json_serialization.py Simplified _test_serialization_roundtrip to remove marshmallow path and schema parameter
src/ahbicht/json_serialization/tree_schema.py Replaced marshmallow schemas with pydantic TypeAdapter-based serialization using custom serializers
src/ahbicht/json_serialization/concise_tree_schema.py Deleted file - functionality moved to tree_schema.py
src/ahbicht/json_serialization/concise_condition_key_tree_schema.py Deleted file - functionality moved to tree_schema.py
pyproject.toml Updated minimum Python to 3.10, removed marshmallow dependency and Python 3.9 classifier
json_schemas/generate_json_schemas.py Removed marshmallow schema generation path, keeping only pydantic approach
.github/workflows/unittests.yml Removed Python 3.9 from test matrix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def model_dump_tree(
tree: Tree, mode: Literal["json", "concise", "compress-conditions-only"] = "json"
) -> dict[str, Any]:
"""ahbicht v1 replacement for the removed TreeSchema"""
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

The docstring should describe what this function does and document the parameters and return value, not just state it's a replacement. Add a proper docstring with parameter descriptions for 'tree' and 'mode', plus return value documentation.

Suggested change
"""ahbicht v1 replacement for the removed TreeSchema"""
"""
Serializes a Lark Tree object into a dictionary suitable for JSON serialization.
Parameters:
tree (Tree): The Lark Tree object to serialize.
mode (Literal["json", "concise", "compress-conditions-only"], optional):
The serialization mode.
- "json": Standard JSON serialization of the tree.
- "concise": Returns a compressed version of the tree.
- "compress-conditions-only": Compresses only condition key nodes in the tree.
Defaults to "json".
Returns:
dict[str, Any]: The serialized representation of the tree, as a dictionary.
Raises:
ValueError: If an unsupported mode is provided.
"""

Copilot uses AI. Check for mistakes.
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.

Replace attrs + marshmallow with pydantic

2 participants