Skip to content

Commit

Permalink
Skip unbound arguments when generating signature schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed May 26, 2020
1 parent a03f1b5 commit b8ed956
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/labthings/server/types/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def convert(self, parameter, **kwargs) -> FieldABC:
if isinstance(parameter, Parameter):
typehint = parameter.annotation
optional = not (parameter.default is parameter.empty)
if parameter.kind == "VAR_POSITIONAL":
# Handle unbound *args parameters
pass
if parameter.kind == "VAR_KEYWORD":
# Handle unbound **kwargs parameters
pass
# Skip unbound arguments (e.g. *args, **kwargs) until we find a better way to handle them
if (
parameter.kind == Parameter.VAR_POSITIONAL
or parameter.kind == Parameter.VAR_KEYWORD
):
return None
elif isinstance(parameter, type):
typehint = parameter
else:
Expand Down Expand Up @@ -72,6 +72,8 @@ def function_signature_to_schema(function: callable):
params = inspect.signature(function).parameters

for k, p in params.items():
schema_dict[k] = converter.convert(p)
param_schema = converter.convert(p)
if param_schema:
schema_dict[k] = converter.convert(p)

return schema_dict

0 comments on commit b8ed956

Please sign in to comment.