
    -Ph                        d dl mZ d dlmZ d dlZddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddlmZ dad Zd Z G d dee          Z G d d          Z  G d d          Z! e!            Z" G d d          Z#d Z$d Z%d Z&d Z'd Z(d  Z)d! Z*d" Z+d# Z,d$ Z- G d% d&ej.                  Z/d' Z0dS )(    )OrderedDict)dedentN   )	ExprNodes)Nodes)
PyrexTypes)Builtin)Naming)errorwarning)UtilityCodeTempitaUtilityCodePyxCodeWriter)VisitorTransform)EncodedString)TreeFragment)NormalizeTreeSkipDeclarations)copy_inherited_directivesc                 0   t           sUt          j        dd          }t          |j                  }t          j        ddd|                                d          a t          j	        | dt          j        t          j        g           t           g 	          S )
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     Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Compiler/Dataclass.py make_dataclasses_module_callnoder,      s    ( d)56LN^__+,?,DEE(:(?"O+8K8_8_8a8abb)d )d )d% ',Z6;;2	       c           	         t          j        dd          }t          j        t          j        t          j        dt          j        d           t          j        dt          j        d           g          }t          j        | d||||g          S )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TTL$!#J
0I4PP#FJ,EtLL$
 I '3!   r-   c                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )RemoveAssignmentsToNamesa  
    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                 d    t                                                       || _        i | _        d S N)super__init__namesremoved_assignments)selfr=   	__class__s     r+   r<   z!RemoveAssignmentsToNames.__init__B   s.    
#%   r-   c                 0    |                      |           |S r:   visitchildrenr?   nodes     r+   visit_CClassNodez)RemoveAssignmentsToNames.visit_CClassNodeG       4   r-   c                     |S r:    rD   s     r+   visit_PyClassNodez*RemoveAssignmentsToNames.visit_PyClassNodeK       r-   c                     |S r:   rI   rD   s     r+   visit_FuncDefNodez*RemoveAssignmentsToNames.visit_FuncDefNodeN   rK   r-   c                     |j         j        rd|j         j        | j        v rQ|j         j        | j        v r#t          |j        d|j         j        z  d           |j        | j        |j         j        <   g S |S )Nz=Multiple assignments for '%s' in dataclass; using most recentr   )lhsis_namenamer=   r>   r   r)   rhsrD   s     r+   visit_SingleAssignmentNodez3RemoveAssignmentsToNames.visit_SingleAssignmentNodeQ   s|    8 	 ; ;x} 888 $7:>(-#HIJL L L6:hD$TX]3Ir-   c                 0    |                      |           |S r:   rB   rD   s     r+   
visit_Nodez#RemoveAssignmentsToNames.visit_Node]   rG   r-   )__name__
__module____qualname____doc__r<   rF   rJ   rM   rS   rU   __classcell__r@   s   @r+   r8   r8   6   s        
 
& & & & &
              r-   r8   c                   h    e Zd ZdZdZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd ZddZd ZdS )TemplateCodez
    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                 `    |t                      n|| _        |i n|| _        |g n|| _        d S r:   )r   writerplaceholdersextra_stats)r?   r_   r`   ra   s       r+   r<   zTemplateCode.__init__k   s=    )/moooV"."6BBL!,!422+r-   c                 :    | j                             |           d S r:   )r_   putln)r?   	code_lines     r+   add_code_linezTemplateCode.add_code_linep   s    )$$$$$r-   c                 :    | j                             |           d S r:   )r_   	put_chunk)r?   
code_chunks     r+   add_code_chunkzTemplateCode.add_code_chunks   s    j)))))r-   c                 8    | j                                          d S r:   )r_   resetr?   s    r+   rk   zTemplateCode.resetv   s     	r-   c                 4    | j                                         S r:   )r_   emptyrl   s    r+   rn   zTemplateCode.empty{   s    {  """r-   c                 8    | j                                          d S r:   )r_   indentrl   s    r+   rp   zTemplateCode.indent~       r-   c                 8    | j                                          d S r:   )r_   r   rl   s    r+   r   zTemplateCode.dedent   rq   r-   c                 6    | j                             |          S r:   )r_   indenter)r?   block_opener_lines     r+   rt   zTemplateCode.indenter   s    {##$5666r-   c                 D    |                      |          }|| j        |<   |S r:   )_new_placeholder_namer`   )r?   field_namesvaluerQ   s       r+   new_placeholderzTemplateCode.new_placeholder   s'    ))+66"'$r-   c                 \    | j         
J d            | j                             |           d S )NFz5Can only use add_extra_statements on top-level writer)ra   extend)r?   
statementss     r+   add_extra_statementsz!TemplateCode.add_extra_statements   s7    #QQQQQ
+++++r-   c                 \    	 d| j         d}|| j        vr||vrn| xj         dz  c_         *|S )NTDATACLASS_PLACEHOLDER_dr   )_placeholder_countr`   )r?   rx   rQ   s      r+   rw   z"TemplateCode._new_placeholder_name   sX    	)GD,CGGGDD---K// ##q(##	) r-   c_classc                     t          | j                                        |t          d           g                              | j                  }|xj        | j        z  c_        |S )Nlevelpipeline)r   r_   getvaluer   
substituter`   statsra   )r?   r   stat_list_nodes      r+   generate_treezTemplateCode.generate_tree   sl    %K  ""#D))*
 
 
 *T&
'
'	 	 	 00r-   c                 l    | j                                         }t          || j        | j                  S )N)r_   r`   ra   )r_   insertion_pointr]   r`   ra   )r?   
new_writers     r+   r   zTemplateCode.insertion_point   s;    [0022
*(
 
 
 	
r-   )NNN)r   )rV   rW   rX   rY   r   r<   re   ri   rk   rn   rp   r   rt   rz   r~   rw   r   r   rI   r-   r+   r]   r]   b   s          F F F F
% % %* * *  
# # #    7 7 7  
, , ,
	 	 	   
 
 
 
 
r-   r]   c                       e Zd ZdS )_MISSING_TYPEN)rV   rW   rX   rI   r-   r+   r   r      s        Dr-   r   c            	       B    e Zd ZdZeZeZdZdZeedddddddf	dZ	d Z
dS )Fieldar  
    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                 R   |t           ur|| _        |t           ur|| _        |pt          j        |d          | _        |pt          j        |          | _        |pt          j        |d          | _        |pt          j        |d          | _	        |pt          j        |          | _
        |	| _        |
| _        |                                D ]\  }}t          |j        d|z             | j        D ]1}t#          | |          }|j        st          |j        d|z             2d S )NTry   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<   zField.__init__   sU   
 '!!"DL'))#2D ?I.s$???	3I.s33	?I.s$???	E)"4S"E"E"E ;I$6s$;$;$&#))++ 	c 	cDAq!%]`aabbbb+ 	f 	fJ!$
33K) fkoWZddf f f	f 	fr-   c              #   b   K   | j         dz   D ]!}t          | |          }|t          ur||fV  "d S )Nr   r   )r   r   r   )r?   keyry   s      r+   iterate_record_node_argumentsz#Field.iterate_record_node_arguments   sS      %(FF 	! 	!CD#&&EG##5j   	! 	!r-   )rV   rW   rX   rY   r   r   r   privater   r<   r   rI   r-   r+   r   r      ss          GOGBL %,WD!uf f f f6! ! ! ! !r-   r   c                 R   | j         j        }t          |t          j        d                    }d |D             }t          |          } ||            |j        }| j        }t                      }|rS|j	        s|j         j
        st          | j        dd           |j        r|j                                        }n	|j        }|S|D ]K}|j        }|                    d          }	|                    d          }
||v r||         }t#          |t$          j                  rB|j                                        dk    s$t-          j        |j        | j                   dk    rt#          |t$          j                  oSt#          |j        t$          j                  o4|j        j         o'|j        d u pt#          |j        t$          j                  }t#          |t$          j                  o|j         }|s|st?          |j        d	           H|r |j        r|j                                         ni }d
|v rd|v rt?          |j        d           tC          | j        fi |}n|j"        t,          j#        t,          j$        t,          j%        fv r3t?          |j        d&                    |j"        j        |                     tC          | j        |          }ntC          | j                  }|	|_'        |
|_(        |j)        dk    rd|_*        |||<   M|| j+        j"        _        |S )Nr)   )r   c                     g | ]	}|j         
S rI   rQ   ).0entrys     r+   
<listcomp>z,process_class_get_fields.<locals>.<listcomp>   s    555555r-   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
attrgetterr8   r>   	base_typer   is_externalimplementedr   r)   dataclass_fieldscopyrQ   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   r   )rE   r   	var_names	transformdefault_value_assignmentsr   fieldsr   rQ   r   r   
assignmentvalid_general_callvalid_simple_callr   fields                   r+   process_class_get_fieldsr      s   *(K(*=e*D*DEEEK55555I )33IIdOOO ) =I]]F
 (  	a	(C 	aDH ]^_a a a% 	/4466F'	  (  + +z::;PQQ
 ;;<MNN,,,248J:y'9:: <';;==ATTTC"+TZ9 9<OP P '1Y=V&W&W 'y&z'A9CVWW'y * : ??'y (4<w
:Kbdmdv@w@w # &0
I<T%U%U%m^h^mZm!* .? *. +> ? ? ?K]   Bblby   Bz6EEGGG  @B,,1Bl1R1R*.*[\\\dh77,77?w'8':KWM]&^^^ *. +006z7KT0R0RT T T dh
;;;$(OOE%'y(( EMt'-DJO$Mr-   c           
          t          dddddddd          }||d         rt           j        d           |d                                         D ]Z\  }}||vrt           j        d|z             t	          |t
          j                  st           j        d           |j        ||<   [|d	         }t                     }t           j                  }t          j
         j        |t          d
                    }	t
          j                             j         fd|                                D              fdd	|fddfD             z             }
t           j        |	|
          }t          j         j        t          j         j        t          d                    |          }t%           ||          }t          j         j        |g|z             }t)                      }t+          ||d          ||           t-          ||d          ||           t/          ||d          |           t1          ||d          |           t3          ||d          |           t5          ||d         |d         |d          |           |xj        |                                j        z  c_        t          j         j        t=           j        j         d          |          }|!                     j                   |"                      j                   |#                    |           |$                                  j%        j        &                    |           d S )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	attributec                     g | ]H\  }}t          j        j        t          |                     t          j        j        |           fIS r   r   IdentifierStringNoder)   r   r   r   r   r   rE   s      r+   r   z+handle_cclass_dataclass.<locals>.<listcomp>J  sa     	' 	' 	'a )$(-:J:JKKKdha0002 	' 	' 	'r-   c                     g | ]H\  }}t          j        j        t          |                     t          j        j        |           fIS r   r   r   s      r+   r   z+handle_cclass_dataclass.<locals>.<listcomp>M  sa     	
 	
 	
a )$(-:J:JKKKdha0002 	
 	
 	
r-   )slotsF)weakref_slotF__dataclass_params__r   rO   rR   )r   r   r   r   r   r   r   r   )annotation_typing)
directivesbody)'dictr   r)   r   r   r   r   ry   r   r,   AttributeNoder   r   
from_pairsr6   r   SingleAssignmentNodeNameNode_set_up_dataclass_fieldsStatListNoder]   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)rE   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  ,  s   t$45$@ @ @F !! 	Z$(XYYY"1%++-- 	  	 DAqdh^abbd d da!344 `dh^` ` `F1IIYG%d++F7AA
 &3DHBR>KL^>_>_a a a ) 2 = =	' 	' 	' 	'llnn	' 	' 	'	
 	
 	
 	
!7+')@B	
 	
 	
	
	! 	! 2')BD D"'"< >T0U0UVVV#  #  # 
 6dFDTUUtx&A%BE[%[] ] ]E >>DtVF^T67CCCf\2D&'JJJtVF^T6:::T6$<v666fWotV<<<tVM2F4L&BRTXZ`aaa	KK4%%''--KK
 248,TZ-BV[\\\  O ((444&&tTZ888  111%%'''IO?+++++r-   c                    |r|j                             d          rdS d|v rdnd}|g}|r|                    d           |                                 }|                                 } |                                  t          |j                  }t          j        |j        |t          d                    }	| 
                    ||	          }
d}|                                D ]\  }}|j                             |          }|j        rd	|j        j        j         }nd
}d
}|j        t"          us|j        t"          ur@|j        j        rd}|j        t"          ur|
}n| 
                    ||j                  }d| }n?|r=|s;|j        j        r/t)          |j        d|z             |                                   dS |j        j        r|                    | | |            |j        r|j        t"          u rK|j        j        r|                     | d| d|            D|r|                     | d| |            d| 
                    ||j                  }|j        j        r(|                     | d| d| d| d|
 d|            |                     | d| d| d           |j                             d          rLd                    d |                                D                       }|                     | d| d           |                                 r|                     d           d                    |          }|                    d| d           dS )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   .   K   | ]\  }}|j         |V  d S r:   )r   r   rQ   r   s      r+   	<genexpr>z%generate_init_code.<locals>.<genexpr>  sA       #8 #8KD%&+&6#84 #8 #8 #8 #8 #8 #8r-   z.__post_init__()passzdef __init__(z):)r   lookup_herer  r   rp   r,   r)   r   r   r   rz   r   lookup
annotationstringry   r   r   r   r   r   rk   r   re   joinrn   )r  r   rE   r   r   selfnamer    function_start_pointr  has_default_factorydefault_factory_placeholderseen_defaultrQ   r   r   r#  r   ph_namepost_init_varss                      r+   r   r   x  s1   &  4:))*55  (.'7'7##VH:D C//11!!DKKMMM 8AA#1 677   #'"6"6v?R"S"SL||~~ +G +Ge
!!$'' 	=e.5;==JJJ
=''5+@+O+Oz $#$G335..vu}EE(wJJ 	' 	ej.> 	%) 69=> ? ? ?JJLLLFF: 	;KK499Z99::: 	G"g--z E""h#@#@#@#@$#@#@AAAA E""h#C#C#Cz#C#CDDD**653HIIGz 	G ""mm$mm7mm$mmD_mmgkmm   
 ""h#E#E#E#E'#E#E#EFFFFz)) J #8 #86<<>> #8 #8 #8 8 8hHH~HHHIIIzz|| #6"""99T??D&&'?t'?'?'?@@@@@r-   c                 H   |r|j                             d          rdS g }|                                D ]:\  }}|pt          |d          o|j        j        }|s|                    |           ;|                     dt          t          |                    z             dS )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   r!  r   hasattrr   ry   r  re   strtuple)	r  r   rE   r   global_kw_onlypositional_arg_namesr   r   field_is_kw_onlys	            r+   r   r     s      //0@AA #\\^^ 4 4
E) 
E9%%=%-*= 	   	4 ''
333,s59M3N3N/O/OOPPPPPr-   c                     |r|j                             d          rdS d}|                                D ]D}|j                             |          }|j        }|j        r|j        }|j        s9|j        sd} nE|r|                     d           | 	                    d          5  |r)|                     d           | 
                                 d |                                D             }d	                    |          }	|                     d
|	 d           |rV|                                  | 	                    d          5  |                     d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )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:
            c                 J    g | ] \  }}|j         j        |j        |d |d!S )z={self.z!r})r   ry   r   r  s      r+   r   z&generate_repr_code.<locals>.<listcomp>"  sN     > > >D%:#>,1,<>DDD$$$/ > > >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   r"  keysr   is_memoryviewslicedtypeis_pyobjectis_gc_simpleri   rt   rp   r   r%  r   re   )
r  r   rE   r   needs_recursive_guardrQ   r   type_strsformat_strings
             r+   r   r     sk      4:$$Z00  " 	 	
!!$''
# 	 KE  	! 	$(!E	    	 	 	
 
,	-	- < <  	 !    KKMMM> >#)<<>>> > > 		$ ,   	 	 	 ! 	<KKMMMz** < <""#:;;;< < < < < < < < < < < < < < <-< < < < < < < < < < < < < < < < < <s7   &B#F	E+F+E/	/F2E/	3FF
Fc                 "   |j                             |          rd S d |                                D             }|                     d| d          5  |                     d|j         d|j         d           g }|                    dd          }|D ]C}|d	k    r|                     d
| d| d| d           |                     d
| d| d           D|                     dd|v rdnd            d d d            d S # 1 swxY w Y   d S )Nc                 >    g | ]\  }}|j         j        |j        |S rI   )r   ry   r   r  s      r+   r   z%generate_cmp_code.<locals>.<listcomp>5  s/    fffkdE8KfTYTdfTfffr-   z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   r!  r   rt   ri   
class_namereplacere   )	r  opfuncnamerE   r   r=   checksop_without_equalsrQ   s	            r+   generate_cmp_coderN  1  s   zh'' ffV\\^^fffE	6h666	7	7 I I  /   ?	   	 	 	" JJsB// 	U 	UDTzz""#gd#g#g5F#g#gTX#g#g#ghhhS$SStSSSTTTTGsbyyVVgGGHHH5I I I I I I I I I I I I I I I I I Is   B#DDDc                 4    |sd S t          | dd||           d S )NrD  __eq__rN  )r  r   rE   r   s       r+   r   r   T  s+     dD(D&99999r-   c                 D    |sd S dD ]\  }}t          | ||||           d S )N))<__lt__)z<=__le__)>__gt__)z>=__ge__rQ  )r  r   rE   r   rJ  rQ   s         r+   r   r   Z  sI     ' 8 8D 	$D$7777	8 8r-   c                    |j                             d          }|r!|rt          |j        d|j        z             dS |su|sdS |so|                     t          j        |j        t          j	        |j        t          d                    t          j        |j                            g           dS d |                                D             }d                    d |D                       }|r|d	z  }|                     d
          5  |                     d| d           ddd           dS # 1 swxY w Y   dS )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   c                 p    g | ]3\  }}|j         s'|j        j        |j        j        $n|j        j        1|4S r:   )r   r   ry   r   r  s      r+   r   z&generate_hash_code.<locals>.<listcomp>  sU       u $):#3#;EM#;#;AQ#; 	#;#;#;r-   r  c              3       K   | ]	}d |z  V  
dS )zself.%sNrI   )r   rQ   s     r+   r  z%generate_hash_code.<locals>.<genexpr>  s'       D DdT!1 D D D D D Dr-   ,zdef __hash__(self):zreturn hash((z)))r   r!  r   r)   rH  r~   r   r   r   r   r   r   r   r%  rt   re   )	r  r   r   r   rE   r   
hash_entryr=   hash_tuple_itemss	            r+   r  r  e  s   L ''
33J   	a$(MPTP__```  	F 	%%*H!*48-
:S:STTT!*4844  '    F  &  E yy D De D D DDD  C 
,	-	- A A?+;???@@@A A A A A A A A A A A A A A A A A As   D55D9<D9c                     |j         r|j         j        S t          |j                            dd                    }t          j        | |          S )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   )r#  r$  r   r   declaration_coder   UnicodeNode)r)   r   ss      r+   get_field_typere    sW      3
 &&" %*55ba5HHII$S2222r-   c                   @     e Zd ZdZdgZ fdZd Zd Zd Zd Z	 xZ
S )FieldRecordNodean  
    __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                 N    t                                          ||           d S )Nrh  )r;   r<   )r?   r)   rh  r@   s      r+   r<   zFieldRecordNode.__init__  s&    #&&&&&r-   c                 \    | j                             |           | j         j        | _        | S r:   )rh  analyse_typesr   r?   envs     r+   rl  zFieldRecordNode.analyse_types  s(    s###HM	r-   c                     | j         j                            |          r| j                             |          S |                                 S r:   )rh  r   can_coerce_to_pyobjectcoerce_to_pyobject_make_stringrm  s     r+   rq  z"FieldRecordNode.coerce_to_pyobject  sF    8=//44 	'8..s333
 $$&&&r-   c                     ddl m}  |d          }|                    | j                  }t	          j        | j        t          |                    S )Nr   )AnnotationWriterzDataclass field)descriptionr   )AutoDocTransformsrt  writerh  r   rc  r)   r   )r?   rt  r_   r$  s       r+   rr  zFieldRecordNode._make_string  s[    777777!!.?@@@dh''$TX]65J5JKKKKr-   c                 6    | j                             |          S r:   )rh  generate_evaluation_code)r?   r  s     r+   ry  z(FieldRecordNode.generate_evaluation_code  s    x00666r-   )rV   rW   rX   rY   subexprsr<   rl  rq  rr  ry  rZ   r[   s   @r+   rg  rg    s          wH' ' ' ' '  
' ' 'L L L7 7 7 7 7 7 7r-   rg  c                     g }|                                 D ]6\  }}|j        rdD ]$}t          ||          }|t          u s|j        s|j        r+ j                                        }|                    |                    t          j
         j                  |          }	t          j        |j        t          |	                    }
|                    |
j        |j        pt&          j        |j        |
j        d          |
_        t-          |||
           |                    t1          j        |j        |
|                     &8i }t          j         j        |t          d                    }t          j         j        g           }g }|                                 D ]\  }}|j        rd	|z  }t9           j         j        j        |                   ||<   d
|z  }|j        r-t          j         j        |t          d                    ||<   n`|j        r-t          j         j        |t          d                    ||<   n,t          j         j        |t          d                    ||<   t          j                              j         fd|!                                D                       }tE           j        ||          }|j#                            t          j$         j        t          j%         j        t          |                    |                     |                    tM          d|d|d|d| d|d| d                     t1          j         j        t          j         j        t          d                    |          }d'                    |          }tQ          |dtS          d           g          }|*                    |          }||gz   |j+        z   S )Nr   r   T)r   r)   r   is_cdefr   r   r   )key_value_pairszPLACEHOLDER_%szPLACEHOLDER_FIELD_TYPE_%s_FIELD_INITVAR_FIELD_CLASSVAR_FIELDc                     g | ]C\  }}t          j        j        t          |                     t	          j        |          fDS )r   rj  )r   r   r)   r   rg  r   s      r+   r   z,_set_up_dataclass_fields.<locals>.<listcomp>B  sd     A A A!Q ,TX]1=M=MNNNtxQ///1 A A Ar-   r   )r   ry   z%                __dataclass_fields__[z	].name = z&
                __dataclass_fields__[z	].type = z]._field_type = z
            __dataclass_fields__
r   r   ),r   r   r   r   r   rP   r   global_scopemangler
   dataclass_field_default_cnamerH  r   r   r)   r   declare_varrQ   r   r   unspecified_typer   setattrr  r   r   r   r   re  entriesr   r   r   r   r6   r}  DictItemNoder   r   r%  r   r   r   r   )rE   r   r  variables_assignment_statsrQ   r   attrnamefield_defaultr  module_field_name
field_noder`   
field_func	dc_fieldsdc_fields_namevalue_assignmentstype_placeholder_namefield_type_placeholder_namedc_field_keywordsdc_field_calldataclass_fields_assignments   `                   r+   r   r     s    "$||~~ b be= 	8 	b 	bH#E844M''=+C'}G\' :2244L , 3 3##F$H$/ZZ! ! #+M,=MRcDdDdeeeJ+77m&8&WJ<W!%Z_d  8    J E8Z000&--*=+<*R_```b b b b)	b. L(7G3@3I3IK K KJ"48R@@@I&(#||~~ / /e= 	 04 7.<Hdj(./
 /
*+
 'BD&H# 	8A8O.'(8999 9 9L455  
	8A8O.'(9::9 9 9L455
 9B8O.'119 9 9L45
 &.99HA A A A==??A A A
 
 3Hj"3
 
 	!(("248=QUCVCVWWW#% % %	& 	& 	&
 	(.. &* 7; &* 7L  '+  ?Z    	 	 	 	 	"48'0-:;Q-R-RT T T'	) 	) 	)   '+ii0O&P&P#&23R9B=J4=P=P<Q'S 'S 'S# 'F&P&PQ]&^&^#&*+,-34 5r-   )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   r]   r   r   r   r   r  r   r   r   rN  r   r   r  re  ExprNoderg  r   rI   r-   r+   <module>r     s   $ # # # # #                                      " " " " " " " " @ @ @ @ @ @ @ @ @ @ % % % % % % ) ) ) ) ) ) & & & & & & @ @ @ @ @ @ @ @ . . . . . . $     ") ) ) ) )/1A ) ) )XJ
 J
 J
 J
 J
 J
 J
 J
Z	 	 	 	 	 	 	 	
-///! /! /! /! /! /! /! /!dC C CLI, I, I,XbA bA bAJQ Q Q&>< >< ><B I  I  IF: : :8 8 8IA IA IAX3 3 3D#7 #7 #7 #7 #7i( #7 #7 #7Lk5 k5 k5 k5 k5r-   