a
    tDf                     @  sZ   d Z ddlmZ ddlZddlmZ ddlmZ ejZe	 Z
d
ddZG dd	 d	ZdS )z$
Control global computation context
    )annotationsN)partial)configc                 C  s$   | du rt t||dS t| ||dS )a  Allow function to be taken over by globals

    This modifies a method so that occurrences of it may be taken over by
    functions registered in the global options. Can be used as a decorator or a
    function.

    Parameters
    ----------
    default : callable
        The default callable to use.
    key : str
        Key under which we register this function in the global parameters
    falsey : callable, None, optional
        A function to use if the option is falsey. If not provided, the default
        is used instead.

    Examples
    --------
    >>> import dask
    >>> class Foo:
    ...     @globalmethod(key='bar', falsey=lambda: 3)
    ...     def bar():
    ...         return 1
    >>> f = Foo()
    >>> f.bar()
    1
    >>> with dask.config.set(bar=lambda: 2):
    ...     print(f.bar())
    2
    >>> with dask.config.set(bar=False):
    ...     print(f.bar())
    3
    N)keyfalseydefaultr   r   )r   globalmethodGlobalMethodr    r   Y/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/dask/context.pyr	      s    "r	   c                   @  s    e Zd ZdddZdddZdS )r
   Nc                 C  s   || _ || _|| _d S N)_default_key_falsey)selfr   r   r   r   r   r   __init__9   s    zGlobalMethod.__init__c                 C  s4   | j tv r.t| j  rt| j  S | jd ur.| jS | jS r   )r   _globalsr   r   )r   instanceownerr   r   r   __get__>   s    



zGlobalMethod.__get__)N)N)__name__
__module____qualname__r   r   r   r   r   r   r
   8   s   
r
   )NNN)__doc__
__future__r   	threading	functoolsr   Zdaskr   r   localZthread_stater	   r
   r   r   r   r   <module>   s   
'