Repository navigation
Python: fix(core): handle None text and Mapping arguments in Content addition - #8689
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
Conversation
Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
|
Thank you for proposing this change. I am closing this PR for now because it has no linked issue, and I could not find an issue covering this specific problem. Our contribution guidelines ask contributors to create or reuse an issue and discuss the approach before nontrivial changes (with an exception for trivial changes). The repository PR template asks for Motivation & Context, Description & Review Guide, a Related Issue linked with a closing keyword such as |
While working with streaming chunks and combining Content instances, I noticed that Content._add_text_content throws a TypeError if either instance has text=None because of direct self.text + other.text addition. In contrast, _add_text_reasoning_content already handles None text values safely by falling back to empty strings and preserving None when both sides are None.
In addition, _add_function_call_content was checking isinstance(..., dict) rather than isinstance(..., Mapping), which rejects valid mapping implementations like MappingProxyType even though the type hints explicitly allow Mapping[str, Any].
This PR updates _add_text_content to handle None text values gracefully and widens the function call arguments check to Mapping. I also added unit tests covering both cases in test_types.py.