Skip to content

Commit 5e8a242

Browse files
committed
Update HierarchyBlock.py
1 parent 9212a5e commit 5e8a242

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

edg/core/HierarchyBlock.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,17 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
149149
for arg_name, arg_param in list(inspect.signature(orig_init).parameters.items())[1:]:
150150
if arg_param.kind not in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
151151
param_expr_type = BlockMeta._ANNOTATION_EXPR_MAP.get(arg_param.annotation, None)
152+
if param_expr_type is None:
153+
raise BlockDefinitionError(new_cls, f"in {new_cls}.__init__, unknown annotation type for {arg_name}: {arg_param.annotation}")
152154
else:
153155
param_expr_type = ConstraintExpr # dummy placeholder
154-
if param_expr_type is None:
155-
raise BlockDefinitionError(new_cls, f"in {new_cls}.__init__, unknown annotation type for {arg_name}: {arg_param.annotation}")
156156

157157
arg_data.append((arg_name, arg_param, param_expr_type))
158158

159159
def wrapped_init(self, *args, **kwargs) -> None:
160160
if not hasattr(self, '_init_params'): # used to communicate to the block the added init params
161161
self._init_params = {}
162162

163-
# this discards extra args at this stage, they will be re-inserted later
164163
def remap_arg(arg_name: str, arg_type: Type[ConstraintExpr], arg_value: Any) -> ConstraintExpr:
165164
if isinstance(arg_value, ConstraintExpr):
166165
if isinstance(arg_value.binding, InitParamBinding) and arg_value.binding.parent is self:
@@ -198,11 +197,11 @@ def remap_arg(arg_name: str, arg_type: Type[ConstraintExpr], arg_value: Any) ->
198197
if arg_name not in new_kwargs:
199198
new_kwargs[arg_name] = kwargs[arg_name]
200199
elif arg_pos < len(args) and arg_param.kind in (inspect.Parameter.POSITIONAL_ONLY,
201-
inspect.Parameter.POSITIONAL_OR_KEYWORD): # present positional arg
200+
inspect.Parameter.POSITIONAL_OR_KEYWORD): # present positional arg
202201
new_arg = remap_arg(arg_name, param_expr_type, args[arg_pos])
203202
new_args.append(new_arg)
204203
self._init_params[arg_name] = new_arg
205-
elif arg_pos >= len(args) and arg_param.kind in (inspect.Parameter.POSITIONAL_ONLY, ): # non-present positional
204+
elif arg_pos >= len(args) and arg_param.kind in (inspect.Parameter.POSITIONAL_ONLY, ): # non-present positional arg
206205
if len(builder.stack) == 1: # at top-level, fill in all args
207206
new_arg = remap_arg(arg_name, param_expr_type, None)
208207
new_args.append(new_arg)
@@ -214,7 +213,7 @@ def remap_arg(arg_name: str, arg_type: Type[ConstraintExpr], arg_value: Any) ->
214213
self._init_params[arg_name] = new_arg
215214
elif arg_name not in kwargs and arg_param.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD,
216215
inspect.Parameter.KEYWORD_ONLY): # non-present kwarg
217-
if arg_param.default is not inspect._empty: # default values do show up in kwargs, always transformed
216+
if arg_param.default is not inspect._empty: # default values do show up in kwargs, add them to transform them
218217
new_arg = remap_arg(arg_name, param_expr_type, arg_param.default)
219218
new_kwargs[arg_name] = new_arg
220219
self._init_params[arg_name] = new_arg

0 commit comments

Comments
 (0)