o
    eiE                     @  s   d Z ddlm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
 ddlmZ e	r0ddlmZ g d	Ze
d
Zeejddd"ddZeejddd"ddZeejddd#d$ddZeejddd#d%ddZG dd dZe Zefd d!ZdS )&z
Python polyfills for builtins
    )annotationsN)Callable)TYPE_CHECKINGTypeVar   )substitute_in_graph)Iterable)allany	enumeratesum_TT)can_constant_fold_throughiterableIterable[object]returnboolc                C  s   | D ]}|s	 dS qdS )NFT r   elemr   r   j/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/_dynamo/polyfills/builtins.pyr	      
   r	   c                C  s   | D ]}|r	 dS qdS )NTFr   r   r   r   r   r
   '   r   r
   )is_embedded_typeIterable[_T]startintIterable[tuple[int, _T]]c                 c  s@    t |tstt|jd| D ]}||fV  |d7 }qd S )Nz+ object cannot be interpreted as an integer   )
isinstancer   	TypeErrortype__name__)r   r   xr   r   r   r   /   s   


r   c                C  s   t tj| |S N)	functoolsreduceoperatoradd)r   r   r   r   r   r   ;   s   r   c                   @  s$   e Zd Zdd Zdd Zdd ZdS )_CallableIteratorc                 C  s   || _ || _d S r#   )fnsentinel)selfr)   r*   r   r   r   __init__A   s   
z_CallableIterator.__init__c                 C  s   | S r#   r   )r+   r   r   r   __iter__E   s   z_CallableIterator.__iter__c                 C  s   |   }|| jkrt|S r#   )r)   r*   StopIteration)r+   rr   r   r   __next__H   s   
z_CallableIterator.__next__N)r!   
__module____qualname__r,   r-   r0   r   r   r   r   r(   @   s    r(   c                C  s   |t u r7| }t|dr | }t|dr|S tdt| dt|dr-dd }||S tdt| d| }t|tsBtdt||S )	Nr-   r0   'z' object is not iterable__getitem__c                 s  s8    d}	 z|  |V  |d7 }W n
 ty   Y d S w q)Nr   Tr   )r4   
IndexError)r   ir   r   r   sequence_protocolg   s   z iter_.<locals>.sequence_protocolz iter(v, w): v must be a callable)_sentinel_missinghasattrr-   r   r    r   r   r(   )fn_or_iterabler*   r   iteratorr7   r)   r   r   r   iter_Y   s   


	

r<   )r   r   r   r   )r   )r   r   r   r   r   r   )r   r   r   r   r   r   )__doc__
__future__r   builtinsr$   r&   collections.abcr   typingr   r   
decoratorsr   r   __all__r   r	   r
   r   r   r(   objectr8   r<   r   r   r   r   <module>   s.    