We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d345923 commit da1782cCopy full SHA for da1782c
function_schema/core.py
@@ -22,6 +22,15 @@
22
UnionType = Union # type: ignore
23
24
25
+def is_optional_type(T: Any) -> bool:
26
+ """Check if a type annotation represents an optional/nullable type."""
27
+ origin = get_origin(T)
28
+ if origin is Union or origin is UnionType:
29
+ args = get_args(T)
30
+ return type(None) in args
31
+ return False
32
+
33
34
__all__ = ("get_function_schema", "guess_type", "Doc", "Annotated")
35
36
@@ -146,7 +155,7 @@ def get_function_schema(
146
155
147
156
if (
148
157
get_origin(T) is not Literal
149
- and not isinstance(None, T)
158
+ and not is_optional_type(T)
150
159
and default_value is inspect._empty
151
160
):
152
161
schema["required"].append(name)
0 commit comments