Skip to content

Commit fb0edf8

Browse files
authored
Merge pull request #73 from pydn/catch_kwargs
Hotfix to pass all parameters to generated code if function allows kw…
2 parents 05f3a93 + 14afc66 commit fb0edf8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

comfyui_to_python.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,18 @@ def generate_workflow(
254254
class_def_params = self.get_function_parameters(
255255
getattr(class_def, class_def.FUNCTION)
256256
)
257+
no_params = class_def_params is None
257258

258259
# Remove any keyword arguments from **inputs if they are not in class_def_params
259260
inputs = {
260-
key: value for key, value in inputs.items() if key in class_def_params
261+
key: value
262+
for key, value in inputs.items()
263+
if no_params or key in class_def_params
261264
}
262265
# Deal with hidden variables
263-
if "unique_id" in class_def_params:
264-
inputs["unique_id"] = random.randint(1, 2**64)
266+
if class_def_params is not None:
267+
if "unique_id" in class_def_params:
268+
inputs["unique_id"] = random.randint(1, 2**64)
265269

266270
# Create executed variable and generate code
267271
executed_variables[idx] = f"{self.clean_variable_name(class_type)}_{idx}"
@@ -471,7 +475,11 @@ def get_function_parameters(self, func: Callable) -> List:
471475
name: param.default if param.default != param.empty else None
472476
for name, param in signature.parameters.items()
473477
}
474-
return list(parameters.keys())
478+
catch_all = any(
479+
param.kind == inspect.Parameter.VAR_KEYWORD
480+
for param in signature.parameters.values()
481+
)
482+
return list(parameters.keys()) if not catch_all else None
475483

476484
def update_inputs(self, inputs: Dict, executed_variables: Dict) -> Dict:
477485
"""Update inputs based on the executed variables.

0 commit comments

Comments
 (0)