o
    c²“iq
  ã                   @   sœ   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlm	Z	 d dlm
Z d dlmZ z
d dlmZmZ W n eyG   d	d
„ Zdd„ ZY nw dd„ ZdS )é    )ÚOrderedDict)ÚIterator)ÚgetitemN)Úquote)Úget)Úapply)Úis_dataclassÚfieldsc                 C   s   dS )NF© ©Úxr
   r
   úH/home/ubuntu/.local/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   E   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   0   s0   

þþüz#unpack_object_refs.<locals>._unpackc                    r   r
   r
   r   r   r
   r   r   Q   r   z&unpack_object_refs.<locals>.<listcomp>c                    s   ˆ  ¡ }t| ƒ|ˆ < t|ˆƒS r   )Úcopyr   Úget_sync)ÚresultsÚdsk)r1   Úoutr2   r
   r   ÚrepackS   s   
z"unpack_object_refs.<locals>.repack)r%   r&   r"   r)   )Úargsr8   r
   )r   r0   r1   r7   r2   r   Úunpack_object_refs   s   

 r:   )Úcollectionsr   Úcollections.abcr   Úoperatorr   r%   r    Ú	dask.corer   r   r4   Ú
dask.utilsr   Údataclassesr   r	   r   ÚImportErrorr:   r
   r
   r
   r   Ú<module>   s    û	