U
    §Ê¹j  ã                   @   s\  U d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	 d dl
mZmZ d dlmZmZ dd„ Zee	e eedœd	d
„Zedœdd„Zedœdd„Zedœdd„Zeeedœdd„Zeeeedœdd„Zeeee	e edœdd„Zeeeeeddd�eeddd�eed d!d"d#�eed$d!d%d#�eed&d'd"d#�eed(d'd%d#�d)œ	Zeeef ed*< dS )+é    N)Úpartial)ÚCallableÚDictÚList)ÚFAKE_FILENAME_PREFIXÚis_optional)Ú	ParsedDefÚSourceContextc                 C   s   t j t| j|¡S ©N)ÚosÚpathÚjoinr   Ú__name__)ÚclsÚmethod_name© r   úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/jit/_dataclass_impls.pyÚ_get_fake_filename   s    r   )ÚnameÚ
body_linesÚ	signatureÚreturnc           	   
   C   sœ   d  dd„ |D ƒ¡}d|› |› d|› �}zt |¡}W n< tk
rr } ztd|› d| j› d�ƒ|‚W 5 d }~X Y nX t| |ƒ}t|t||d	d	d
�||d	d�S )NÚ
c                 s   s   | ]}d |› �V  qdS )ú  Nr   )Ú.0Úbr   r   r   Ú	<genexpr>   s     zcompose_fn.<locals>.<genexpr>zdef z:
z3TorchScript failed to synthesize dataclass method 'z' for class 'zJ'. Please file a bug report at <https://github.com/pytorch/pytorch/issues>r   )ÚsourceÚfilenameÚfile_linenoZleading_whitespace_len)Úctxr   r   r   )	r   ÚastÚparseÚSyntaxErrorÚRuntimeErrorr   r   r   r	   )	r   r   r   r   ÚbodyÚdeclZpy_astÚeZfake_filenamer   r   r   Ú
compose_fn   s.    ÿý
   ÿùr(   )r   c                    sä   t dd„ t | ¡D ƒƒr tdƒ‚t | j¡}g ‰ g }|j ¡ D ]D\}}|j	}t
|tjƒrxˆ  |¡ | |j|jd�¡ q>| |¡ q>|j|d�}‡ fdd„t | ¡D ƒ}t| dƒrÊ| d	d
 ˆ ¡ d ¡ t| d|pØdgt|ƒd�S )Nc                 s   s   | ]}|j tjk	V  qd S r
   )Údefault_factoryÚdataclassesÚMISSING©r   Úfieldr   r   r   r   /   s   ÿz%synthesize__init__.<locals>.<genexpr>zIDefault factory initializers are not supported in TorchScript dataclasses)Ú
annotation)Ú
parametersc                    s0   g | ](}|j r|jˆ krd |j› d|j› �‘qS )zself.z = )Úinitr   r,   ©Z	init_varsr   r   Ú
<listcomp>K   s    
þz&synthesize__init__.<locals>.<listcomp>Ú__post_init__zself.__post_init__(ú, ú)Ú__init__Úpass©r   )Úanyr*   ÚfieldsÚNotImplementedErrorÚinspectr   r6   r/   Úitemsr.   Ú
isinstanceÚInitVarÚappendÚreplaceÚtypeÚhasattrr   r(   Ústr)r   r   Úparamsr   ÚparamÚannr%   r   r1   r   Úsynthesize__init__,   s,    þÿ

ý
rH   c              
   C   s:   t | dd| j› d�d dd„ t | ¡D ƒ¡ d gdd	�S )
NÚ__repr__zreturn 'ú(r4   c                 S   s$   g | ]}|j r|j› d |j› �‘qS )z=self.)Úreprr   r,   r   r   r   r2   `   s   þz&synthesize__repr__.<locals>.<listcomp>z)'z(self) -> strr8   )r(   r   r   r*   r:   ©r   r   r   r   Úsynthesize__repr__Y   s    þÿÿøÿòrM   c                 C   s   t | ddgdd�S )NÚ__hash__zUraise NotImplementedError('__hash__ is not supported for dataclasses in TorchScript')z(self) -> intr8   )r(   rL   r   r   r   Úsynthesize__hash__l   s    ýørO   )r   Úconverser   c                 C   s   t | |ddd|› d�gd�S )NTFúif val1 z val2: return False)Úallow_eqÚraise_on_noneÚinner©Úsynthesize_comparison)r   r   rP   r   r   r   Úsynthesize_equalityz   s    ûrW   )r   ÚoprR   r   c              	   C   s&   t | ||dd|› d�d|› d�gd�S )NTrQ   z val2: return Truez
elif val2 z val1: return False)rS   rT   rU   )r   r   rX   rR   r   r   r   Úsynthesize_inequality„   s    

þûrY   )r   rR   rS   rT   r   c              	   C   s¢   g }t  | ¡D ]h}|jsq| d|j› �d|j› �g¡ | t|jƒsJ|n(ddd„ |D ƒd|rld| j› d�nd	f•¡ q| d
|› �¡ t	| ||d| j› d�d�S )Nzval1 = self.zval2 = other.ú)if val1 is not None and val2 is not None:c                 S   s   g | ]}d | ‘qS )r   r   )r   Úliner   r   r   r2   ¥   s     z)synthesize_comparison.<locals>.<listcomp>z&elif (val1 is None) != (val2 is None):z"  raise TypeError('Cannot compare z with None')z  return Falsezreturn z(self, other: z	) -> boolr8   )rZ   )
r*   r:   ÚcompareÚextendr   r   rB   r   r@   r(   )r   r   rR   rS   rT   r%   r-   r   r   r   rV   ‘   s8    

þÿÿ þÿùý   ÿrV   Ú__eq__z!=)r   rP   Ú__ne__z==Ú__lt__ú<F)r   rX   rR   Ú__le__TÚ__gt__ú>Ú__ge__)	r6   rI   rN   r^   r_   r`   rb   rc   re   ÚDATACLASS_MAGIC_METHODS)r!   r*   r<   r   Ú	functoolsr   Útypingr   r   r   Ztorch._jit_internalr   r   Ztorch._sourcesr   r	   r   rD   r(   rH   rM   rO   rW   ÚboolrY   rV   rf   Ú__annotations__r   r   r   r   Ú<module>   s>    -
   þ#÷