Skip to content

Commit 4123f9a

Browse files
authored
Merge pull request #16 from jbaiter/pep563-compat
Add support for PEP568 (fixes #15)
2 parents 46303ab + 6360935 commit 4123f9a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

function_schema/core.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Union,
1010
get_args,
1111
get_origin,
12+
get_type_hints,
1213
)
1314

1415
from .types import FunctionSchema, Doc
@@ -81,9 +82,15 @@ def get_function_schema(
8182
"properties": {},
8283
"required": [],
8384
}
85+
type_hints = get_type_hints(func, include_extras=True)
8486
for name, param in params.items():
85-
param_args = get_args(param.annotation)
86-
is_annotated = get_origin(param.annotation) is Annotated
87+
type_hint = type_hints.get(name)
88+
if type_hint is not None:
89+
param_args = get_args(type_hint)
90+
is_annotated = get_origin(type_hint) is Annotated
91+
else:
92+
param_args = []
93+
is_annotated = False
8794

8895
enum_ = None
8996
default_value = inspect._empty

0 commit comments

Comments
 (0)