
    KiE{                       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
mZmZ ddlmZ ddlmZmZ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 ddlmZ ddlm Z  ddl!m"Z"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dl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 er ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< ddl=m>Z>  G d de0      Z? ej                  d8i e, G d  d!             ZAd9d"ZBe	d:d#       ZC	 	 	 	 	 	 	 	 	 	 d;d$ZDd<d=d&ZE	 	 	 	 	 	 d>d'ZF	 	 	 	 	 	 d?d(ZGd@d)ZHh d*ZIh d+ZJdd,	 	 	 	 	 	 	 	 	 dAd-ZK	 	 	 	 	 	 	 	 	 	 dBd.ZL	 	 	 	 	 	 	 	 	 	 dCd/ZMddd0	 	 	 	 	 	 	 	 	 dDd1ZN	 	 	 	 	 	 	 	 	 	 dEd2ZOdFd3ZPdFd4ZQ	 	 	 	 dGd5ZRdd%d6	 	 	 	 	 	 	 	 	 dHd7ZSy)IzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)cache)	Parameterismethoddescriptor)Pattern)TYPE_CHECKINGAnyCallableTypeVarcast)PydanticUndefined)TypeIs)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError   )AliasGenerator   )	_generics_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
slots_true)
NsResolver)Representation)can_be_positionalget_first_not_noneBaseMetadata)	FieldInfo)	BaseModel)PydanticDataclassStandardDataclass)DecoratorInfosc                      e Zd ZdZdZy)PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r*       f/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/pydantic/_internal/_fields.pyr)   r)   '   s
    :Ir0   r)   c                  "    e Zd ZU ded<   ded<   y)PydanticExtraInfor
   
annotationboolcompleteN)r+   r,   r-   __annotations__r*   r0   r1   r3   r3   -   s     ONr0   r3   c                 "     t               |       S )zCreate a new `_PydanticGeneralMetadata` class with the given metadata.

    Args:
        **metadata: The metadata to add.

    Returns:
        The new `_PydanticGeneralMetadata` class.
    )_general_metadata_cls)metadatas    r1   pydantic_general_metadatar;   4   s     # "8,,r0   c                 2    ddl m}   G d dt        |       }|S )zCDo it this way to avoid importing `annotated_types` at import time.r   r!   c                      e Zd ZdZddZy)7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.c                    || _         y N)__dict__)selfr:   s     r1   __init__z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__H   s	    $DMr0   N)r:   r
   )r+   r,   r-   r.   rC   r*   r0   r1   _PydanticGeneralMetadatar>   E   s
    :	%r0   rD   )annotated_typesr"   r)   )r"   rD   s     r1   r9   r9   @   s     -%#3\ % $#r0   c                   t               }| D ]\  }d}t        |t              r|j                  |      d u}n!t        |t              r|j                  |      }|sN|D ]I  }t        ||      st        ||      r|t        |di       v r,t        d|dt        ||       d|d       g }| D ]k  }	t        |	t              r2|	j                  |      r%|j                  d|	j                  d       E|j                  |	      rW|j                  d	|	 d	       m d
dj                  |       t        |      dk(  rdnd }
t        j                  d|d|d|d|
 d	t         d       _ y )NF__pydantic_fields__Field z conflicts with member z of protected namespace .zre.compile()'(z, r   z,)z in z$ conflicts with protected namespace zX.

You may be able to solve this by setting the 'protected_namespaces' configuration to    
stacklevel)r   
isinstancer   matchstr
startswithhasattr
issubclassgetattr
ValueErrorappendpatternjoinlenwarningswarnUserWarning)protected_namespacesann_namebasescls_namer$   protected_namespacens_violationbvalid_namespacespnvalid_namespaces_strs              r1   _check_protected_namespacesri   N   s    )*I3  )73.44X>dJL+S1#../BCL 1h'&q)4WQPegiEj9j($XL0GPQS[H\G]67J6MQP  /1 . ?B!"g.!xx1,33k"**q4QR'2226,33at1I>? *+4995E+F*GPSTdPeijPjpsGt'u$XLXL8\]p\s tl mA  lB  BCD 	7 r0   Fc                    t        | |      }|j                         D ]!  \  }}|j                  ||v s||   |_        # y )Nuse_inspect)r   itemsdescription)clsfieldsrl   fields_docsr`   
field_infos         r1   _update_fields_from_docstringsrs   y   sH    -c{KK & ;*!!)h+.E%0%:J";r0   c                    |j                   < | ||      }t        |t              st        d|  d|j                         ||_         y y )Nzfield_title_generator  must return str, not )titlerP   rR   	TypeError	__class__)title_generator
field_namerr   rv   s       r1   *_apply_field_title_generator_to_field_infor{      sV    
 
J7%%4_4EE[\a\k\k[lmnn 
  r0   c                   |j                   4|j                   dk  s%|j                  |j                  |j                  d\  }}}t	        | t
              r| j                  |      \  }}}n>t        |       r3 | |      }t	        |t              st        d|  d|j                         |j                   |j                   dk  rd|_         |j                   dk(  r)t        ||      |_        t        ||      |_        ||_        |j                  ||_        |j                  t        ||      |_        |j                  t        ||      |_        yyy)av  Apply an alias generator to aliases on a `FieldInfo` instance if appropriate.

    Args:
        alias_generator: A callable that takes a string and returns a string, or an `AliasGenerator` instance.
        field_name: The name of the field from which to generate the alias.
        field_info: The `FieldInfo` instance to which the alias generator is (maybe) applied.
    Nr   )NNNzalias_generator ru   )alias_priorityaliasvalidation_aliasserialization_aliasrP   r   generate_aliasescallablerR   rw   rx   r    )alias_generatorrz   rr   r~   r   r   s         r1   $_apply_alias_generator_to_field_infor      sh    	!!)$$)#&&.))17G4!4o~6;J;[;[\f;g8E#%8o&#J/EeS)"2?2CCYZ_ZiZiYj kll
 $$,
0I0IQ0N()J% $$)-?@SUZ-[J**<=Mu*UJ'$J #$J))1-?@SUZ-[J*&&.*<=Mu*UJ' /9 2r0   c                    |j                   xs | j                   }|t        |||       | j                  t        | j                  ||       yy)ap  Update the `FieldInfo` instance from the configuration set on the model it belongs to.

    This will apply the title and alias generators from the configuration.

    Args:
        config_wrapper: The configuration from the model.
        field_name: The field name the `FieldInfo` instance is attached to.
        field_info: The `FieldInfo` instance to update.
    N)field_title_generatorr{   r   r   )config_wrapperrz   rr   r   s       r1   update_field_from_configr      sS     '<<d@d@d(23H*V`a%%1,^-K-KZYcd 2r0   >   copydictjson_iter_calculate_keys_copy_and_set_values>
   schemafrom_ormvalidate	construct	parse_obj	parse_raw
_get_value
parse_fileschema_jsonupdate_forward_refs)typevars_mapc                  t               }t               | j                  }i }t        |      D ]#  }t	        |dd      x}s|j                  |       % t        j                  | |      }	t        j                  |       }
i }t               }|	j                         D ]T  \  }\  }}|dk(  rt        |j                  ||| j                         t        j                  |      r|j                  |       Zt	        | |t               t         urDt#        fdt$        D              s%t'        d      rt#        fdt(        D              rt         t+        |      s| j,                  r|d	k7  rt/        d
|d      |D ]  }t'        ||      s||
vrt	        | di       j1                  d      }||u r6t3        j4                  |      rt3        j6                  |      ndD ch c]  }|j8                   }}||v r~t;        j<                  d| d| j>                   d|j>                   dt@        d        t         u rd||
v s||vr4|jC                  |tD        jF                        }||_$        |s"d|_%        n||   jM                         }|rtO        |||d      }n|}ntQ        |      rGtS        jT                        r2jT                  jW                  d|       }|_*        |jX                  d<   |j[                  |tD        jF                        }|_.        ||_$        |sd|_%        nWd|j^                  v rI|ja                         s9t;        j<                  d|d|d|dtb        d       |j                  |       	 te        | |       | jh                  d    }||jj                  v rtm        d!|d"| j                  d#      |||<   |jJ                  sHto        |||       W |jp                  rts        | |       d}d$|	v r|	d$   \  }}tu        ||%      }|||fS c c}w # tf        $ r Y w xY w)&a  Collect the fields and class variables names of a nascent Pydantic model.

    The fields collection process is *lenient*, meaning it won't error if string annotations
    fail to evaluate. If this happens, the original annotation (and assigned value, if any)
    is stored on the created `FieldInfo` instance.

    The `rebuild_model_fields()` should be called at a later point (e.g. when rebuilding the model),
    and will make use of these stored attributes.

    Args:
        cls: BaseModel or dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting model annotations.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        A three-tuple containing the model fields, the `PydanticExtraInfo` instance if the `__pydantic_extra__` annotation is set,
        and class variables names.

    Raises:
        NameError:
            - If there is a conflict between a field name and protected namespaces.
            - If there is a field other than `root` in `RootModel`.
            - If a field shadows an attribute in the parent model.
    rG   N)ns_resolvermodel_config)r_   r`   ra   rb   c              3  <   K   | ]  }t        |d       u   y wr@   )rV   .0	depr_name
BaseModel_assigned_values     r1   	<genexpr>z'collect_model_fields.<locals>.<genexpr>&  s     q9
It4Fqs   __func__c              3  f   K   | ](  }t        t        |d       dd       j                  u  * y w)Nr   )rV   r   r   s     r1   r   z'collect_model_fields.<locals>.<genexpr>*  s7      ! GJ	4@*dSWeWnWnns   .1rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originr*   zField name "z" in "z"" shadows an attribute in parent ""   rN   _sourceFTr   r   lenientdefaultfinalzAnnotation z= is marked as final and has a default value. Pydantic treats zz as a class variable, but it will be considered as a normal field in V3 to be aligned with dataclasses. If you still want zV to be considered as a class variable, annotate it as: `ClassVar[<type>] = <default>.`)categoryrO   __pydantic_decorators__rH   z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.__pydantic_extra__r4   r6   );r   r   	__bases__reversedrV   updater   get_model_type_hintssafe_get_annotationssetrm   ri   r_   r+   is_classvar_annotationaddr   any_deprecated_method_namesrT   _deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__	NameErrorgetdataclassesis_dataclassrp   namer\   r]   r-   r^   from_annotationr   CLASS_original_annotation	_complete_copy_recreate_field_inforP   r   r   __get___attributes_setfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorrA   computed_fieldsrw   r   use_attribute_docstringsrs   r3   )ro   r   r   r   
FieldInfo_ra   parent_fields_lookupbasemodel_fields
type_hintscls_annotationsrp   
class_varsr`   ann_type	evaluatedgeneric_originfielddataclass_fieldsrr   parent_field_infor   
decoratorspydantic_extra_infoannr6   r   r   s                             @@r1   collect_model_fieldsr      s   @ *+J)+JMME13 6"4)>EE<E ''56 33C[QJ $88=O#%F5J+5+;+;+= SK''8Y~% #!/!D!D\\		
 //9NN8$ h0AB!22qXpqq 
3 %B  /N"8,&&8v+=-h\9mn   	DtX&?2 ").Mr!R!V!VW_!`>) JUIaIabfIg[-?-?-Emo$#(EJJ$  $ // "8*F33C3C2D E))*!- 	+	8 ..?*h>R.R (77JZJ`J`7a
2:
/ +0J(
 %9$B$H$H$J!  !5){Q]gk"J "3J .*5:L^McMc:d )0088sC)0&<C..y9#<<X~_o_u_u<vJ /=J+.6J+',
$J222:;Q;Q;S!(-jksjv w""*  .DE 8  x(
X& &)\\2K%L
z111Js||.> ?G G  &x$^XzJgSKj ..&sF348z)"#78X/

 &
22U$\ " s   'P.P33	P?>P?c                  i }|j                  |       5  | j                  j                         D ]8  \  }}|j                  r|||<   t	        |||d      }t        |||       |||<   : | j                  V| j                  j                  s@t        t        j                  | j                  j                  g|j                   d      }n| j                  }ddd       ||fS # 1 sw Y   |fS xY w)a^  Rebuild the (already present) model fields by trying to reevaluate annotations.

    This function should be called whenever a model with incomplete fields is encountered.

    Returns:
        A two-tuple, the first element being the rebuilt fields, the second element being
        the rebuild `PydanticExtraInfo` instance, if available.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the model fields in place, as it can be called during
        schema generation, where you don't want to mutate other model's fields.
    Fr   NTr   )pushrG   rm   r   r   r   __pydantic_extra_info__r6   r3   r   	eval_typer4   types_namespace)	ro   r   r   r   rebuilt_fieldsf_namerr   	new_fieldrebuilt_extra_infos	            r1   rebuild_model_fieldsr     s
   , ,.N			#	 ="%"9"9"?"?"A 	3FJ##)3v&0Kl\a	 )K)2v&	3 &&23;V;V;_;_!2(22//::=H=X=X 	" "%!<!<'=* ---+=* ---s   CC$$C0c                  t               }| j                  }|rDt        j                  | j                  |      }t        j                  |g|j                   \  }}nbt        j                  | j                  g|j                   }t        j                  ||      }t        j                  |g|j                   }d}| j                  x}t        u r"|j                  |t        j                        }	n)|j                  ||t        j                        }	||	_	        ||	_        |	j                  |	j                  n||	_        |sd|	_        |	S )NTr   F)r   rn   r   replace_typesr   r   try_eval_typer   r   r   r   r   r   r   r   r   )
rr   r   r   r   r   existing_descr   r   assignr   s
             r1   r   r     sG    *+J**M%%j&E&E|T&44
((
Y %%++
((
 %%c<8%%
((
 	1116GG..s<L<R<R.S	77VM]McMc7d	)/	&%(I"5>5J5J5VI11\iI#	r0   )r   r   c          
     l   t               }i }|xs
 t               }| j                  }t        | j                        D ]  }t        j                  |      s|j                  |      5  |j                         D ]  \  }}	t        j                  |      }
||
vr!|j                  \  }}t        j                  |	j                  ||      \  }}t        j                  |      rj|	j                  s9|	j                   t
        j"                  u r|	j$                  t
        j"                  u rt'        |	j                   |      r|	j                   j(                  r+|	j                   j                  du rt+        d| dd      |j-                  ||	j                   t.        j0                        }|	j                   |_        n)|j-                  ||	t.        j0                        }|	|_        |sd|_        ||_        |||<   t9        |||       |j                   t:        ust'        t=        | ||      |      st?        | ||j                           	 ddd        |r&|jA                         D ]  }|jC                  |        |jD                  rtG        | |tI        | d       	       |S # 1 sw Y   wxY w)
a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
            Defaults to an empty instance.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        The dataclass fields.
    FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coder   N__is_pydantic_dataclass__rk   )%r   r   __dataclass_fields__r   __mro__r   r   r   rm   r   r   r   r   typer   initr   MISSINGdefault_factoryrP   init_varr   r   r   	DATACLASSr   r   r   r   r   rV   setattrvaluesapply_typevars_mapr   rs   rT   )ro   r   r   r   r   rp   r   r   r`   dataclass_field	base_annsglobalnslocalnsr   r   rr   r   s                    r1   collect_dataclass_fieldsr	    s   & *+J#%F-K//
 % ;?''-d# 7	?-=-C-C-E 6?)/)>>tD	9, $/$?$?!'&3&A&A/BVBVX`bi&j#) 77A (,,'//;3F3FF'77;;N;NN o55zB&..77*22775@"3"28*  =A  !B%A#  !!+!D!D /"9"9CSC]C] "E "J 7F6M6MJ3!+!D!D /;K;U;U "E "J 7FJ3 +0J(6>J3#-x (:N%%->>:C:6
D C:+=+=>m6?7	? 7	?	;?z ]]_ 	3E $$\2		3 ..& $C)DEE	
 MS7	? 7	?s   'F2J)J)4J))J3	c               (   t               }i }|j                  |       5  | j                  j                         D ]  \  }}|j                  r|||<   |j
                  }t        j                  |j                  g|j                   }	t        j                  |	|      }	|j                  |	|j                  t        j                        }
|
j
                  |
j
                  n||
_        t!        |||
       |
||<    	 ddd       |S # 1 sw Y   |S xY w)a  Rebuild the (already present) dataclass fields by trying to reevaluate annotations.

    This function should be called whenever a dataclass with incomplete fields is encountered.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the dataclass fields in place, as it can be called during
        schema generation, where you don't want to mutate other dataclass's fields.
    r   N)r   r   rG   rm   r   rn   r   r   r   r   r   r   r   r   r   r  r   )ro   r   r   r   r   r   r   rr   r   r   r   s              r1   rebuild_dataclass_fieldsr  {  s   $ *+J+-N			#	 3"%"9"9"?"?"A 	3FJ##)3v& * 6 6#--33 00  --c<@&??33,66 @ 	 BKAVAVAb	(=(=hu	%(K)2v&'	33, -3, s   CDDc                &    | j                  d       S )N_rS   r   s    r1   r   r     s    s###r0   c                L    | j                  d      xr | j                  d       S )Nr  __r  r  s    r1   is_valid_privateattr_namer    s"    ??3=(=$==r0   c                   	 t        j                  |       }t	        |j
                  j                               }t        |      dk(  xr/ t        |d         xr |d   j                  t        j                  u S # t        t        f$ r Y yw xY w)zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r   signature_no_evalrW   rw   list
parametersr  r[   r   r   r   empty)r   sigr  s      r1   takes_validated_data_argumentr    s    --o> cnn++-.Jz?aq$5jm$DqTUI^I^bkbqbqIqq 	"  s   A9 9B
B)validated_datacall_default_factoryc                   ddl m} | ||       S |r@t        |      r!t        d|      }|t	        d       ||      S t        d|      } |       S t
        S )zMResolve the default value using either a static default or a default_factory.r   )smart_deepcopy)r   zCallable[[dict[str, Any]], Any]zpThe default factory requires the 'validated_data' argument, which was not provided when calling 'get_default()'.zCallable[[], Any])_utilsr  r  r   rW   r   )r   r   r  r  r  facs         r1   resolve_default_valuer     sp     'g&&(I8/JC%  G  ~&&*O<C5Lr0   r*   )r:   r
   returnr"   )r!  ztype[BaseMetadata])
r_   ztuple[str | Pattern[str], ...]r`   rR   ra   ztuple[type[Any], ...]rb   rR   r!  None)F)ro   z	type[Any]rp   dict[str, FieldInfo]rl   r5   r!  r"  )ry   zCallable[[str, FieldInfo], str]rz   rR   rr   r#   )r   z%Callable[[str], str] | AliasGeneratorrz   rR   rr   r#   )r   r   rz   rR   rr   r#   r!  r"  )
ro   type[BaseModel]r   r   r   r   r   zMapping[TypeVar, Any] | Noner!  z?tuple[dict[str, FieldInfo], PydanticExtraInfo | None, set[str]])
ro   r$  r   r   r   r   r   Mapping[TypeVar, Any]r!  z5tuple[dict[str, FieldInfo], PydanticExtraInfo | None])
rr   r#   r   r   r   r%  r   r5   r!  r#   )
ro   ztype[StandardDataclass]r   r   r   zNsResolver | Noner   zdict[Any, Any] | Noner!  r#  )
ro   ztype[PydanticDataclass]r   r   r   r   r   r%  r!  r#  )r   rR   r!  r5   )r   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]r!  z'TypeIs[Callable[[dict[str, Any]], Any]])
r   r
   r   z:Callable[[], Any] | Callable[[dict[str, Any]], Any] | Noner  zdict[str, Any] | Noner  r5   r!  r
   )Tr.   
__future__r   _annotationsr   r\   collections.abcr   	functoolsr   inspectr   r   rer   typingr	   r
   r   r   r   pydantic_corer   typing_extensionsr   typing_inspection.introspectionr   pydanticr   pydantic.errorsr   aliasesr    r   r   _configr   _docs_extractionr   _import_utilsr   r   _internal_dataclassr   _namespace_utilsr   _reprr   r  r   r    rE   r"   rp   r#   mainr$   _dataclassesr%   r&   _decoratorsr'   r)   	dataclassr3   r;   r9   ri   rs   r{   r   r   r   r   r   r   r   r	  r  r   r  r  r   r*   r0   r1   <module>r>     s   s 2   #  1  > > + $ < / - $ & " 9 M + ( ! 9," B+~  $$  %	- 
$ 
$(8(( !( 	(
 
(V;
!4
!
! 
!/V:/VHK/VYb/Vde" h ! & 26Q3	Q3!Q3 Q3
 /Q3 EQ3h,.	,. ",. 	,.
 (,. ;,.^))) ()
 ) )` &**.i	 i "i #	i
 (i iX+	 + "+ 	+
 (+ +\$>rHr,r( -1!&O *	
  	r0   