a
    7a                     @   sH   d dl Z d dlZd dlZdddZdd Zdd Zdd	d
Zdd ZdS )    NFc                 C   s  t | tr|  } t|s(t|j}n|j}|r>t|| }| dks\| du rBt|sB|durd||}| durt	|d|S |S nd}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|| }|r.|d}t| ||||dS n:| d	v sV| du rp| du rd|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 infered. 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 infered 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 '0x10741f1b0'"
    >>> describe("the", object)
    "the type '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theNz{} {}TFzat '%s'z'')nameverbosecapital)aZanzAThe 'article' argument should be 'the', 'a', 'an', or None not %r)
isinstancestrlowerinspectisclasstype__name___prefixformatadd_articletypesFunctionType
MethodType__func____repr__objecthexidreprjoindescribe
ValueError)Zarticlevaluer   r   r   typenameresultZ	tick_wrap r   ;lib/python3.9/site-packages/traitlets/utils/descriptions.pyr      sR    8




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	   Z	getmoduler   )r   r   moduler   r   r    r   n   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&   z   s    

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 charater.

    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   Zdefiniter   r   Zfirst_lettersr   r   r    r      s    

r   c                 C   s   t | }d| |}|S )z]Return a string representation of a value and its type for readable

    error messages.
    z	{!r} {!r})r   r   )objZthe_typemsgr   r   r    	repr_type   s    r.   )NFF)FF)r	   r(   r   r   r   r&   r   r.   r   r   r   r    <module>   s   
h
