
    >ie                        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j	                    Z
d	dZ G d d          ZdS )
z$
Control global computation context
    )annotationsN)partial)configc                X    | t          t          ||          S t          | ||          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	   s      ,lib/python3.11/site-packages/dask/context.pyr   r      s4    D |V<<<<S@@@@    c                      e Zd ZddZddZdS )r   Nc                0    || _         || _        || _        d S N)_default_key_falsey)selfr
   r   r   s       r   __init__zGlobalMethod.__init__9   s    	r   c                    | j         t          v r2t          | j                  rt          | j                  S | j        | j        S | j        S r   )r   _globalsr   r   )r   instanceowners      r   __get__zGlobalMethod.__get__>   sC    9  	" $	**)|#}r   r   )__name__
__module____qualname__r   r    r   r   r   r   8   s<           
     r   r   )NNN)__doc__
__future__r   	threading	functoolsr   daskr   r   localthread_stater   r   r   r   r   <module>r'      s     # " " " " "                = y  $A $A $A $AN         r   