o
    i                  
   @   s   d dl mZmZmZmZ ddlZddlmZ ddlm	Z	m
Z
 dddeded	ed
e
e	 fddZG dd dZG dd dZdd ZdefddZdd Zded
efddZG dd deZd"ddZdd Zd d! ZdS )#   )ComfyAPIBaseComfyAPIWithVersionregister_versionsget_all_versions    N)asdict)CallableOptional)baseclsnamer
   returnc                C   s   |du rt | dstd|  }t||d}|du rdS |j}|  D ]}||u r- dS ||jv rCt||j}||urCt| |  S q$dS )zReturn the *callable* override of `name` visible on `cls`, or None if every
    implementation up to (and including) `base` is the placeholder defined on `base`.

    If base is not provided, it will assume cls has a GET_BASE_CLASS
    NGET_BASE_CLASSz[base is required if cls does not have a GET_BASE_CLASS; is this a valid ComfyNode subclass?)hasattr
ValueErrorr   getattr__func__mro__dict__)r   r   r
   	base_attr	base_funccfunc r   9/mnt/c/Users/fbmor/ComfyUI/comfy_api/internal/__init__.pyfirst_real_override   s$   

r   c                   @   s   e Zd ZdZedd ZdS )_ComfyNodeInternalzClass that all V3-based APIs inherit from for ComfyNode.

    This is intended to only be referenced within execution.py, as it has to handle all V3 APIs going forward.c                 C   s   d S Nr   )r   r   r   r   GET_NODE_INFO_V1*   s   z#_ComfyNodeInternal.GET_NODE_INFO_V1N)__name__
__module____qualname____doc__classmethodr   r   r   r   r   r   &   s    r   c                   @   s   e Zd ZdZdS )_NodeOutputInternalzClass that all V3-based APIs inherit from for NodeOutput.

    This is intended to only be referenced within execution.py, as it has to handle all V3 APIs going forward.N)r   r    r!   r"   r   r   r   r   r$   /   s    r$   c                 C   s   t t| S )z8Return dict of dataclass object with pruned None values.)
prune_dictr   )dataclass_objr   r   r   as_pruned_dict6   s   r'   dc                 C   s   dd |   D S )Nc                 S   s   i | ]\}}|d ur||qS r   r   .0kvr   r   r   
<dictcomp>;   s    zprune_dict.<locals>.<dictcomp>)items)r(   r   r   r   r%   :   s   r%   c                 C   s
   t | tS )zT
    Returns True if is a class type.
    Returns False if is a class instance.
    )
isinstancetype)objr   r   r   is_class>   s   
r2   c                 C   sD   | du rdS dd | j  D }t| j| f|}| j|_| j|_|S )z*
    Copy a class and its attributes.
    Nc                 S   s   i | ]\}}|d vr||qS ))r   __weakref__r    r"   r   r)   r   r   r   r-   L   s
    zcopy_class.<locals>.<dictcomp>)r   r.   r0   r   r    r"   )r   cls_dictnew_clsr   r   r   
copy_classF   s   r6   c                   @   s   e Zd Zdd Zdd ZdS )classpropertyc                 C   s
   || _ d S r   f)selfr9   r   r   r   __init__]      
zclassproperty.__init__c                 C   s
   |  |S r   r8   )r:   r1   ownerr   r   r   __get___   r<   zclassproperty.__get__N)r   r    r!   r;   r>   r   r   r   r   r7   \   s    r7   c                 C   s.   |p| j  d}| f| j }t||t| jS )zG
    Shallow clone a class while preserving super() functionality.
    Clone)r   	__bases__r0   dictr   )r   new_name	new_basesr   r   r   shallow_clone_classd   s   rD   c                 C   s>   dd }G dd dt | }t| j}||d< || j| j|S )zJ
    Lock a class so that its top-levelattributes cannot be modified.
    c                 S   s   t d| dt| j )NzCannot set attribute 'z' on immutable instance of )AttributeErrorr0   r   )r:   r   valuer   r   r   locked_instance_setattrs   s   z+lock_class.<locals>.locked_instance_setattrc                   @   s   e Zd Zdd ZdS )zlock_class.<locals>.LockedMetac                 S   s   t d| d| j d)NzCannot modify class attribute 'z' on locked class '')rE   r   )cls_r   rF   r   r   r   __setattr__y   s   z*lock_class.<locals>.LockedMeta.__setattr__N)r   r    r!   rJ   r   r   r   r   
LockedMetax   s    rK   rJ   )r0   rA   r   r   r@   )r   rG   rK   locked_dictr   r   r   
lock_classn   s
   
rM   c                    sB   t | t| |jtr fdd}|S  fdd}|S )z
    Returns a function that, when called with **inputs, will execute:
    getattr(type_obj, func).__func__(lock_class(class_clone), **inputs)

    Supports both synchronous and asynchronous methods.
    c                     s    fi | I d H S r   r   inputslocked_classmethodr   r   wrapped_async_func   s   z3make_locked_method_func.<locals>.wrapped_async_funcc                     s    fi | S r   r   rN   rP   r   r   wrapped_func   s   z-make_locked_method_func.<locals>.wrapped_func)rM   r   r   asyncioiscoroutinefunction)type_objr   class_clonerS   rT   r   rP   r   make_locked_method_func   s   
rY   r   )api_registryr   r   r   r   rU   dataclassesr   typingr   r	   r0   strr   r   r$   r'   rA   r%   r2   r6   objectr7   rD   rM   rY   r   r   r   r   <module>   s   $	

