U
    zh                     @   sd   d dl Z d dlmZ d dlmZmZ G dd deZe jddee ddd	Z	G d
d dZ
dS )    Nfields)HashableSetc                   @   s8   e Zd ZU eed< edd ZedddZdd Z	d	S )
	_UnionTag_clsc                 C   s    t | }t|drt||_|S )Nr   )r   hasattrAssertionErrorr   )tclstag r   K/var/www/html/venv/lib/python3.8/site-packages/torch/_export/serde/union.pycreate
   s    z_UnionTag.createreturnc                 C   sP   t |tstt|}|t| jksDt| d| j dt| j t| |kS )Nz is not a valid tag for z. Available tags: )
isinstancestrr	   _get_field_namesr   )selfcmpotherr   r   r   __eq__   s    z_UnionTag.__eq__c                 C   s   t t| S N)hashr   r   r   r   r   __hash__   s    z_UnionTag.__hash__N)
__name__
__module____qualname__r   __annotations__staticmethodr   boolr   r   r   r   r   r   r      s
   

r   )maxsizer   c                 C   s   dd t | D S )Nc                 S   s   h | ]
}|j qS r   name.0fr   r   r   	<setcomp>   s     z#_get_field_names.<locals>.<setcomp>r   )r   r   r   r   r      s    r   c                       sh   e Zd ZU eed< edd Zdd Zee	dddZ
ed	d
 Z fddZdd Zdd Z  ZS )_Union_typec                 K   sJ   t |dkst| f dd t| D |}ttt| | |_|S )N   c                 S   s   i | ]}|j d qS r   r$   r&   r   r   r   
<dictcomp>(   s      z!_Union.create.<locals>.<dictcomp>)	lenr	   r   r   r   nextiterkeysr+   )r   kwargsobjr   r   r   r   %   s    z_Union.createc                 C   s   t dd t| D rtd S )Nc                 s   s   | ]}|j d kV  qdS ))typer+   r   valueNr$   r&   r   r   r   	<genexpr>-   s     z'_Union.__post_init__.<locals>.<genexpr>)anyr   r	   r   r   r   r   __post_init__,   s    z_Union.__post_init__r   c              
   C   sH   z| j W S  tk
rB } ztdt| j d|W 5 d }~X Y nX d S )NzPlease use z&.create to instantiate the union type.)r+   AttributeErrorRuntimeErrorr4   r   )r   er   r   r   r4   /   s    z_Union.typec                 C   s   t | | jS r   )getattrr4   r   r   r   r   r5   8   s    z_Union.valuec                    sB   t  |}|d kr>|tt| kr>|| jkr>td| d|S )NzField z is not set.)super__getattribute__r   r4   r9   )r   r%   attr	__class__r   r   r>   <   s    "z_Union.__getattribute__c                 C   s   |   S r   )__repr__r   r   r   r   __str__B   s    z_Union.__str__c                 C   s&   t | j d| j  dt| | j  dS )N(=))r4   r   r<   r   r   r   r   rB   E   s    z_Union.__repr__)r   r   r   r   r    classmethodr   r8   propertyr   r4   r5   r>   rC   rB   __classcell__r   r   r@   r   r*   "   s   


r*   )	functoolsdataclassesr   typingr   r   r   r   	lru_cacher   r*   r   r   r   r   <module>   s   
