Skip to content

Commit

Permalink
Merge pull request #73 from pydn/catch_kwargs
Browse files Browse the repository at this point in the history
Hotfix to pass all parameters to generated code if function allows kw…
  • Loading branch information
pydn authored Sep 12, 2024
2 parents 05f3a93 + 14afc66 commit fb0edf8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions comfyui_to_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,18 @@ def generate_workflow(
class_def_params = self.get_function_parameters(
getattr(class_def, class_def.FUNCTION)
)
no_params = class_def_params is None

# Remove any keyword arguments from **inputs if they are not in class_def_params
inputs = {
key: value for key, value in inputs.items() if key in class_def_params
key: value
for key, value in inputs.items()
if no_params or key in class_def_params
}
# Deal with hidden variables
if "unique_id" in class_def_params:
inputs["unique_id"] = random.randint(1, 2**64)
if class_def_params is not None:
if "unique_id" in class_def_params:
inputs["unique_id"] = random.randint(1, 2**64)

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

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

0 comments on commit fb0edf8

Please sign in to comment.