o
    }oi                     @   s   d dl Z d dlZd dlmZmZmZmZmZmZ d dl	Z
eeZddee fddZedddZeG d	d
 d
eee ZeG dd deee Zdee defddZi ZdddZdS )    N)CallableGenericOptionalProtocolTypeVarruntime_checkable
to_capturec                    s*    d u rdd S t   fdd}|S )Nc                 S   s   t | S N)capture)f r   M/home/ubuntu/.local/lib/python3.10/site-packages/nemo/lightning/io/capture.py<lambda>   s    zcapture.<locals>.<lambda>c               
      s   t  tr | i |S  | i |}t|dsbz.t |ttttfr+tt||d}n
tt|}||}t	j
 g| R i ||_|}W |S  tya } ztd|  W Y d }~|S d }~ww t	j
 g| R i ||_|S )N__dict__)
base_valuez"Error creating configurable type: )
isinstance
IOProtocolhasattrintfloatstrtupletype_factorytypefdlPartial__io__	Exceptionloggingerror)argskwargsoutput
new_outputNewTypeer   r   r   wrapper   s&   

zcapture.<locals>.wrapper)	functoolswraps)r   r'   r   r&   r   r
      s
   r
   SelfTT)	covariantc                   @   s$   e Zd Zedeje fddZdS )r   returnc                 C      d S r	   r   selfr   r   r   r   :   s   zIOProtocol.__io__N)__name__
__module____qualname__propertyr   Configr*   r   r   r   r   r   r   8   s    r   c                   @   s   e Zd ZdefddZdS )ReInitProtocolr,   c                 C   r-   r	   r   r.   r   r   r   reinit@   s    zReInitProtocol.reinitN)r0   r1   r2   r*   r6   r   r   r   r   r5   >   s    r5   configurabler,   c                 C   s8   t | tr	|  S t| dstd|  dt| jS )Nr   zCannot reinit z, because it does not have a __io__ attribute)r   r5   r6   r   
ValueErrorr   buildr   )r7   r   r   r   r6   C   s
   

r6   c                 C   s   d| j  }|tv rt| }ntd| j  | fi }|t|< |durAz||}W |S  ty@   td|j  d | }Y |S w |S )a  
    Factory function to create or retrieve from cache a new type that can have additional attributes,
    even if the original type is immutable.

    Args:
        original_type: The type of the original output value.
        base_value: The base value to use for immutable types, if applicable.

    Returns
    -------
        A new type that inherits from the original type and can have additional attributes,
        or an instance of this new type if base_value is provided.
    ConfigurableNzCould not instantiate type z with base value.)r0   
type_cacher   	TypeErrorr   warning)original_typer   	type_namer$   instancer   r   r   r   Q   s   

r   r	   )r(   r   typingr   r   r   r   r   r   fiddler   	getLoggerr0   logr
   r*   r   r5   r6   r;   r   r   r   r   r   <module>   s    
