Skip to content

Commit aa9a294

Browse files
committed
fix: unwrap PEP 604 union types (X | None) in _unwrap_optional
1 parent baa4b75 commit aa9a294

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/uipath_langchain/agent/react/json_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ast
22
import json
33
import sys
4+
import types
45
from typing import Any, ForwardRef, Union, get_args, get_origin
56

67
from jsonpath_ng import parse # type: ignore[import-untyped]
@@ -183,7 +184,7 @@ def _unwrap_optional(annotation: Any) -> Any:
183184
The unwrapped type, or the original if not Optional/Union
184185
"""
185186
origin = get_origin(annotation)
186-
if origin is Union:
187+
if origin is Union or isinstance(annotation, types.UnionType):
187188
args = get_args(annotation)
188189
non_none_args = [arg for arg in args if arg is not type(None)]
189190
if non_none_args:

0 commit comments

Comments
 (0)