
    Lg                        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y)
z$
Control global computation context
    )annotationsN)partial)configc                F    | 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
    )keyfalseydefaultr   r   )r   globalmethodGlobalMethodr	   s      ,lib/python3.12/site-packages/dask/context.pyr   r      s(    D |V<<S@@    c                      e Zd ZddZddZy)r   Nc                .    || _         || _        || _        y N)_default_key_falsey)selfr
   r   r   s       r   __init__zGlobalMethod.__init__:   s    	r   c                    | j                   t        v r>t        | j                      rt        | j                      S | j                  | j                  S | j                  S r   )r   _globalsr   r   )r   instanceowners      r   __get__zGlobalMethod.__get__?   sG    99 		"		**)||#}}r   r   )__name__
__module____qualname__r   r    r   r   r   r   9   s    
r   r   )NNN)__doc__
__future__r   	threading	functoolsr   daskr   r   localthread_stater   r   r   r   r   <module>r'      sB    #   == y $AN r   