Skip to content

Commit

Permalink
fix: inspect value empty for defaults in check cmd (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
julesbertrand committed Mar 1, 2024
1 parent 32351db commit 5536f67
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions deployer/utils/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from inspect import signature
from inspect import Parameter, signature
from typing import Callable, Literal, Optional, Protocol

from pydantic import BaseModel, ConfigDict, create_model
Expand Down Expand Up @@ -44,13 +44,18 @@ def create_model_from_func(

func_signature = signature(func)

func_typing = {
p.name: (
type_converter(p.annotation),
... if (exclude_defaults or p.default == Parameter.empty) else p.default,
)
for p in func_signature.parameters.values()
}

func_model = create_model(
__model_name=model_name,
__base__=CustomBaseModel,
**{
p.name: (type_converter(p.annotation), ... if exclude_defaults else p.default)
for p in func_signature.parameters.values()
},
**func_typing,
)

return func_model
Expand Down

0 comments on commit 5536f67

Please sign in to comment.