§
    .P„jË5  ã                  óÆ  — d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	Z
ddlmZ   ej        d¦  «        e
j        ¦  «        Z  ej        d¦  «        ej        ¦  «        Z  ej        d¦  «        ej        ¦  «        Z ee¦  «        Ze G d„ d	¦  «        ¦   «         Z	 d"d#d„Z ej        d¦  «        d$d„¦   «         Zd%d„Zd&d„Zd'd„Zd'd„Zd(d„Zd(d„Zd(d „Zd(d!„Z dS ))z_Utility for retrieveing the docstring of a dataclass's attributes.

@author: Fabrice Normandin
é    )ÚannotationsN)Ú	dataclass)Ú	getLogger)Ú	Docstringi   c                  óf   — e Zd ZU dZdZded<   dZded<   dZded<   dZded<   	 e	dd	„¦   «         Z
d
S )ÚAttributeDocStringz;Simple dataclass for holding the comments of a given field.Ú ÚstrÚcomment_aboveÚcomment_inlineÚdocstring_belowÚdesc_from_cls_docstringÚreturnc                ó:   — | j         p| j        p| j        p| j        S )z`Returns the value that will be used for the "--help" string, using the contents of
        self.)r   r   r   r   )Úselfs    ú]/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/simple_parsing/docstring.pyÚhelp_stringzAttributeDocString.help_string"   s2   € ð
 Ô ð ,ØÔ!ð,àÔ"ð,ð Ô+ð		
ó    N)r   r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r   Úpropertyr   © r   r   r   r      s‚   € € € € € € àEÐEà€MÐÐÐÑØ€NÐÐÐÑØ€OÐÐÐÑà#%ÐÐ%Ð%Ð%Ñ%ØAàð
ð 
ð 
ñ „Xð
ð 
ð 
r   r   Tr   ÚtypeÚ
field_namer
   Úaccumulate_from_basesÚboolr   c                ó*  — d}t          j        | ¦  «        }|d         | u sJ ‚|d         t          u sJ ‚|dd…         }|D ]l}t          ||¦  «        }|sŒ|s	|}|s|c S Œ |j        p|j        |_        |j        p|j        |_        |j        p|j        |_        |j        p|j        |_        Œm|sdt           	                    t          d|› d| › dd                     d„ |d	d…         D ¦   «         ¦  «        › d
�¦  «        ¦  «         t          ¦   «         S |S )a+  Returns the docstrings of a dataclass field.

    NOTE: a docstring can either be:
    - An inline comment, starting with <#>
    - A Comment on the preceding line, starting with <#>
    - A docstring on the following line, starting with either <"""> or <'''>
    - The description of a field in the classes's docstring.

    Arguments:
        some_dataclass: a dataclass
        field_name: the name of the field.
        accumulate_from_bases: Whether to accumulate the docstring components by looking through the
            base classes. When set to `False`, whenever one of the classes has a definition for the
            field, it is directly returned. Otherwise, we accumulate the parts of the dodc
    Returns:
        AttributeDocString -- an object holding the string descriptions of the field.
    Nr   éÿÿÿÿz(Couldn't find the definition for field 'z' within the dataclass z or any of its base classes ú,c              3  ó$   K  — | ]}|j         V — Œd S )N)r   )Ú.0Úts     r   ú	<genexpr>z*get_attribute_docstring.<locals>.<genexpr>d   s%   è è € ÐB_ÐB_ÐRSÀ1Ä:ÐB_ÐB_ÐB_ÐB_ÐB_ÐB_r   é   ú.)ÚinspectÚgetmroÚobjectÚ_get_attribute_docstringr   r   r   r   ÚloggerÚdebugÚRuntimeWarningÚjoinr   )r   r   r   Úcreated_docstringÚmroÚ
base_classÚattribute_docstrings          r   Úget_attribute_docstringr5   .   s«  € ð( 48Ðå
Œ.˜Ñ
#Ô
#€CØˆqŒ6�YÐÐÐÐØˆrŒ7•fÐÐÐÐØ
ˆcˆrˆcŒ(€CØð ð ˆ
Ý6°zÀ:ÑNÔNÐØ"ð 	ØØ ð 	Ø 3ÐØ(ð )à(Ð(Ð(Ð(ð)ð "Ô/ÐTÐ3FÔ3Tð Ô+ð "Ô0ÐVÐ4GÔ4Vð Ô,ð "Ô1ÐXÐ5HÔ5Xð Ô-ð "Ô9ð ?Ø&Ô>ð Ô5Ð5ð ð $Ý�ŠÝðc¸:ð cð cØðcð cØ:=¿(º(ÐB_ÐB_ÐWZÐ[\Ð[]Ð[]ÔW^ÐB_ÑB_ÔB_Ñ:_Ô:_ðcð cð cñô ñ	
ô 	
ð 	
õ "Ñ#Ô#Ð#ØÐr   úAttributeDocString | Nonec                óD  — 	 t          | ¦  «        }nO# t          t          f$ r;}t                               t          d| › d|› d|› �¦  «        ¦  «         Y d}~dS d}~ww xY wd}t          | ¦  «        }|r-t          |¦  «        }|j        D ]}|j	        |k    r	|j
        pd}Œ| j        r%| j        |v r|                     | j        dd¦  «        }|                     ¦   «         }d}	|	t          |¦  «        k     r.t          ||	         ¦  «        rn|	dz  }	|	t          |¦  «        k     °.d„ t!          |¦  «        D ¦   «         }
|
D ]`\  }}t#          ||¦  «        rKt%          ||dz
  ¦  «        }t'          ||¦  «        }t)          ||dz   ¦  «        }t+          ||||¬	¦  «        c S ŒadS )
znGets the AttributeDocString of the given field in the given dataclass.

    Doesn't inspect base classes.
    z+Couldn't retrieve the source code of class z. (in order to retrieve the docstring of field z): Nr	   ú
r'   c                ó:   — g | ]\  }}t          |¦  «        ¯||f‘ŒS r   )Ú_contains_field_definition)r$   ÚindexÚlines      r   ú
<listcomp>z,_get_attribute_docstring.<locals>.<listcomp>–   s?   € ð ð ð Ù%˜% ÕB\Ð]aÑBbÔBbðØ	�ˆðð ð r   )r   )Úinspect_getsourceÚ	TypeErrorÚOSErrorr-   r.   ÚUserWarningÚinspect_getdocÚdp_parseÚparamsÚarg_nameÚdescriptionr   ÚreplaceÚ
splitlinesÚlenr:   Ú	enumerateÚ_line_contains_definition_forÚ_get_comment_ending_at_lineÚ_get_inline_comment_at_lineÚ_get_docstring_starting_at_liner   )r   r   ÚsourceÚer   Úcls_docstringÚ	docstringÚparamÚ
code_linesÚstart_line_indexÚlines_with_field_defsÚir<   r   r   r   s                   r   r,   r,   k   sJ  € ð	Ý" 9Ñ-Ô-ˆˆøÝ•wÐð ð ð Ý�ŠÝðS¸ið Sð SØ@JðSð SØOPðSð Sñô ñ	
ô 	
ð 	
ð ˆtˆtˆtˆtˆtøøøøðøøøð !ÐÝ" 9Ñ-Ô-€MØð BÝ'¨Ñ6Ô6ˆ	ØÔ%ð 	Bð 	BˆEØŒ~ Ò+Ð+Ø*/Ô*;Ð*A¸rÐ'øð
 Ôð <˜YÔ.°&Ð8Ð8Ø—’ 	Ô 1°4¸Ñ;Ô;ˆð #×-Ò-Ñ/Ô/€JàÐð �S ™_œ_Ò
,Ð
,Ý% jÐ1AÔ&BÑCÔCð 	ØØ˜AÑÐð �S ™_œ_Ò
,Ð
,ð
ð Ý)2°:Ñ)>Ô)>ðñ ô Ðð )ð ð ‰ˆˆ4Ý(¨¨zÑ:Ô:ð 
	å7¸
ÀAÈÁEÑJÔJˆMÝ8¸ÀQÑGÔGˆNÝ=¸jÈ!ÈaÉ%ÑPÔPˆOÝ%ØØØØ(?ð	ñ ô ð ð ð ð
	ð ˆ4s   ‚ ’A£0AÁAr<   c                ó  — |                       d¦  «        \  } }}d| vrdS d| v r|                       d¦  «        \  }}}n| }|                      d¦  «        \  }}}|                     ¦   «         }d|v rdS |sdS |                     ¦   «         S )aj  Returns whether or not a line contains a an dataclass field definition.

    Arguments:
        line_str {str} -- the line content

    Returns:
        bool -- True if there is an attribute definition in the line.

    >>> _contains_field_definition("a: int = 0")
    True
    >>> _contains_field_definition("a: int")
    True
    >>> _contains_field_definition("a: int # comment")
    True
    >>> _contains_field_definition("a: int = 0 # comment")
    True
    >>> _contains_field_definition("class FooBaz(Foo, Baz):")
    False
    >>> _contains_field_definition("a = 4")
    False
    >>> _contains_field_definition("fooooooooobar.append(123)")
    False
    >>> _contains_field_definition("{a: int}")
    False
    >>> _contains_field_definition("        foobaz: int = 123  #: The foobaz property")
    True
    >>> _contains_field_definition("a #:= 3")
    False
    ú#ú:Fú=)Ú	partitionÚstripÚisidentifier)r<   Ú_Úattribute_and_typer   r   s        r   r:   r:   ¨   s«   € ð> —’ Ñ$Ô$�J€Dˆ!ˆQà
�$€€Øˆuà
ˆd€{€{Ø#'§>¢>°#Ñ#6Ô#6Ñ Ð˜A˜q˜qà!Ðà,×6Ò6°sÑ;Ô;Ñ€J��4Ø×!Ò!Ñ#Ô#€JØ
ˆd€{€{àˆuØð àˆuØ×"Ò"Ñ$Ô$Ð$r   c                óÚ   — |                       ¦   «         } t          | ¦  «        sdS |                      d¦  «        \  }}}|                      ¦   «         }|                     ¦   «         o||k    S )NFrZ   )r]   r:   r\   r^   )r<   r   Ú	attributer_   Útype_and_value_assignments        r   rK   rK   Ü   sh   € Ø�:Š:‰<Œ<€DÝ% dÑ+Ô+ð ØˆuØ.2¯nªn¸SÑ.AÔ.AÑ+€IˆqÐ+Ø—’Ñ!Ô!€IØ×!Ò!Ñ#Ô#Ð?¨	°ZÒ(?Ð?r   Úline_strc                ó2   — |                       ¦   «         dk    S )Nr	   )r]   ©rd   s    r   Ú	_is_emptyrg   å   s   € Ø�>Š>ÑÔ˜rÒ!Ð!r   c                óP   — |                       ¦   «                              d¦  «        S )NrY   )r]   Ú
startswithrf   s    r   Ú_is_commentrj   é   s    € Ø�>Š>ÑÔ×&Ò& sÑ+Ô+Ð+r   rT   ú	list[str]Úintc                ó¦   — | |         }t          |¦  «        rJ ‚d|vrdS |                     dd¬¦  «        }|d                              ¦   «         }|S )zØGets the comment at line `line` in `code_lines`.

    Arguments:
        line {int} -- the index of the line in code_lines

    Returns:
        str -- the comment at the given line. empty string if not present.
    rY   r	   r'   ©Úmaxsplit)r:   Úsplitr]   ©rT   r<   rd   ÚpartsÚcomments        r   Ú_get_comment_at_linert   í   s_   € ð ˜$Ô€HÝ)¨(Ñ3Ô3Ð3Ð3Ð3Ø
�(ÐÐØˆrØ�NŠN˜3¨ˆNÑ+Ô+€EØ�AŒh�nŠnÑÔ€GØ€Nr   c                ó  — d|cxk    rt          | ¦  «        k     sn J ‚t          | |         ¦  «        sJ ‚| |         }|                     dd¬¦  «        }t          |¦  «        dk    rdS |d                              ¦   «         }|S )zÏGets the inline comment at line `line`.

    Arguments:
        line {int} -- the index of the line in code_lines

    Returns:
        str -- the inline comment at the given line, else an empty string.
    r   rY   r'   rn   é   r	   )rI   r:   rp   r]   rq   s        r   rM   rM   ÿ   s“   € ð �Ð&Ð&Ò&Ð&•s˜:‘”Ò&Ð&Ð&Ð&Ð&Ð&Ý% j°Ô&6Ñ7Ô7Ð7Ð7Ð7Ø˜$Ô€HØ�NŠN˜3¨ˆNÑ+Ô+€EÝ
ˆ5�z„z�Q‚€ØˆrØ�AŒh�nŠnÑÔ€GØ€Nr   c                óš  — |}|}|dk    r,| |         }t          |¦  «        rnd|v sd|v rn|dz  }|dk    °,|dz  }g }t          ||dz   ¦  «        D ]T}t          | |         ¦  «        rŒt          | |         ¦  «        rJ ‚t          | |¦  «        }|                     |¦  «         ŒUd                     |¦  «                             ¦   «         S )Nr   ú"""ú'''r'   r8   )r:   Úrangerg   rt   Úappendr0   r]   )rT   r<   Ú
start_lineÚend_linerd   ÚlinesrW   rs   s           r   rL   rL     sþ   € Ø€JØ€Hð �qŠ.ˆ.Ø˜jÔ)ˆÝ% hÑ/Ô/ð 	ØØ�HÐÐ ¨Ð 1Ð 1ØØ�a‰ˆ
ð �qŠ.ˆ.ð �!�O€Jà€EÝ�:˜x¨!™|Ñ,Ô,ð ð ˆå�Z ”]Ñ#Ô#ð 	ØÝ-¨j¸¬mÑ<Ô<Ð<Ð<Ð<Ý& z°1Ñ5Ô5ˆØ�Š�WÑÔÐÐØ�9Š9�UÑÔ×!Ò!Ñ#Ô#Ð#r   c                ó4  — |}d }d}d}|t          | ¦  «        k    rdS g }|t          | ¦  «        k     �rÑ| |         }|�€=t          |¦  «        r|dz  }Œ4t          |¦  «        st          |¦  «        rdS ||v r:||v r6|                     |¦  «        }|                     |¦  «        }	||	k     r|}n0|}n-||v r|}n&||v r|}nt
                               d|› �¦  «         dS |                     |d¬¦  «        }
t          |
¦  «        dk    r0|
d                              ¦   «         }| 	                    |¦  «         nÌt          |
¦  «        dk    r/|
d                              ¦   «         }| 	                    |¦  «         np||v rE|                     |d¬¦  «        d	         }| 	                    |                     ¦   «         ¦  «         n@| 	                    |                     ¦   «         ¦  «         |dz  }|t          | ¦  «        k     �°Ñd
 
                    |¦  «        S )Nry   rx   r	   r'   z.Warning: Unable to parse attribute docstring: rv   rn   é   r   r8   )rI   rg   r:   rj   r;   r-   r.   rp   r]   r{   r0   )rT   r<   rW   ÚtokenÚtriple_singleÚtriple_doubleÚdocstring_contentsrd   Útriple_single_indexÚtriple_double_indexrr   Úbetween_tokensÚafter_tokenÚbefores                 r   rN   rN   +  sT  € Ø€AØ€EØ€MØ€Mð
 �s�:‰ŒÒÐØˆrà$&Ðà
�c�*‰oŒoÒ
Ñ
Ø˜a”=ˆð ‰=Ý˜Ñ"Ô"ð #Ø�Q‘�Øå+¨HÑ5Ô5ð ½ÀXÑ9NÔ9Nð ð �rà (Ð*Ð*¨}ÀÐ/HÐ/Hð '/§n¢n°]Ñ&CÔ&CÐ#Ø&.§n¢n°]Ñ&CÔ&CÐ#Ø&Ð)<Ò<Ð<Ø)�E�Eà)�E�EØ (Ð*Ð*Ø%��Ø (Ð*Ð*Ø%��õ —’ÐXÈhÐXÐXÑYÔYÐYØ�rð —N’N 5°1�NÑ5Ô5ˆEÝ�5‰zŒz˜QŠˆð "' q¤§¢Ñ!1Ô!1�à"×)Ò)¨.Ñ9Ô9Ð9Øå�U‘”˜q’�Ø# AœhŸnšnÑ.Ô.�à"×)Ò)¨+Ñ6Ô6Ð6øð ˜Ð Ð à!Ÿš¨¸˜Ñ:Ô:¸1Ô=�Ø"×)Ò)¨&¯,ª,©.¬.Ñ9Ô9Ð9Øð #×)Ò)¨(¯.ª.Ñ*:Ô*:Ñ;Ô;Ð;Ø	ˆQ‰ˆðO �c�*‰oŒoÒ
Ñ
ðR �9Š9Ð'Ñ(Ô(Ð(r   )T)r   r   r   r
   r   r   r   r   )r   r   r   r
   r   r6   )r<   r
   r   r   )r<   r
   r   r
   r   r   )rd   r
   r   r   )rT   rk   r<   rl   r   r
   )!r   Ú
__future__r   Ú	functoolsr)   Údataclassesr   Úloggingr   Údocstring_parserÚdpÚdocstring_parser.commonr   Ú	lru_cacheÚparserC   Ú	getsourcer>   ÚgetdocrB   r   r-   r   r5   r,   r:   rK   rg   rj   rt   rM   rL   rN   r   r   r   ú<module>r•      s#  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø €€€ð "Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -à$Ðˆ9Ô˜tÑ$Ô$ R¤XÑ.Ô.€Ø-Ð'�IÔ'¨Ñ-Ô-¨gÔ.?Ñ@Ô@Ð Ø*Ð$�Ô$ TÑ*Ô*¨7¬>Ñ:Ô:€Ø	ˆ�8Ñ	Ô	€ð ð
ð 
ð 
ð 
ð 
ñ 
ô 
ñ „ð
ð. EIð:ð :ð :ð :ð :ðz €Ô�TÑÔð9ð 9ð 9ñ Ôð9ðx1%ð 1%ð 1%ð 1%ðh@ð @ð @ð @ð"ð "ð "ð "ð,ð ,ð ,ð ,ðð ð ð ð$ð ð ð ð&$ð $ð $ð $ð2W)ð W)ð W)ð W)ð W)ð W)r   