feat: add python-benedict[schema] optional dependency (pydantic v2)#565
Conversation
- Add pydantic >= 2.0.0, < 3.0.0 as schema optional dependency in pyproject.toml - Add require_schema() to benedict/extras.py - Create benedict/utils/schema_util.py with apply_schema() helper - Integrate schema kwarg into io_util.decode() and io_util.encode() - Add pydantic to requirements.txt - Add tests in tests/github/test_issue_0471.py with 100% coverage for new code Closes #471 Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/f0d9ad17-fb25-4bcb-8de0-5800a9a7d022 Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/f0d9ad17-fb25-4bcb-8de0-5800a9a7d022 Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
… classes Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/b53d4441-fd02-45fc-bc29-77bc733cab32 Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/075d4699-4b95-45d2-888b-5e71304de357 Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
…rrors) Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/d82adb04-6f57-4f46-a373-1add0c82a31c Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/be1e2958-70be-4968-8c96-bff0f5fce3dd Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
…ply ruff formatting Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/3269dce3-6fd4-4ab2-a82d-a7a2c3e6fc77 Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #565 +/- ##
==========================================
+ Coverage 98.31% 98.32% +0.01%
==========================================
Files 63 64 +1
Lines 2368 2389 +21
==========================================
+ Hits 2328 2349 +21
Misses 40 40
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR introduces optional Pydantic v2-based schema validation/type coercion for python-benedict’s normalized I/O layer via a new schema= kwarg, and wires it into packaging/docs/tests.
Changes:
- Add
benedict.utils.schema_util.apply_schema()+ newrequire_schema()extra gate, and apply it inio_util.decode/encodewhenschemais provided. - Add the new
schemaoptional dependency (pydantic v2) inpyproject.tomland update README documentation. - Add a dedicated schema test suite covering multiple
from_*/to_*I/O methods.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/dicts/io/test_schema.py | Adds schema-focused tests for validation, coercion, and extra-field stripping across multiple I/O methods. |
| requirements.txt | Adds pydantic v2 to the repo’s test/dev dependency set (used by tox). |
| pyproject.toml | Introduces the new schema extra (pydantic v2). |
| benedict/utils/schema_util.py | Adds a lightweight schema application helper gated by the schema extra. |
| benedict/extras.py | Adds require_schema() to enforce schema extra installation. |
| benedict/dicts/io/io_util.py | Plumbs schema through decode/encode, applying schema validation when provided. |
| README.md | Documents the schema kwarg and adds [schema] to the optional requirements list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…chema Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/ecd9a835-50a0-4239-a338-ae6c6cbcf36e Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/1d4fcc73-e833-493f-a17f-b152866ef5df Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
fabiocaccamo
left a comment
There was a problem hiding this comment.
zipp requirement must be clamped or fixed using ==
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/cc014501-997c-43f1-a7c2-99039df6502c Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Fixed in 4cbdf47 — |
fabiocaccamo
left a comment
There was a problem hiding this comment.
@copilot you must also update from main branch.
…-requirement Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
…s, merge main Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/5a87a272-d48b-48bc-a74b-f03dfd52107e Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Introduces optional Pydantic v2-based schema validation/type coercion for python-benedict's I/O layer via a new
schema=kwarg, and wires it into packaging, docs, and tests.Describe your changes
benedict/utils/schema_util.pywithapply_schema()andrequire_schema()usingtry/except ImportErrorfor optional pydantic detection; added# pragma: no coverto theexcept ImportError:branchapply_schema()inio_util.decode/encodewhenschemais providedschemaoptional extra (pydantic>=2,<3) inpyproject.tomland included it in theallextraschemaoptional extrafrom_json,from_yaml,from_toml,from_ini,from_xml,from_csv,from_xls, and correspondingto_*methodspydantic >= 2.0.0, < 3.0.0inrequirements.txt; removed the unnecessaryzipppinmainRelated issue
?
Checklist before requesting a review