a
    õ£BeÑ  ã                   @  s”   d dl mZ d dlZd dlZd dlZd dlmZ dddddddd	œd
d„Zdddœdd„Zdddœdd„Z	ddddddœdd„Z
dddœdd„ZdS )é    )ÚannotationsN)ÚAnyFz
str | Noner   ÚboolÚstr)ÚarticleÚvalueÚnameÚverboseÚcapitalÚreturnc                 C  s‚  t | tƒr|  ¡ } t |¡s(t|ƒj}n|j}|r>t|ƒ| }| dks\| du �rDt |¡�sD|durŒ|› d|› �}| dur†t|d|ƒS |S n¶d}t |¡r¢|j}nlt |t	j
ƒrº|j}d}nTt |t	jƒrÔ|jj}d}n:t|ƒjtjtjfv �rdtt|ƒƒ }d}nt|ƒ}d}|�r t|ƒ| }|�r0| d¡}t| ||||d�S n:| d	v �sX| du �rr| du �rf|S t|d|ƒS td
|  ƒ‚dS )aý  Return string that describes a value

    Parameters
    ----------
    article : str or None
        A definite or indefinite article. If the article is
        indefinite (i.e. "a" or "an") the appropriate one
        will be inferred. Thus, the arguments of ``describe``
        can themselves represent what the resulting string
        will actually look like. If None, then no article
        will be prepended to the result. For non-articled
        description, values that are instances are treated
        definitely, while classes are handled indefinitely.
    value : any
        The value which will be named.
    name : str or None (default: None)
        Only applies when ``article`` is "the" - this
        ``name`` is a definite reference to the value.
        By default one will be inferred from the value's
        type and repr methods.
    verbose : bool (default: False)
        Whether the name should be concise or verbose. When
        possible, verbose names include the module, and/or
        class name where an object was defined.
    capital : bool (default: False)
        Whether the first letter of the article should
        be capitalized or not. By default it is not.

    Examples
    --------
    Indefinite description:

    >>> describe("a", object())
    'an object'
    >>> describe("a", object)
    'an object'
    >>> describe("a", type(object))
    'a type'

    Definite description:

    >>> describe("the", object())
    "the object at '...'"
    >>> describe("the", object)
    'the object object'
    >>> describe("the", type(object))
    'the type type'

    Definitely named description:

    >>> describe("the", object(), "I made")
    'the object I made'
    >>> describe("the", object, "I will use")
    'the object I will use'
    ZtheNú TFzat '%s'z'')r   r	   r
   )ÚaÚanzAThe 'article' argument should be 'the', 'a', 'an', or None not %r)Ú
isinstancer   ÚlowerÚinspectÚisclassÚtypeÚ__name__Ú_prefixÚadd_articleÚtypesÚFunctionTypeÚ
MethodTypeÚ__func__Ú__repr__ÚobjectÚhexÚidÚreprÚjoinÚdescribeÚ
ValueError)r   r   r   r	   r
   ÚtypenameÚresultZ	tick_wrap© r%   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitlets/utils/descriptions.pyr!   	   sT    >


þ

ÿr!   )r   r   c                 C  sR   t | tjƒr"td | jdd�d }n,t | ¡}|d urJ|jdkrJ|jd }nd}|S )NT)r	   Ú.ÚbuiltinsÚ )r   r   r   r!   Ú__self__r   Ú	getmoduler   )r   r   Úmoduler%   r%   r&   r   z   s    
r   c                 C  s$   t  | ¡rt| jƒS tt| ƒƒS dS )zsReturns a string of the value's type with an indefinite article.

    For example 'an Image' or 'a PlotValue'.
    N)r   r   r   r   Úclass_ofr   )r   r%   r%   r&   r-   †   s    

r-   )r   Údefiniter
   r   c                 C  sj   |rd|  }n8t  d¡ d| ¡}|dd…  ¡ dv r>d|  }nd|  }|rb|d	  ¡ |dd…  S |S dS )
aè  Returns the string with a prepended article.

    The input does not need to begin with a character.

    Parameters
    ----------
    name : str
        Name to which to prepend an article
    definite : bool (default: False)
        Whether the article is definite or not.
        Indefinite articles being 'a' and 'an',
        while 'the' is definite.
    capital : bool (default: False)
        Whether the added article should have
        its first letter capitalized or not.
    zthe z[\W_]+r)   Né   Zaeiouzan za r   )ÚreÚcompileÚsubr   Úupper)r   r.   r
   r$   Zfirst_lettersr%   r%   r&   r   ‘   s    

r   )Úobjr   c                 C  s   t | ƒ}| ›d|›�}|S )z]Return a string representation of a value and its type for readable

    error messages.
    r   )r   )r4   Zthe_typeÚmsgr%   r%   r&   Ú	repr_type°   s    r6   )NFF)FF)Ú
__future__r   r   r0   r   Útypingr   r!   r   r-   r   r6   r%   r%   r%   r&   Ú<module>   s      ûq