B
    T\                 @   sl   d Z ddlmZmZmZ ddlZddlmZ ddlm	Z	 e	j	Z
e Zdd Zdd	d
ZG dd deZdS )z$
Control global computation context
    )absolute_importdivisionprint_functionN)partial   )configc              O   s   t ddS )z) Deprecated: see dask.config.set instead zThe dask.set_options function has been deprecated.
Please use dask.config.set instead

  Before: with dask.set_options(foo='bar'):
              ...
  After:  with dask.config.set(foo='bar'):
              ...N)	TypeError)argskwargs r   +lib/python3.7/site-packages/dask/context.pyset_options   s    r   c             C   s$   | dk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(object):
    ...     @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GlobalMethod)r   r   r   r   r   r   r      s    "r   c               @   s    e Zd ZdddZdddZdS )r   Nc             C   s   || _ t|| _|| _d S )N)_defaultr   Znormalize_key_key_falsey)selfr   r   r   r   r   r   __init__B   s    zGlobalMethod.__init__c             C   s4   | j tkr.t| j  rt| j  S | jd k	r.| jS | jS )N)r   _globalsr   r   )r   instanceownerr   r   r   __get__G   s    



zGlobalMethod.__get__)N)N)__name__
__module____qualname__r   r   r   r   r   r   r   A   s   
r   )NNN)__doc__Z
__future__r   r   r   Z	threading	functoolsr    r   r   ZlocalZthread_stater   r   objectr   r   r   r   r   <module>   s   

'