fix: refactor _compat.py for pydantic v2 compatibility #53
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.
Refactor _compat.py to improve compatibility with Pydantic v2, simplify conditional logic, and add safe fallbacks when internal Pydantic utilities are unavailable.
Key changes:
Consolidate TYPE_CHECKING stubs and simplify type hints.
Use pydantic.TypeAdapter as a safe fallback when internal _utils helpers are missing (avoids import crashes).
Simplify and normalize model helper functions: model_dump, model_copy, model_json, model_parse.
Normalize ConfigDict handling across Pydantic v1/v2 code paths.
Clean up GenericModel and cached_property compatibility branches.
Small related fix:
Normalize CRLF → LF when base64-encoding textual file inputs so outputs are platform-independent (fixes Windows test expectations).
Why:
Makes the compatibility layer more robust across Pydantic versions and platforms and prevents runtime import errors when internal Pydantic helpers are not present.
Verification:
Branch: fix/compat-refactor
Ran full test suite locally: all tests passed (393 passed, 4302 skipped, 10 deselected).
Confirmed the base64 newline issue is resolved.
Notes for reviewers:
Please ensure CI runs against supported Pydantic versions (v1 and v2 where possible).
Pay attention to any public-facing behavior that may rely on model_dump/model_copy semantics.