o
    !2g                     @  s   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 d dl	m
Z
 d dlmZmZ d dlZd dlmZ dd	lmZ eG d
d dZdddZeG dd dZdddZejdddgejdddgejdddgdddZdS )     )annotationsN)	dataclass)Path)check_output)AnyIterator)one   )cachewc                   @  s.   e Zd ZU ded< ded< ded< ded< d	S )
NewStyleTypes1stra_strzdict[str, Any]a_dictz	list[Any]a_listztuple[float, str]a_tupleN__name__
__module____qualname____annotations__ r   r   \/home/garg/my-data/venv/lib/python3.10/site-packages/cachew/tests/test_future_annotations.pyr      s
   
 r   tmp_pathr   returnNonec                   s\   t ddddidg ddd t| d fdd}t|  ks#J t|  ks,J d S )NabacTwhatevergQ	@)ax)aba{   N)gGz?z3.2.1)r   r   r   r   r   Iterator[NewStyleTypes1]c                   3       V  d S Nr   r   objr   r   get%      
ztest_types1.<locals>.get)r   r!   )r   r
   r   r   r&   r   r$   r   test_types1   s   r)   c                   @  s   e Zd ZU ded< ded< dS )NewStyleTypes2z
str | Nonean_optz	str | inta_unionNr   r   r   r   r   r*   .   s   
 r*   c                   sf   t jd d dkrtd tddd t| d fd	d
}t|  ks(J t|  ks1J d S )Nr	   )   	   z,can only use new style union types from 3.10helloi  )r+   r,   r   Iterator[NewStyleTypes2]c                   3  r"   r#   r   r   r$   r   r   r&   @   r'   ztest_types2.<locals>.get)r   r0   )sysversion_infopytestskipr*   r
   r   r(   r   r$   r   test_types25   s   
r5   use_future_annotationsFTlocalthrowboolc                 C  s   | r|r|rt d d| d}d}| rd}nd}||7 }|r.|dtj|dd	 d
7 }n||7 }|d }|| |d }|  ttj|gdt	|it
jdd}	t|	d}
| ri|ri|si|
dksgJ dS |
dksoJ dS )ze
    Checks handling of postponed evaluation of annotations (from __future__ import annotations)
    zIlocal aliases/classses don't work with from __future__ import annotationszi
from pathlib import Path
import tempfile

from cachew import cachew, settings
settings.THROW_ON_ERROR = zE

temp_dir = tempfile.TemporaryDirectory()
td = Path(temp_dir.name)

z
T = int

@cachew(td)
def fun() -> list[T]:
    print("called")
    return [1, 2]

assert list(fun()) == [1, 2]
assert list(fun()) == [1, 2]
z$
from __future__ import annotations
 z
def test() -> None:
 )prefixz	

test()
zrun.pycacheTMPDIRT)envtextcalledr	      N)r3   r4   textwrapindent
write_textmkdirr   r1   
executabler   osenvironintcount)r6   r7   r8   r   	_PREAMBLE_TESTcoderun_py	cache_dirresrA   r   r   r   test_future_annotationsH   s8   

rR   )r   r   r   r   )
r6   r9   r7   r9   r8   r9   r   r   r   r   )
__future__r   rH   r1   rC   dataclassesr   pathlibr   
subprocessr   typingr   r   r3   more_itertoolsr   r:   r
   r   r)   r*   r5   markparametrizerR   r   r   r   r   <module>   s*    

