U
    nËj`  ã                   @  s’   U d Z ddlmZ ddlZddlZddlmZ ddlZddlm	Z	 ej
r`dZded	< d
Zded< G dd„ deƒZG dd„ dƒZdddœdd„ZdS )z:Tools to provide pretty/human-readable display of objects.é    )ÚannotationsN)ÚAnyé   )Ú_typing_extraz'typing.Iterable[tuple[str | None, Any]]ztyping_extensions.TypeAliasÚReprArgszJtyping.Iterable[Any | tuple[Any] | tuple[str, Any] | tuple[str, Any, Any]]ÚRichReprResultc                   @  s   e Zd ZdZddœdd„ZdS )Ú	PlainReprz¸String class where repr doesn't include quotes. Useful with Representation when you want to return a string
    representation of something that is valid (or pseudo-valid) python.
    Ústr©Úreturnc                 C  s   t | ƒS ©N)r	   ©Úself© r   ú</tmp/pip-unpacked-wheel-zvl9l234/pydantic/_internal/_repr.pyÚ__repr__   s    zPlainRepr.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   @  sˆ   e Zd ZdZddœdd„Zddœdd„Zd	dd
œdd„Zdddœdd„Zdd	ddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„ZdS )ÚRepresentationr   r   r
   c                   sB   ˆ j }|stˆ dƒrˆ j ¡ }‡ fdd„|D ƒ}‡ fdd„|D ƒS )a-  Returns the attributes to show in __str__, __repr__, and __pretty__ this is generally overridden.

        Can either return:
        * name - value pairs, e.g.: `[('foo_name', 'foo'), ('bar_name', ['b', 'a', 'r'])]`
        * or, just values, e.g.: `[(None, 'foo'), (None, ['b', 'a', 'r'])]`
        Ú__dict__c                 3  s   | ]}|t ˆ |ƒfV  qd S r   )Úgetattr)Ú.0Úsr   r   r   Ú	<genexpr>0   s     z/Representation.__repr_args__.<locals>.<genexpr>c                   s2   g | ]*\}}|d k	r||ˆ k	r"|nˆ   |¡f‘qS r   )Ú__repr_recursion__©r   ÚaÚvr   r   r   Ú
<listcomp>1   s      z0Representation.__repr_args__.<locals>.<listcomp>)Ú	__slots__Úhasattrr   Úkeys)r   Zattrs_namesÚattrsr   r   r   Ú__repr_args__&   s
    
zRepresentation.__repr_args__r	   c                 C  s   | j jS )z/Name of the instance's class, used in __repr__.)Ú	__class__r   r   r   r   r   Ú__repr_name__3   s    zRepresentation.__repr_name__r   )Úobjectr   c                 C  s   dt |ƒj› dt|ƒ› d�S )z8Returns the string representation of a recursive object.z<Recursion on z	 with id=ú>)Útyper   Úid)r   r(   r   r   r   r   7   s    z!Representation.__repr_recursion__)Újoin_strr   c                 C  s   |  dd„ |  ¡ D ƒ¡S )Nc                 s  s0   | ](\}}|d krt |ƒn|› d|›�V  qd S )Nú=)Úreprr   r   r   r   r   =   s     z.Representation.__repr_str__.<locals>.<genexpr>)Újoinr%   )r   r,   r   r   r   Ú__repr_str__<   s    zRepresentation.__repr_str__ztyping.Callable[[Any], Any]z!typing.Generator[Any, None, None])ÚfmtÚkwargsr   c                 k  s^   |   ¡ d V  dV  |  ¡ D ]0\}}|dk	r6|d V  ||ƒV  dV  dV  qdV  dV  dS )	zRUsed by devtools (https://python-devtools.helpmanual.io/) to pretty print objects.ú(r   Nr-   ú,r   éÿÿÿÿú))r'   r%   )r   r1   r2   ÚnameÚvaluer   r   r   Ú
__pretty__?   s    

zRepresentation.__pretty__r   c                 c  s0   |   ¡ D ]"\}}|dkr |V  q||fV  qdS )zYUsed by Rich (https://rich.readthedocs.io/en/stable/pretty.html) to pretty print objects.N)r%   )r   r7   Z
field_reprr   r   r   Ú__rich_repr__L   s    zRepresentation.__rich_repr__c                 C  s
   |   d¡S )Nú )r0   r   r   r   r   Ú__str__T   s    zRepresentation.__str__c                 C  s   |   ¡ › d|  d¡› d�S )Nr3   ú, r6   )r'   r0   r   r   r   r   r   W   s    zRepresentation.__repr__N)r   r   r   r!   r%   r'   r   r0   r9   r:   r<   r   r   r   r   r   r      s   r   r   r	   )Úobjr   c                 C  sZ  t | tjtjfƒr| jS | dkr$dS t | tƒr6t| ƒS t | tjƒsLt	 
| ¡rTt| ƒS t | t	jt	jtfƒsn| j} t	 t | ¡¡r d ttt | ¡ƒ¡}d|› d�S t | t	jƒ�r,t	 | ¡rÐd ttt | ¡ƒ¡}nd ttt | ¡ƒ¡}z| j› d|› d�W S  tk
�r(   t| ƒ dd¡ d	d¡ Y S X n*t | tƒ�r>| jS t| ƒ dd¡ d	d¡S d
S )zœPretty representation of a type, should be as close as possible to the original type definition string.

    Takes some logic from `typing._type_repr`.
    .z...r=   zUnion[ú]ú[ztyping.Ú ztyping_extensions.N)Ú
isinstanceÚtypesÚFunctionTypeÚBuiltinFunctionTyper   r   r.   ÚtypingÚ
ForwardRefr   Zis_type_alias_typer	   Ztyping_baseZWithArgsTypesr*   r&   Zorigin_is_unionÚtyping_extensionsÚ
get_originr/   ÚmapÚdisplay_as_typeÚget_argsZ
is_literalr   ÚAttributeErrorÚreplace)r>   Úargsr   r   r   rK   [   s0    

 rK   )r   Ú
__future__r   Z_annotationsrC   rF   r   rH   rA   r   ÚTYPE_CHECKINGr   Ú__annotations__r   r	   r   r   rK   r   r   r   r   Ú<module>   s   ÿ
	>