
    h                        S SK Jr  S SKJr  S SKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SS	KJ
r
  SS
KJrJr  SSKJrJrJr  SSKJr  SSKJr  SSKJr  SSKJrJr  SSKJr  SqS rS r " S S\\5      r " S S5      r  " S S5      r!\!" 5       r" " S S5      r#S r$S r%S r&S r'S r(S  r)S! r*S" r+S# r,S$ r- " S% S&\R\                  5      r/S' r0g)(    )OrderedDict)dedentN   )	ExprNodes)Nodes)
PyrexTypes)Builtin)Naming)errorwarning)UtilityCodeTempitaUtilityCodePyxCodeWriter)VisitorTransform)EncodedString)TreeFragment)NormalizeTreeSkipDeclarations)copy_inherited_directivesc                 <   [         (       dS  [        R                  " SS5      n[        UR                  5      n[
        R                  " SSSUR                  5       S.S9q [        R                  " U S[        R                  " [        R                  / 5      [         / S	9$ )
NDataclasses_fallbackzDataclasses.pySpecificModuleLoaderDataclasses.cdataclasses)cnamepy_code)context__Pyx_Load_dataclasses_Module)utility_codeargs)_dataclass_loader_utilitycoder   load_cachedr   implr   loadas_c_string_literalr   PythonCapiCallNoder   	CFuncTypepy_object_type)pospython_utility_codes     S/var/www/fran/franai/venv/lib/python3.13/site-packages/Cython/Compiler/Dataclass.py make_dataclasses_module_callnoder,      s    (()556LN^_+,?,D,DE(:(?(?"O+8K8_8_8ab)d% '',Z66;2	     c           	      @   [         R                  " SS5      n[        R                  " [        R                  [        R
                  " S[        R                  S 5      [        R
                  " S[        R                  S 5      /5      n[        R                  " U SUUX/S9$ )NDataclassesCallHelperr   callablekwds__Pyx_DataclassesCallHelper)function_name	func_typer   r    )r   r"   r   r'   r(   CFuncTypeArgr   r&   )r)   r0   r1   r   r4   s        r+   make_dataclass_call_helperr6   %   s    **+BOTL$$!!##J
0I0I4P##FJ,E,EtL$
I ''3! r-   c                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
RemoveAssignmentsToNames6   a  
Cython (and Python) normally treats

class A:
     x = 1

as generating a class attribute. However for dataclasses the `= 1` should be interpreted as
a default value to initialize an instance attribute with.
This transform therefore removes the `x=1` assignment so that the class attribute isn't
generated, while recording what it has removed so that it can be used in the initialization.
c                 <   > [         TU ]  5         Xl        0 U l        g N)super__init__namesremoved_assignments)selfr>   	__class__s     r+   r=   !RemoveAssignmentsToNames.__init__B   s    
#% r-   c                 (    U R                  U5        U$ r;   visitchildrenr@   nodes     r+   visit_CClassNode)RemoveAssignmentsToNames.visit_CClassNodeG       4 r-   c                     U$ r;    rF   s     r+   visit_PyClassNode*RemoveAssignmentsToNames.visit_PyClassNodeK       r-   c                     U$ r;   rL   rF   s     r+   visit_FuncDefNode*RemoveAssignmentsToNames.visit_FuncDefNodeN   rO   r-   c                    UR                   R                  (       a  UR                   R                  U R                  ;   a  UR                   R                  U R                  ;   a.  [        UR                  SUR                   R                  -  S5        UR                  U R                  UR                   R                  '   / $ U$ )Nz=Multiple assignments for '%s' in dataclass; using most recentr   )lhsis_namenamer>   r?   r   r)   rhsrF   s     r+   visit_SingleAssignmentNode3RemoveAssignmentsToNames.visit_SingleAssignmentNodeQ   s    88 ;xx}} 8 88 $7:>((--#HIJL6:hhD$$TXX]]3Ir-   c                 (    U R                  U5        U$ r;   rD   rF   s     r+   
visit_Node#RemoveAssignmentsToNames.visit_Node]   rJ   r-   )r>   r?   )__name__
__module____qualname____firstlineno____doc__r=   rH   rM   rQ   rX   r[   __static_attributes____classcell__rA   s   @r+   r8   r8   6   s+    
&
 r-   r8   c                   r    \ rS rSrSrSrSS jrS rS rS r	S	 r
S
 rS rS rS rS rS rSS jrS rSrg)TemplateCodeb   z
Adds the ability to keep track of placeholder argument names to PyxCodeWriter.

Also adds extra_stats which are nodes bundled at the end when this
is converted to a tree.
r   Nc                 h    Uc
  [        5       OUU l        Uc  0 OUU l        Uc  / U l        g UU l        g r;   )r   writerplaceholdersextra_stats)r@   ri   rj   rk   s       r+   r=   TemplateCode.__init__k   s4    )/moV"."6BL!,!42+r-   c                 :    U R                   R                  U5        g r;   )ri   putln)r@   	code_lines     r+   add_code_lineTemplateCode.add_code_linep   s    )$r-   c                 :    U R                   R                  U5        g r;   )ri   	put_chunk)r@   
code_chunks     r+   add_code_chunkTemplateCode.add_code_chunks   s    j)r-   c                 8    U R                   R                  5         g r;   )ri   resetr@   s    r+   rx   TemplateCode.resetv   s     	r-   c                 6    U R                   R                  5       $ r;   )ri   emptyry   s    r+   r|   TemplateCode.empty{   s    {{  ""r-   c                 8    U R                   R                  5         g r;   )ri   indentry   s    r+   r   TemplateCode.indent~       r-   c                 8    U R                   R                  5         g r;   )ri   r   ry   s    r+   r   TemplateCode.dedent   r   r-   c                 8    U R                   R                  U5      $ r;   )ri   indenter)r@   block_opener_lines     r+   r   TemplateCode.indenter   s    {{##$566r-   c                 D    U R                  U5      nX R                  U'   U$ r;   )_new_placeholder_namerj   )r@   field_namesvaluerV   s       r+   new_placeholderTemplateCode.new_placeholder   s%    ))+6"'$r-   c                 b    U R                   c   S5       eU R                   R                  U5        g )Nz5Can only use add_extra_statements on top-level writer)rk   extend)r@   
statementss     r+   add_extra_statements!TemplateCode.add_extra_statements   s-    #QQQ5
+r-   c                      SU R                   S 3nX R                  ;  a  X!;  a   U$ U =R                   S-  sl         M>  )NDATACLASS_PLACEHOLDER_dr   )_placeholder_countrj   )r@   r   rV   s      r+   r   "TemplateCode._new_placeholder_name   sN    +D,C,CA+FGD---/  ##q(# r-   c                     [        U R                  R                  5       U[        S 5      /S9R	                  U R
                  5      nU=R                  U R                  -  sl        U$ )Nlevelpipeline)r   ri   getvaluer   
substituterj   statsrk   )r@   r   stat_list_nodes      r+   generate_treeTemplateCode.generate_tree   s^    %KK  "#D)*
 *T&&
'	 	 	 0 00r-   c                 t    U R                   R                  5       n[        UU R                  U R                  S9$ )N)ri   rj   rk   )ri   insertion_pointrf   rj   rk   )r@   
new_writers     r+   r   TemplateCode.insertion_point   s6    [[002
**((
 	
r-   )rk   rj   ri   )NNN)c_class)r]   r^   r_   r`   ra   r   r=   rp   ru   rx   r|   r   r   r   r   r   r   r   r   rb   rL   r-   r+   rf   rf   b   sQ     F
%*
#7
,
	
r-   rf   c                       \ rS rSrSrg)_MISSING_TYPE   rL   N)r]   r^   r_   r`   rb   rL   r-   r+   r   r      s    r-   r   c            	       J    \ rS rSrSr\r\rSrSr	\\SSSSSSS4	S jr
S rSrg)	Field   aZ  
Field is based on the dataclasses.field class from the standard library module.
It is used internally during the generation of Cython dataclasses to keep track
of the settings for individual attributes.

Attributes of this class are stored as nodes so they can be used in code construction
more readily (i.e. we store BoolNode rather than bool)
F)reprhashinitcomparemetadataNc                    U[         La  X l        U[         La  X0l        U=(       d    [        R                  " USS9U l        U=(       d    [        R                  " U5      U l        U=(       d    [        R                  " USS9U l        U=(       d    [        R                  " USS9U l	        U=(       d    [        R                  " U5      U l
        Xl        Xl        UR                  5        H  u  p[        UR                  SU-  5        M      U R                    H:  n[#        X5      nUR$                  (       a  M!  [        UR                  SU-  5        M<     g )NTr   zBcython.dataclasses.field() got an unexpected keyword argument '%s'z?cython.dataclasses.field parameter '%s' must be a literal value)MISSINGdefaultdefault_factoryr   BoolNoder   NoneNoder   r   r   r   
is_initvaris_classvaritemsr   r)   literal_keysgetattr
is_literal)r@   r)   r   r   r   r   r   r   r   r   r   additional_kwdskv
field_namefield_values                   r+   r=   Field.__init__   s   
 '!"L')#2 ?I..s$?	3I..s3	?I..s$?	E)"4"4S"E ;I$6$6s$;$&#))+DA!%%]`aab , ++J!$3K)))kooWZddf ,r-   c              #   n   #    U R                   S-    H  n[        X5      nU[        Ld  M  X4v   M      g 7f)Nr   r   )r   r   r   )r@   keyr   s      r+   iterate_record_node_arguments#Field.iterate_record_node_arguments   s6     %%(FFCD&EG#j  Gs   %5
5)	r   r   r   r   r   r   r   r   r   )r]   r^   r_   r`   ra   r   r   r   privater   r=   r   rb   rL   r-   r+   r   r      s@     GOGBL %,WD!uf6!r-   r   c                 4   U R                   R                  n[        U[        R                  " S5      S9nU Vs/ s H  o"R
                  PM     nn[        U5      nU" U 5        UR                  nU R                  n[        5       nU(       a  UR                  (       d  UR                   R                  (       d  [        U R                  SS5        UR                  (       a  UR                  R                  5       nOUR                  nU(       a  M  U GH  nUR
                  nUR!                  S5      n	UR!                  S5      n
X;   Gan  XX   n[#        U[$        R&                  5      (       Ga  UR(                  R+                  5       S:X  d0  [,        R.                  " UR(                  U R                   5      S:X  Gap  [#        U[$        R0                  5      =(       a    [#        UR2                  [$        R4                  5      =(       a[    UR2                  R6                  (       + =(       a9    UR8                  S L =(       d$    [#        UR8                  [$        R:                  5      n[#        U[$        R<                  5      =(       a    UR6                  (       + nU(       d   U(       d  [?        UR                  S5        GM  U(       a+  UR8                  (       a  UR8                  RA                  5       O0 nS	U;   a  S
U;   a  [?        UR                  S5        GM  [C        U R                  40 UD6nOURD                  [,        RF                  [,        RH                  [,        RJ                  4;   a:  [?        UR                  SRM                  URD                  R
                  U5      5        [C        U R                  US9nO[C        U R                  5      nXl'        Xl(        URR                  S:X  a  SUl*        XU'   GM     XpRV                  RD                  l        U$ s  snf )Nr)   )r   zCannot reliably handle Cython dataclasses with base types in external modules since it is not possible to tell what fields they have   zdataclasses.InitVarztyping.ClassVarzdataclasses.fieldzVCall to 'cython.dataclasses.field' must only consist of compile-time keyword argumentsr   r   z/cannot specify both default and default_factoryzMmutable default <class '{}'> for field {} is not allowed: use default_factory)r   r   T),scopevar_entriessortedoperator
attrgetterrV   r8   r?   	base_typer   is_externalimplementedr   r)   dataclass_fieldscopydeclared_with_pytyping_modifier
isinstancer   CallNodefunctionas_cython_attributer	   'exprnode_to_known_standard_library_nameGeneralCallNodepositional_args	TupleNoder    keyword_argsDictNodeSimpleCallNoder   as_python_dictr   type	list_type	dict_typeset_typeformatr   r   
visibilityr   entry)rG   r   r   	var_names	transformdefault_value_assignmentsr   fieldsrV   r   r   
assignmentvalid_general_callvalid_simple_callr   fields                   r+   process_class_get_fieldsr      s1   **((K(*=*=e*DEK)45I5 )3IdO ) = =I]F
  	(C(CDHH ]^_a%%//446F''	 ) zz::;PQ
 ;;<MN,28J:y'9'9::'';;=ATTCC"++TZZ9<OP '1Y=V=V&W 'y&z'A'A9CVCVW'y * : : ? ??'y (44<w
:KbKbdmdvdv@w # &0
I<T<T%U%m^h^m^mZm!*.?*.. +> ?K]blbybyz66EEG  @B,1Bl1R*..*[\dhh7,7??w'8'8':K:KWM]M]&^^ *.. +006z7K7KT0RT dhh
;$((OE%'y( EMtW X (.JJOO$M 6s   Pc                    [        SSSSSSSSS9nUb  US   (       a  [        U R                  S5        US   R                  5        Hf  u  pEXC;  a  [        U R                  SU-  5        [	        U[
        R                  5      (       d  [        U R                  S5        UR                  X4'   Mh     US	   n[        U 5      n[        U R                  5      n[
        R                  " U R                  U[        S
5      S9n	[
        R                  R                  U R                  UR                  5        VVs/ s HL  u  pE[
        R                  " U R                  [        U5      S9[
        R                  " U R                  US94PMN     snnS	U4SS4 VVs/ s HL  u  pE[
        R                  " U R                  [        U5      S9[
        R                  " U R                  US94PMN     snn-   5      n
[        U R                  X5      n[         R"                  " U R                  [
        R$                  " U R                  [        S5      S9US9n['        XU5      n[         R(                  " U R                  U/U-   S9n[+        5       n[-        XS   XU5        [/        XS   XU5        [1        XS   X5        [3        XS   X5        [5        XS   X5        [7        XS   US   US   X5        U=R8                  UR;                  5       R8                  -  sl        [         R<                  " U R                  [?        U R@                  RB                  SS9US9nURE                  U R@                  5        URG                  X R@                  5        URI                  U5        URK                  5         U RL                  R8                  RO                  U5        g s  snnf s  snnf )NTF)r   r   eqorderunsafe_hashfrozenkw_only
match_argsr   z:cython.dataclasses.dataclass takes no positional argumentsr   zFcython.dataclasses.dataclass() got an unexpected keyword argument '%s'zFArguments passed to cython.dataclasses.dataclass must be True or Falser   _DataclassParamsobj	attributer   )slotsF)weakref_slotF__dataclass_params__rV   rT   rW   )r   r   r   r   r   r   r   r   )annotation_typing)
directivesbody)(dictr   r)   r   r   r   r   r   r   r,   AttributeNoder   r   
from_pairsIdentifierStringNoder6   r   SingleAssignmentNodeNameNode_set_up_dataclass_fieldsStatListNoderf   generate_init_codegenerate_match_argsgenerate_repr_codegenerate_eq_codegenerate_order_codegenerate_hash_coder   r   CompilerDirectivesNoder   r   r  analyse_declarationsenter_scopevisit
exit_scoper  append)rG   dataclass_argsanalyse_decs_transformkwargsr   r   r   r   dataclass_moduledataclass_params_funcdataclass_params_keywordsdataclass_paramsdataclass_params_assignmentdataclass_fields_statsr   codecomp_directivess                    r+   handle_cclass_dataclassr&  ,  sk   t$45$@F !!$((XY"1%++-DAdhh^abbda!3!344dhh^`FI . YG%d+F7A
 &33DHHBR>KL^>_a ) 2 2 = = lln	'$da ))$((-:JKdhha02$	'
 "7+')@B	
Bda ))$((-:JKdhha02B	
	
	! 2'D"'"<"<  >T0UV# 
 6dDTUtxx&A%BE[%[]E >DtF^T7C\2D'JtF^T:T$<6Wot<tM2F4L&BRTXa	KK4%%'---K
 22488,TZZ-B-BV[\O ((4&&tZZ8  1%%'IIOO?+W	'	
s   6AOAOc                    U(       a   UR                   R                  S5      (       a  gSU;   a  SOSnU/nU(       a  UR                  S5        U R                  5       nU R                  5       n U R	                  5         [        UR                  5      n[        R                  " UR                  U[        S5      S9n	U R                  X95      n
SnUR                  5        GHR  u  pUR                   R                  U5      nUR                  (       a$  S	UR                  R                  R                   3nOS
nS
nUR                   ["        Ld  UR$                  ["        LaT  UR&                  R                  (       a  SnUR$                  ["        La  U
nOU R                  X=R                   5      nSU 3nOTU(       aM  U(       dF  UR&                  R                  (       a+  [)        UR                  SU-  5        U R+                  5           gUR&                  R                  (       a  UR                  U U U 35        UR,                  (       a  GMn  UR$                  ["        L a\  UR&                  R                  (       a  U R/                  U SU SU 35        GM  U(       a  U R/                  U SU U 35        GM  GM  U R                  X=R$                  5      nUR&                  R                  (       a%  U R/                  U SU SU SU SU
 SU 35        GM8  U R/                  U SU SU S35        GMU     UR                   R                  S5      (       a=  SR1                  S UR                  5        5       5      nU R/                  U SU S35        U R3                  5       (       a  U R/                  S5        SR1                  U5      nUR/                  SU S35        g)a  
Notes on CPython generated "__init__":
* Implemented in `_init_fn`.
* The use of the `dataclasses._HAS_DEFAULT_FACTORY` sentinel value as
  the default argument for fields that need constructing with a factory
  function is copied from the CPython implementation. (`None` isn't
  suitable because it could also be a value for the user to pass.)
  There's no real reason why it needs importing from the dataclasses module
  though - it could equally be a value generated by Cython when the module loads.
* seen_default and the associated error message are copied directly from Python
* Call to user-defined __post_init__ function (if it exists) is copied from
  CPython.

Cython behaviour deviates a little here (to be decided if this is right...)
Because the class variable from the assignment does not exist Cython fields will
return None (or whatever their type default is) if not initialized while Python
dataclasses will fall back to looking up the class variable.
r=   Nr@   __dataclass_self__*_HAS_DEFAULT_FACTORYr   Fz:  Tz = zHnon-default argument '%s' follows default argument in dataclass __init__.z() if z is z else z()__post_init__, c              3   P   #    U  H  u  pUR                   (       d  M  Uv   M     g 7fr;   )r   ).0rV   r   s      r+   	<genexpr>%generate_init_code.<locals>.<genexpr>  s"      #8>KD&+&6&6 $(4>s   &	&z.__post_init__()passzdef __init__(z):)r   lookup_herer  r   r   r,   r)   r   r  r   r   r   lookup
annotationstringr   r   r   r   r   r   rx   r   rp   joinr|   )r$  r   rG   r   r   selfnamer    function_start_pointr  has_default_factorydefault_factory_placeholderseen_defaultrV   r   r   r7  r   ph_namepost_init_varss                      r+   r  r  x  sK   & 4::))*55 (.'7#VH:DC//1!DKKM 8A#11 67 #'"6"6v"SL||~

!!$'e..55;;<=JJ
=='5+@+@+Ozz#$$G35..v}}EwiJ'ejj.>.>%)) 69=> ?JJL::KK4&ZL9:""g-zz""hZqc$#@A""hZqzl#CD  **63H3HIGzz ""j$s7)6$tD_C``fgkflm
 ""hZqc'"#EFW &Z zz)) #86<<> #8 8hZ~6FaHIzz||6"99T?D&&tfB'?@r-   c                 n   U(       a   UR                   R                  S5      (       a  g/ nUR                  5        HQ  u  pgU=(       d)    [        US5      =(       a    UR                  R
                  nU(       a  M@  UR                  U5        MS     U R                  S[        [        U5      5      -  5        g)z
Generates a tuple containing what would be the positional args to __init__

Note that this is generated even if the user overrides init
__match_args__Nr   z__match_args__ = %s)
r   r5  r   hasattrr   r   r  rp   strtuple)	r$  r   rG   r   global_kw_onlypositional_arg_namesr   r   field_is_kw_onlys	            r+   r  r    s     //0@AA#\\^
) 
E9%=%--*=*= 	   ''
3 , 	,s59M3N/OOPr-   c           	         U(       a   UR                   R                  S5      (       a  gSnUR                  5        Ho  nUR                   R                  U5      nUR                  nUR                  (       a  UR
                  nUR                  (       d  MZ  UR                  (       a  Mm  Sn  O   U(       a  U R                  S5        U R                  S5         U(       a!  U R                  S5        U R                  5         UR                  5        VVs/ s H?  u  pXUR                  R                  (       d  M"  UR                  (       a  M5  U< SU< S	3PMA     n	nnS
R                  U	5      n
U R                  SU
 S35        U(       a;  U R!                  5         U R                  S5         U R#                  S5        SSS5        SSS5        gs  snnf ! , (       d  f       N= f! , (       d  f       g= f)a~  
The core of the CPython implementation is just:
['return self.__class__.__qualname__ + f"(' +
                 ', '.join([f"{f.name}={{self.{f.name}!r}}"
                            for f in fields]) +
                 ')"'],

The only notable difference here is self.__class__.__qualname__ -> type(self).__name__
which is because Cython currently supports Python 2.

However, it also has some guards for recursive repr invocations. In the standard
library implementation they're done with a wrapper decorator that captures a set
(with the set keyed by id and thread). Here we create a set as a thread local
variable and key only by id.
__repr__NFTz
            __pyx_recursive_repr_guard = __import__('threading').local()
            __pyx_recursive_repr_guard.running = set()
        zdef __repr__(self):z
                key = id(self)
                guard_set = self.__pyx_recursive_repr_guard.running
                if key in guard_set: return '...'
                guard_set.add(key)
                try:
            z={self.z!r}r.  zq
            name = getattr(type(self), "__qualname__", None) or type(self).__name__
            return f'{name}(z)'
        zfinally:zguard_set.remove(key))r   r6  keysr   is_memoryviewslicedtypeis_pyobjectis_gc_simpleru   r   r   r   r   r   r   r9  r   rp   )r$  r   rG   r   needs_recursive_guardrV   r   type_r   strsformat_strings              r+   r  r    s     4::$$Z00 "

!!$'

##KKE  !!!$(!    	
 
,	-  !  KKM $*<<>>#1KD::## 0,1,<,< 0D$/#1 	 > 		$ !,o .	 	 !KKMz*""#:; +- 
.	-> +*- 
.	-sC   <G$!G8GGAG$*G<G$G$
G!	G$$
G2c                    UR                   R                  U5      (       a  g UR                  5        VVs/ s H7  u  pVUR                  R                  (       d  M"  UR
                  (       a  M5  UPM9     nnnU R                  SU S35         U R                  SUR                   SUR                   S35        / nUR                  SS5      n	U H<  nUS:w  a  U R                  S	U S
U	 SU S35        U R                  S	U SU S35        M>     U R                  SSU;   a  SOS 35        S S S 5        g s  snnf ! , (       d  f       g = f)Nzdef z(self, other):z_
            if other.__class__ is not self.__class__: return NotImplemented

            cdef z& other_cast
            other_cast = <z>other
        =r+  ==zif self. z other_cast.z: return Truez != other_cast.z: return Falsezreturn TrueFalse)r   r5  r   r   r   r   r   ru   
class_namereplacerp   )
r$  opfuncnamerG   r   rV   r   r>   checksop_without_equalss
             r+   generate_cmp_coder`  1  s=   zzh''%+\\^f^kd8K8KTTYTdTdT^Ef	hZ~6	7 ! //" #??+ ,		 	" JJsB/DTz""XdV15F4G|TXSYYf#gh$tfNST	 
 	WsbyVg$FGH5 
8	7 g	7	7s   !D3D3-D3BD99
Ec                 0    U(       d  g [        U SSX#5        g )NrV  __eq__r`  )r$  r   rG   r   s       r+   r  r  T  s    dD(D9r-   c                 D    U(       d  g S H  u  pE[        XXRU5        M     g )N))<__lt__)z<=__le__)>__gt__)z>=__ge__rc  )r$  r   rG   r   r\  rV   s         r+   r  r  Z  s$    ' 	$D7	'r-   c                    UR                   R                  S5      nU(       a+  U(       a#  [        UR                  SUR                  -  5        gU(       d  U(       d  gU(       du  U R                  [        R                  " UR                  [        R                  " UR                  [        S5      S9[        R                  " UR                  5      S9/5        gUR                  5        VVs/ s Hl  u  pxUR                  (       a  M  UR                  R                  c  UR                   R                  (       d  ML  OUR                  R                  (       d  Mj  UPMn     n	nnSR#                  S U	 5       5      n
U
(       a  U
S-  n
U R%                  S	5         U R'                  S
U
 S35        SSS5        gs  snnf ! , (       d  f       g= f)a  
Copied from CPython implementation - the intention is to follow this as far as
is possible:
#    +------------------- unsafe_hash= parameter
#    |       +----------- eq= parameter
#    |       |       +--- frozen= parameter
#    |       |       |
#    v       v       v    |        |        |
#                         |   no   |  yes   |  <--- class has explicitly defined __hash__
# +=======+=======+=======+========+========+
# | False | False | False |        |        | No __eq__, use the base class __hash__
# +-------+-------+-------+--------+--------+
# | False | False | True  |        |        | No __eq__, use the base class __hash__
# +-------+-------+-------+--------+--------+
# | False | True  | False | None   |        | <-- the default, not hashable
# +-------+-------+-------+--------+--------+
# | False | True  | True  | add    |        | Frozen, so hashable, allows override
# +-------+-------+-------+--------+--------+
# | True  | False | False | add    | raise  | Has no __eq__, but hashable
# +-------+-------+-------+--------+--------+
# | True  | False | True  | add    | raise  | Has no __eq__, but hashable
# +-------+-------+-------+--------+--------+
# | True  | True  | False | add    | raise  | Not frozen, but hashable
# +-------+-------+-------+--------+--------+
# | True  | True  | True  | add    | raise  | Frozen, so hashable
# +=======+=======+=======+========+========+
# For boxes that are blank, __hash__ is untouched and therefore
# inherited from the base class.  If the base is object, then
# id-based hashing is used.

The Python implementation creates a tuple of all the fields, then hashes them.
This implementation creates a tuple of all the hashes of all the fields and hashes that.
The reason for this slight difference is to avoid to-Python conversions for anything
that Cython knows how to hash directly (It doesn't look like this currently applies to
anything though...).
__hash__z/Cannot overwrite attribute __hash__ in class %sNr  r  r.  c              3   ,   #    U  H
  nS U-  v   M     g7f)zself.%sNrL   )r0  rV   s     r+   r1  %generate_hash_code.<locals>.<genexpr>  s      DedT!1es   ,zdef __hash__(self):zreturn hash((z)))r   r5  r   r)   rZ  r   r   r  r   r  r   r   r   r   r   r   r   r9  r   rp   )r$  r   r   r   rG   r   
hash_entryrV   r   r>   hash_tuple_itemss              r+   r  r  e  sm   L ''
3J $((MPTP_P__`%%**HH!**488-
:ST!**4884'   !' . 	#(::#3#3#;EMM 	AQAQ 	 
  yy De DDC 
,	-]+;*<B?@ 
.	- 
.	-s$   ,F60F6;F6F6F<<
G
c                     UR                   (       a  UR                   R                  $ [        UR                  R	                  SSS95      n[
        R                  " XS9$ )z
sets the .type attribute for a field

Returns the annotation if possible (since this is what the dataclasses
module does). If not (for example, attributes defined with cdef) then
it creates a string fallback.
r+  r   )for_displayr   )r7  r8  r   r   declaration_coder   UnicodeNode)r)   r   ss      r+   get_field_typerw    sR     
 &&&" %**55ba5HI$$S22r-   c                   J   ^  \ rS rSrSrS/rU 4S jrS rS rS r	S r
S	rU =r$ )
FieldRecordNodei  aV  
__dataclass_fields__ contains a bunch of field objects recording how each field
of the dataclass was initialized (mainly corresponding to the arguments passed to
the "field" function). This node is used for the attributes of these field objects.

If possible, coerces `arg` to a Python object.
Otherwise, generates a sensible backup string.
argc                     > [         TU ]  XS9  g )Nrz  )r<   r=   )r@   r)   rz  rA   s      r+   r=   FieldRecordNode.__init__  s    &r-   c                 r    U R                   R                  U5        U R                   R                  U l        U $ r;   )rz  analyse_typesr   r@   envs     r+   r  FieldRecordNode.analyse_types  s(    s#HHMM	r-   c                     U R                   R                  R                  U5      (       a  U R                   R                  U5      $ U R	                  5       $ r;   )rz  r   can_coerce_to_pyobjectcoerce_to_pyobject_make_stringr  s     r+   r  "FieldRecordNode.coerce_to_pyobject  sA    88==//4488..s33
 $$&&r-   c                     SSK Jn  U" SS9nUR                  U R                  5      n[        R
                  " U R                  [        U5      S9$ )Nr   )AnnotationWriterzDataclass field)descriptionr   )AutoDocTransformsr  writerz  r   ru  r)   r   )r@   r  ri   r8  s       r+   r  FieldRecordNode._make_string  s>    7!.?@dhh'$$TXX]65JKKr-   c                 8    U R                   R                  U5      $ r;   )rz  generate_evaluation_code)r@   r$  s     r+   r  (FieldRecordNode.generate_evaluation_code  s    xx0066r-   )r   )r]   r^   r_   r`   ra   subexprsr=   r  r  r  r  rb   rc   rd   s   @r+   ry  ry    s0     wH'
'L7 7r-   ry  c                 B	   / nUR                  5        GHi  u  pEUR                  (       a  M  S GHI  n[        XV5      nU[        L d"  UR                  (       d  UR
                  (       a  M<  U R                  R                  5       nUR                  UR                  [        R                  U R                  5      U5      n	[        R                  " UR                  [        U	5      S9n
UR!                  U
R"                  UR$                  =(       d    [&        R(                  UR                  U
R"                  SS9U
l        [-        XVU
5        UR/                  [0        R2                  " UR                  XS95        GML     GMl     0 n[        R4                  " U R                  U[        S5      S9n[        R6                  " U R                  / S9n/ nUR                  5        GH)  u  pEUR                  (       a  M  S	U-  n[9        U R                  U R                  R:                  U   5      X'   S
U-  nUR<                  (       a-  [        R4                  " U R                  U[        S5      S9UU'   OjUR>                  (       a-  [        R4                  " U R                  U[        S5      S9UU'   O,[        R4                  " U R                  U[        S5      S9UU'   [        R6                  RA                  U R                  URC                  5        VVs/ s HB  u  nn[        RD                  " U R                  [        U5      S9[G        U R                  US94PMD     snn5      n[I        U R                  UU5      nURJ                  R/                  [        RL                  " U R                  [        RD                  " U R                  [        U5      S9US95        UR/                  [O        SU< SU< SU< SU SU< SU S35      5        GM,     [0        R2                  " U R                  [        R                  " U R                  [        S5      S9US9nSRQ                  U5      n[S        US[U        S 5      /S9nURW                  U5      nUU/-   URX                  -   $ s  snnf )Nr   r  T)r   r)   r   is_cdefr  r   r   )key_value_pairszPLACEHOLDER_%szPLACEHOLDER_FIELD_TYPE_%s_FIELD_INITVAR_FIELD_CLASSVAR_FIELDr   r|  )r   r   z%                __dataclass_fields__[z	].name = z&
                __dataclass_fields__[z	].type = z]._field_type = z
            __dataclass_fields__
r   r   )-r   r   r   r   r   rU   r   global_scopemangler
   dataclass_field_default_cnamerZ  r   r  r)   r   declare_varrV   r   r   unspecified_typer   setattrr  r   r  r  r   rw  entriesr   r   r	  r   r
  ry  r6   r  DictItemNoder   r9  r   r   r   r   )rG   r   r  variables_assignment_statsrV   r   attrnamefield_defaultr  module_field_name
field_noderj   
field_func	dc_fieldsdc_fields_namevalue_assignmentstype_placeholder_namefield_type_placeholder_namer   r   dc_field_keywordsdc_field_calldataclass_fields_assignments                         r+   r  r    s3    "$||~==8H#E4M'=+C+C}G\G\ ::224L , 3 3##F$H$H$//Z! #++M,=,=MRcDdeJ+77m&8&8&WJ<W<W!%%Z__d  8  J EZ0&--**=+<+<*`b) 9 &4 L((7G3@3IKJ""488R@I&(#||~== 04 7.<HHdjj((./
+
 'BD&H#8A8O8O.'(899L45 8A8O8O.'(9:9L45
 9B8O8O.'19L45
 &..99HH  ==?A?$!Q ,,TXX]1=MNtxxQ/1?A
 3HHj"3
 	!!((""22488=QUCVW#%	&
 	(.. &&*XYth ?&&*XY7L6M N&&*X-=>Y=Z [ 	U &d 	""488'00-:;Q-RT'	)   '+ii0O&P#&23R9B=J4=P<Q'S# 'F&P&PQ]&^#&*+,-334 5AAs   A	R)1collectionsr   textwrapr   r   r+  r   r   r   r	   r
   Errorsr   r   Coder   r   r   Visitorr   StringEncodingr   r   ParseTreeTransformsr   r   Optionsr   r!   r,   r6   r8   rf   r   r   r   r   r&  r  r  r  r`  r  r  r  rw  ExprNodery  r  rL   r-   r+   <module>r     s    $        " @ @ % ) & @ . $ ")/1A )XJ
 J
Z	 	
//! /!dCLI,XbAJQ&><B IF:8IAX3D#7i(( #7Lk5r-   