Repository navigation
feat(bindings): add UNDEFINED sentinels for unbound binding values - #78
Merged
Merged
Conversation
The Knowledge Engine has no optional values in bindings, so a variable without a value previously could not be sent from a BindingModel. Add two sentinels that serialize to <http://www.knowledge-engine.eu/mapper/undefined>: UNDEFINED (a URIRef) for Uri fields and UNDEFINED_LITERAL (an enum member) for Literal, Datatype and RdfLiteral fields. The enum lets pyright accept the sentinel in literal fields and narrow it away with an `is` check. Incoming bindings deserialize to the sentinel matching the field type; using the wrong sentinel for a field raises a ValidationError. Fixes #75 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #75
What
The Knowledge Engine has no optional values in bindings. This adds two sentinels that serialize to
<http://www.knowledge-engine.eu/mapper/undefined>:UNDEFINEDURIRefUrifieldsUNDEFINED_LITERALUndefinedLiteralLiteral[T],Datatype-annotated andRdfLiteralfieldsis), never toNone.ValidationError, and pyright flags it too.Noneis not converted automatically;dump_result_binding()still rejects it.dump_partial_binding()andmatches_with, the sentinels are concrete values, not wildcards.Why an enum for literals
Pyright accepts an enum member in literal fields and narrows it away. For a
Literal[int]field,x is not None and x is not UNDEFINED_LITERALnarrows toint. AURIRefsentinel can't be narrowed like that.Typing change: literal field hints are now
T | UndefinedLiteral | None. Pyright will flag code that only checks forNonebefore using a literal value.The enum branch is
Strict(), so a bare URI string (no<>) is not turned into the sentinel.Docs
README (API section and examples table),
examples/README.md,CONTEXT.md, and a newexamples/13-undefined_values.py.Testing
uv run pytest: all tests pass, including new sentinel tests intests/test_bindings.py.Related
matches_withfails forLiteralandDatatypefields (existing bug)BindingModelfields as required (existing bug)