U
    42‹i  ã                   @  sz   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ ddgZedƒZed	ƒZ	G d
d„ dee ƒZ
G dd„ dƒZdS )é    )Úannotations)ÚAny)Úcast)ÚGeneric)ÚTypeVarÚStashÚStashKeyÚTÚDc                   @  s   e Zd ZdZdZdS )r   zï``StashKey`` is an object used as a key to a :class:`Stash`.

    A ``StashKey`` is associated with the type ``T`` of the value of the key.

    A ``StashKey`` is unique and cannot conflict with another key.

    .. versionadded:: 7.0
    © N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   ú1/tmp/pip-unpacked-wheel-7n2p7kht/_pytest/stash.pyr      s   	c                   @  s–   e Zd ZdZdZddœdd„Zdddd	œd
d„Zdddœdd„Zddddœdd„Zddddœdd„Z	dddœdd„Z
dddœdd„Zddœdd„ZdS )r   aJ  ``Stash`` is a type-safe heterogeneous mutable mapping that
    allows keys and value types to be defined separately from
    where it (the ``Stash``) is created.

    Usually you will be given an object which has a ``Stash``, for example
    :class:`~pytest.Config` or a :class:`~_pytest.nodes.Node`:

    .. code-block:: python

        stash: Stash = some_object.stash

    If a module or plugin wants to store data in this ``Stash``, it creates
    :class:`StashKey`\s for its keys (at the module level):

    .. code-block:: python

        # At the top-level of the module
        some_str_key = StashKey[str]()
        some_bool_key = StashKey[bool]()

    To store information:

    .. code-block:: python

        # Value type must match the key.
        stash[some_str_key] = "value"
        stash[some_bool_key] = True

    To retrieve the information:

    .. code-block:: python

        # The static type of some_str is str.
        some_str = stash[some_str_key]
        # The static type of some_bool is bool.
        some_bool = stash[some_bool_key]

    .. versionadded:: 7.0
    ©Ú_storageÚNone)Úreturnc                 C  s
   i | _ d S )Nr   ©Úselfr   r   r   Ú__init__H   s    zStash.__init__zStashKey[T]r	   )ÚkeyÚvaluer   c                 C  s   || j |< dS )zSet a value for key.Nr   )r   r   r   r   r   r   Ú__setitem__K   s    zStash.__setitem__)r   r   c                 C  s   t t| j| ƒS )zZGet the value for key.

        Raises ``KeyError`` if the key wasn't set before.
        )r   r	   r   ©r   r   r   r   r   Ú__getitem__O   s    zStash.__getitem__r
   zT | D)r   Údefaultr   c                 C  s(   z
| | W S  t k
r"   | Y S X dS )zNGet the value for key, or return default if the key wasn't set
        before.N©ÚKeyError©r   r   r   r   r   r   ÚgetV   s    
z	Stash.getc                 C  s0   z
| | W S  t k
r*   || |< | Y S X dS )zmReturn the value of key if already set, otherwise set the value
        of key to default and return default.Nr   r!   r   r   r   Ú
setdefault^   s
    
zStash.setdefaultc                 C  s   | j |= dS )z]Delete the value for key.

        Raises ``KeyError`` if the key wasn't set before.
        Nr   r   r   r   r   Ú__delitem__g   s    zStash.__delitem__Úboolc                 C  s
   || j kS )zReturn whether key was set.r   r   r   r   r   Ú__contains__n   s    zStash.__contains__Úintc                 C  s
   t | jƒS )z)Return how many items exist in the stash.)Úlenr   r   r   r   r   Ú__len__r   s    zStash.__len__N)r   r   r   r   r   r   r   r   r"   r#   r$   r&   r)   r   r   r   r   r      s   (	N)Ú
__future__r   Útypingr   r   r   r   Ú__all__r	   r
   r   r   r   r   r   r   Ú<module>   s   