Repository navigation
feat(kb): type ask/post results via binding_model keyword - #62
Merged
Merged
Conversation
Results of kb.ask()/kb.post() were typed as Sequence[BindingModel] | BindingSet even when the KI has a binding model, forcing callers to cast(). The outgoing methods (incl. *_with_info and *_sync) now take a keyword-only binding_model (ASK) / result_binding_model (POST) that types the result; parsing still uses the registered model and a mismatch raises ValueError. ExchangeResult is generic in its binding type. Closes #57 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
david-debest
force-pushed
the
57-feat/typed-ask-post-results
branch
from
October 1, 2026 12:02
628e0fb to
35bcf40
Compare
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.
Closes #57
Problem
kb.ask()/kb.ask_with_info()(and the POST equivalents) are typed as returningSequence[BindingModel] | BindingSet, even when the KI was registered with a binding model. At runtime the results are already validated into that model, but the type checker can't know it: the KI is looked up by aki_namestring. Callers had to usecast()or# type: ignore.Solution
All outgoing methods (
ask,ask_with_info,post,post_with_infoand their*_syncbridges) take a keyword-only argument that types the result:binding_model(ASK) /result_binding_model(POST) mirror the parameter names ofask_ki()/post_ki().ValueError, so the static type can't lie.ExchangeResultis now generic in its binding type.# type: ignoreworkarounds); README and CONTEXT.md are updated.Behaviour change (typing only)
Without the keyword, the result type is now
Sequence[BindingModel | dict[str, str]]instead ofSequence[BindingModel] | Sequence[dict[str, str]]. Runtime behaviour is unchanged, but code that annotated a variable with the old union may get a new type-checker error.Verification
ValueErroron a mismatching model (async and sync bridges).Sequence[P]/ExchangeResult[Q]with a model, the union without one.Notes
py.typedmarker, so mypy users of the installed package won't see these types yet; see Ship a py.typed marker so type checkers use the package's inline types #63.