Skip to content

fix(bindings): compare serialized values in matches_with - #79

Merged
david-debest merged 3 commits into
mainfrom
76-fix/matches-with-literal-fields
Oct 27, 2026
Merged

david-debest merged 3 commits into
mainfrom
76-fix/matches-with-literal-fields

Conversation

@david-debest

Copy link
Copy Markdown
Contributor

Fixes #76

What

BindingModel.matches_with called .n3() on the model's raw field values. That fails for Literal[T] and Datatype fields, which hold plain Python values. It now compares self.model_dump() output, so each field's own serializer is applied and every field type is compared as N3.

matches_with_binding gets the fix too, because it calls matches_with.

  • Unset (None) fields still match anything.
  • Passing an unknown field name now raises KeyError instead of AttributeError.

Testing

  • uv run pytest: all tests pass. New tests in tests/test_bindings.py cover each field type (Uri, Literal[int|str|datetime], RdfLiteral, Datatype), unset fields, and matches_with_binding.
  • ruff check / ruff format --check: clean.

Related

Literal[T] and Datatype fields hold plain Python values, so calling
.n3() on them raised AttributeError. Comparing model_dump() output
applies each field's own serializer, keeping all field types consistent.

Fixes #76

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@david-debest david-debest self-assigned this Oct 27, 2026
@david-debest
david-debest merged commit 541a22b into main Oct 27, 2026
3 checks passed
david-debest added a commit that referenced this pull request Oct 27, 2026
Covers models missed in the first pass and those added by #78 and #79.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@david-debest
david-debest deleted the 76-fix/matches-with-literal-fields branch October 27, 2026 14:32
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.

Fix BindingModel.matches_with for Literal and Datatype fields

1 participant