o
    $i\
                     @   s   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mZ d dlZz
d dlmZmZ W n eyC   dd	 Zd
d ZY nw dd ZdS )    N)OrderedDict)Iterator)getitem)getquote)apply)fieldsis_dataclassc                 C   s   dS )NF xr
   r
   Q/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/util/dask/common.pyr	         r	   c                 C   s   g S Nr
   r   r
   r
   r   dataclass_fields   r   r   c                     s`   g i t  j fdd t  jt fdd| D f< fdd}|fS )a  
    Extract Ray object refs from a set of potentially arbitrarily nested
    Python objects.

    Intended use is to find all Ray object references in a set of (possibly
    nested) Python objects, do something to them (get(), wait(), etc.), then
    repackage them into equivalent Python objects.

    Args:
        *args: One or more (potentially nested) Python objects that contain
            Ray object references.

    Returns:
        A 2-tuple of a flat list of all contained Ray object references, and a
        function that, when given the corresponding flat list of concrete
        values, will return a set of Python objects equivalent to that which
        was given in *args, but with all Ray object references replaced with
        their corresponding concrete values.
    c                    s   t  tjr  }ttf|<   |S t j}t  t	r&t
nt }|t
ttfv r=|fdd D f}n-|ttfv rQ|fdd  D f}nt rht|dt fddt D ff}n S ||< |S )Nc                       g | ]} |qS r
   r
   .0i_unpackr
   r   
<listcomp>:       z7unpack_object_refs.<locals>._unpack.<locals>.<listcomp>c                    s    g | ]\}} | |gqS r
   r
   )r   kvr   r
   r   r   <   s     r
   c                    s"   g | ]}|j  t|j gqS r
   )namegetattr)r   f)r   exprr
   r   r   D   s    )
isinstanceray	ObjectRefhexr   lenappenduuiduuid4r   listtypetuplesetdictr   itemsr	   r   r   )r   tokentyprepack_task)r   object_refsobject_refs_token
repack_dsk)r   r   r   /   s0   

z#unpack_object_refs.<locals>._unpackc                    r   r
   r
   r   r   r
   r   r   P   r   z&unpack_object_refs.<locals>.<listcomp>c                    s     }t| | < t|S r   )copyr   get_sync)resultsdsk)r1   outr2   r
   r   repackR   s   
z"unpack_object_refs.<locals>.repack)r%   r&   r"   r)   )argsr8   r
   )r   r0   r1   r7   r2   r   unpack_object_refs   s   

 r:   )r%   collectionsr   collections.abcr   operatorr   	dask.corer   r4   r   
dask.utilsr   r    dataclassesr   r   r	   ImportErrorr:   r
   r
   r
   r   <module>   s    	