Skip to content

feat: add python-benedict[schema] optional dependency (pydantic v2)#565

Merged
fabiocaccamo merged 14 commits into
mainfrom
copilot/update-schema-requirement
Apr 27, 2026
Merged

feat: add python-benedict[schema] optional dependency (pydantic v2)#565
fabiocaccamo merged 14 commits into
mainfrom
copilot/update-schema-requirement

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

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

  • Added benedict/utils/schema_util.py with apply_schema() and require_schema() using try/except ImportError for optional pydantic detection; added # pragma: no cover to the except ImportError: branch
  • Applied apply_schema() in io_util.decode/encode when schema is provided
  • Added schema optional extra (pydantic>=2,<3) in pyproject.toml and included it in the all extra
  • Updated README to document the new schema optional extra
  • Added schema test suite covering from_json, from_yaml, from_toml, from_ini, from_xml, from_csv, from_xls, and corresponding to_* methods
  • Pinned pydantic >= 2.0.0, < 3.0.0 in requirements.txt; removed the unnecessary zipp pin
  • Merged latest changes from main

Related issue
?

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Copilot AI and others added 3 commits April 17, 2026 12:05
- 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/075d4699-4b95-45d2-888b-5e71304de357

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>
@fabiocaccamo fabiocaccamo marked this pull request as ready for review April 17, 2026 14:40
Copilot AI review requested due to automatic review settings April 17, 2026 14:40
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.32%. Comparing base (4073f83) to head (361b195).

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              
Flag Coverage Δ
unittests 98.32% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
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 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() + new require_schema() extra gate, and apply it in io_util.decode/encode when schema is provided.
  • Add the new schema optional dependency (pydantic v2) in pyproject.toml and 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.

Comment thread pyproject.toml
Comment thread benedict/dicts/io/io_util.py
Copy link
Copy Markdown
Owner

@fabiocaccamo fabiocaccamo left a comment

Choose a reason for hiding this comment

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

zipp requirement must be clamped or fixed using ==

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

zipp requirement must be clamped or fixed using ==

Fixed in 4cbdf47zipp is now pinned to == 3.23.1.

Copy link
Copy Markdown
Owner

@fabiocaccamo fabiocaccamo left a comment

Choose a reason for hiding this comment

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

@copilot you must also update from main branch.

Comment thread benedict/utils/schema_util.py Outdated
Comment thread requirements.txt Outdated
Copilot AI and others added 2 commits April 27, 2026 22:42
…-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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 27, 2026

@copilot you must also update from main branch.

Done in 361b195 — merged the latest changes from main into this branch.

Copilot AI requested a review from fabiocaccamo April 27, 2026 22:54
@fabiocaccamo fabiocaccamo merged commit a423e15 into main Apr 27, 2026
22 of 24 checks passed
@fabiocaccamo fabiocaccamo deleted the copilot/update-schema-requirement branch April 27, 2026 22:56
Copilot stopped work on behalf of fabiocaccamo due to an error April 27, 2026 22:56
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.

3 participants