Skip to content

Commit c6ade63

Browse files
committed
fix: hasattr checks if attr is None
1 parent 2e05cde commit c6ade63

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

ollama/_types.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,30 @@ def __setitem__(self, key: str, value: Any) -> None:
2323
setattr(self, key, value)
2424

2525
def __contains__(self, key: str) -> bool:
26-
return hasattr(self, key)
26+
"""
27+
>>> msg = Message(role='user')
28+
>>> 'nonexistent' in msg
29+
False
30+
>>> 'role' in msg
31+
True
32+
>>> 'content' in msg
33+
False
34+
>>> msg.content = 'hello!'
35+
>>> 'content' in msg
36+
True
37+
>>> msg = Message(role='user', content='hello!')
38+
>>> 'content' in msg
39+
True
40+
>>> 'tool_calls' in msg
41+
False
42+
>>> msg['tool_calls'] = []
43+
>>> 'tool_calls' in msg
44+
True
45+
>>> msg['tool_calls'] = [Message.ToolCall(function=Message.ToolCall.Function(name='foo', arguments={}))]
46+
>>> 'tool_calls' in msg
47+
True
48+
"""
49+
return key in self.model_fields_set
2750

2851
def get(self, key: str, default: Any = None) -> Any:
2952
return getattr(self, key, default)

0 commit comments

Comments
 (0)