mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-13 15:03:33 +00:00
Correctly modify staticmethods
This commit is contained in:
parent
8cc5326beb
commit
b367f21774
48
nodes.py
48
nodes.py
@ -10,7 +10,7 @@ import math
|
|||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
from inspect import signature
|
import inspect
|
||||||
|
|
||||||
from PIL import Image, ImageOps, ImageSequence
|
from PIL import Image, ImageOps, ImageSequence
|
||||||
from PIL.PngImagePlugin import PngInfo
|
from PIL.PngImagePlugin import PngInfo
|
||||||
@ -2151,17 +2151,43 @@ def modify_function_params(cls):
|
|||||||
if not hasattr(cls, 'FUNCTION'):
|
if not hasattr(cls, 'FUNCTION'):
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
function = getattr(cls, cls.FUNCTION)
|
method_name = getattr(cls, 'FUNCTION')
|
||||||
sig = signature(function)
|
is_static = isinstance(
|
||||||
|
inspect.getattr_static(cls, method_name),
|
||||||
|
staticmethod)
|
||||||
|
|
||||||
if 'onTrigger' not in sig.parameters.keys():
|
if is_static:
|
||||||
def _function(self, *args, **kwargs):
|
original_method = inspect.getattr_static(cls, method_name)
|
||||||
if 'onTrigger' in kwargs.keys():
|
else:
|
||||||
del kwargs['onTrigger']
|
original_method = getattr(cls, method_name)
|
||||||
bound_args = sig.bind(self, *args, **kwargs)
|
|
||||||
bound_args.apply_defaults()
|
sig = inspect.signature(original_method)
|
||||||
return function(*bound_args.args, **bound_args.kwargs)
|
|
||||||
setattr(cls, cls.FUNCTION, _function)
|
if 'onTrigger' in sig.parameters.keys():
|
||||||
|
return cls
|
||||||
|
|
||||||
|
# Define a wrapper function that uses the new signature
|
||||||
|
def _function(*args, **kwargs):
|
||||||
|
if 'onTrigger' in kwargs.keys():
|
||||||
|
del kwargs['onTrigger']
|
||||||
|
bound_args = sig.bind(*args, **kwargs)
|
||||||
|
bound_args.apply_defaults()
|
||||||
|
|
||||||
|
if is_static:
|
||||||
|
return original_method(*bound_args.args, **bound_args.kwargs)
|
||||||
|
else:
|
||||||
|
# For instance methods, ensure 'self' is correctly passed
|
||||||
|
self_instance = args[0]
|
||||||
|
method_args = bound_args.args[1:]
|
||||||
|
method_kwargs = bound_args.kwargs
|
||||||
|
return original_method(
|
||||||
|
self_instance, *method_args, **method_kwargs)
|
||||||
|
|
||||||
|
# Assign the new function directly to the class attribute
|
||||||
|
if is_static:
|
||||||
|
setattr(cls, method_name, staticmethod(_function))
|
||||||
|
else:
|
||||||
|
setattr(cls, method_name, _function)
|
||||||
|
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user