Repository navigation
types: align Message.get with __contains__ semantics - #786
Open
AP24110011695 wants to merge 1 commit into
Open
AP24110011695 wants to merge 1 commit into
AP24110011695 wants to merge 1 commit into
Conversation
get() used getattr/hasattr, so a declared-but-unset field (None default)
was treated as present: 'content' in msg was False while
msg.get('content', 'fallback') returned None instead of 'fallback', and
non-field names leaked through (msg.get('model_dump') returned the bound
method). Route get through __getitem__/__contains__ so the two views
agree, and pin the behavior with a test plus a new doctest case.
This branch has not been deployed
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.
Problem
SubscriptableBaseModel.get()usedgetattr/hasattr, which disagrees with the class's own__contains__semantics:'content' in msgisFalsefor a declared-but-unset field (per the existing__contains__doctests), yetmsg.get('content', 'fallback')returnedNoneinstead of'fallback'.msg.get('model_dump')returned the bound method, breakingdict.getexpectations.Fix
Route
getthrough__getitem__/__contains__so the subscript and.getviews agree:Explicitly-set
Nonevalues still count as present (like a dict), and the existing__contains__doctests document that distinction.Tests
test_message_get_follows_contains_semanticsfails onmain(35d9667) and passes with this change; a new doctest case documents the fixed behavior. Doctests (pytest --doctest-modules ollama/_types.py) all pass.