
    ~lDhQ                       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
 ddlmZmZmZ ddlmZ dd	lmZmZmZ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  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/m0Z0 ddl1m2Z2 erddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<  G d de0          Z=dMd$Z>e
dNd&            Z?dOdPd/Z@dd0dQd9ZAdRd=ZBdSd@ZCddddAdTdEZDdUdGZEdUdHZFdVdLZGdS )WzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)copy)cache)	Parameterismethoddescriptor	signature)Pattern)TYPE_CHECKINGAnyCallableTypeVar)PydanticUndefined)TypeIs
get_origin)typing_objects)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError   )	_generics_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positionalBaseMetadata   )	FieldInfo)	BaseModel)StandardDataclass)DecoratorInfosc                      e Zd ZdZdZdS )PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r)       [/users/jtampere/www/backend/venv/lib/python3.11/site-packages/pydantic/_internal/_fields.pyr(   r(   '   s        ::IIIr/   r(   metadatar   returnr!   c                 0     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)r1   s    r0   pydantic_general_metadatar5   -   s     # ""8,,,r/   type[BaseMetadata]c                 :    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dS )7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.r1   r   c                    || _         d S )N)__dict__)selfr1   s     r0   __init__z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__A   s    $DMMMr/   N)r1   r   )r*   r+   r,   r-   r=   r)   r/   r0   _PydanticGeneralMetadatar9   >   s.        ::	% 	% 	% 	% 	% 	%r/   r>   )annotated_typesr!   r(   )r!   r>   s     r0   r4   r4   9   sK     -,,,,,% % % % %#3\ % % % $#r/   Fcls	type[Any]fieldsdict[str, FieldInfo]use_inspectboolNonec                    t          | |          }|                                D ]\  }}|j        ||v r||         |_        d S )NrD   )r   itemsdescription)r@   rB   rD   fields_docsann_name
field_infos         r0   _update_fields_from_docstringsrN   G   s[    -c{KKKK & ; ;*!)h+.E.E%0%:J"; ;r/   )typevars_maptype[BaseModel]config_wrapperr   ns_resolverNsResolver | NonerO   Mapping[TypeVar, Any] | None%tuple[dict[str, FieldInfo], set[str]]c               
   t                      }t                      }| j        }i }t          |          D ]*}t	          |dd          x}	r|                    |	           +t          j        | |          }
| j        	                    di           }i }t                      }|
                                D ]B\  }\  }}|dk    r|j        D ]J}d}t          |t                    r|                    |          du}n*t          |t                     r|                    |          }|r|D ]\}t%          ||          rJt'          ||          r|t	          |di           v s't)          d| dt	          ||           d	| d
          ]d}|j        D ]W}t          |t                    r%|                    |          s|d|j         dfz  }<|                    |          s||fz  }Xt-          j        d| d| j         d| d| d	t2                     Lt          j        |          r|                    |           t	          | |t8                    }t;          |          s| j        r|dk    rt)          d|d          t	          | di           	                    d          }|D ]}d t?          j         |          rt?          j!        |          ndD             }t%          ||          r=||u rK||v rP||vrUt-          j        d| d| j"         d|j"         dt2                     |t8          u rR||v s||vr3|#                    |tH          j%                  }|sd|_&        ||_'        nItQ          ||                   }n2tS          ||           t          ||          r4tU          |j+                  r |j+        ,                    d|           |_+        |s$t          ||          r|-                                n|}|.                    ||tH          j%                  }|sd|_&        ||_'        ||_/        nZd|j0        v rQ|1                                s=t-          j        d|d|d |d!td          d"#           |                    |           	 tg          | |           n# th          $ r Y nw xY w| j        d$         }||j5        v rtm          d%|d&| j        d'          |||<   D|r3|7                                D ]}|j&        r|8                    |           |j9        rtu          | |           ||fS )(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 two-tuple containing model fields 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.
    __pydantic_fields__N)rR   __annotations__model_configFzField "z" conflicts with member z of protected namespace "z".r)   zre.compile()z" in z( has conflict with protected namespace "z_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = z`.rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originc                    h | ]	}|j         
S r)   name).0fields     r0   	<setcomp>z'collect_model_fields.<locals>.<setcomp>   s'          $
     r/   zField name "z" in "z"" shadows an attribute in parent ""_source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>.`   )category
stacklevel__pydantic_decorators__zField z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.);r   r   	__bases__reversedgetattrupdater   get_model_type_hintsr;   getsetrI   protected_namespaces
isinstancer
   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr*   UserWarningis_classvar_annotationaddr   is_valid_field_name__pydantic_root_model__dataclassesis_dataclassrB   r,   from_annotationr   CLASS	_complete_original_annotationr   #_warn_on_nested_alias_in_annotationr   default__get___copyfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorcomputed_fields	TypeErrorvaluesapply_typevars_mapuse_attribute_docstringsrN   )r@   rQ   rR   rO   r$   
FieldInfo_basesparent_fields_lookupbasemodel_fields
type_hintsr   rB   
class_varsrL   ann_type	evaluatedprotected_namespacens_violationbvalid_namespacespnassigned_valuegeneric_origindataclass_fieldsrM   original_assignment
decoratorsrb   s                                r0   collect_model_fieldsr   N   s2   > )**I)++JME13 6 6"4)>EEE< 	6 ''5553C[QQQJ ,""#4b99K#%F55J+5+;+;+=+= R& R&''8Y~%% #1#F 	 	!&L-w77 H288BB$N/55 H'223FGG   Aq(++  *1i 8 8 XQRTikmInIn=n=n"+!T( !T !TGTUW_L`L` !T !T<O!T !T !T# # 
 (*$,A : :%b'22 :#%88H#5#5 S 05P2:5P5P5P4R R 0#+#6#6r#:#: : 0RE 9 0MY( Y Y Y Ygz Y YDTY Y Y $	   /99 	NN8$$$ h0ABB"8,, 	& 	8v+=+=nhnnn   !&ErJJNNxXX 	 	D   EPE]^bEcEc)k);D)A)A)Aik      tX&& >))/// ;..-8 - -33C - -)- - -   ...;&&(:N*N*N (77JZJ`7aa
  ?+0J( 7?J3 ""6x"@AA

 0(CCC.*55 S:L^Mc:d:d S *8)?)G)Gc)R)R& /8vJ~Wa<b<bv$$&&&hv   $<<X~_o_u<vvJ ',
$ 3;
/2E
//J222:;Q;Q;S;S2E( E Eks E E"*E E E 8     x(((
X&&&&!   
 &)\2K%L
z111G G Gs| G G G   &x 7]]__ 	7 	7E 7((666. 4&sF333:s    R11
R>=R>r   rL   rv   c                8   t                      }t          | dd           }|rv|D ]u}t          j        t	          |                    rPt          j        |          D ];}t          ||          r)|j        "t          j
        d| dt                       d S <td S d S )N__args__z `alias` specification on field "z5" must be set on outermost annotation to take effect.)r   rn   r   is_annotatedr   r   get_argsrt   aliasr|   r}   r~   )r   rL   r#   argsanno_arganno_type_args         r0   r   r     s    (**I8Z..D 	 	 	H*:h+?+?@@ %2%;H%E%E  M!-;; @S@_ ~x~~~'   	 		 	r/   r   Mapping[TypeVar, Any]c               &   t                      }i }|                    |           5  | j                                        D ]\  }}|j        r|||<   |j        }t          j        |j        g|j	        R  }t          j        ||          }|j        x}	t          u r"|                    |t          j                  }
n"|                    ||	t          j                  }
|
j        |
j        n||
_        |
||<   	 ddd           n# 1 swxY w Y   |S )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.

    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.
    re   N)r   pushrW   rI   r   rJ   r   	eval_typer   types_namespacer   replace_typesr   r   r   r   r   r   )r@   rR   rO   r   rebuilt_fieldsf_namerM   existing_descannassign	new_fields              r0   rebuild_model_fieldsr   ,  s   " *++J+-N			#		 3 3"%"9"?"?"A"A 	3 	3FJ# 3)3v&& * 6#-3 0    -c<@@(==FBSSS * : :3HXH^ : _ _II * C CCYiYo C p pIAJAVAb	(=(=hu	%)2v&&#	33 3 3 3 3 3 3 3 3 3 3 3 3 3 3( s   CDD
D
)rR   rO   rQ   type[StandardDataclass]dict[Any, Any] | NoneConfigWrapper | Nonec          
        t                      }i }|pt                      }| j        }t          | j                  D ]}t          j        |          s|                    |          5  |                                D ]f\  }}	||j	        
                    di           vr$|j        \  }
}t          j        |	j        |
|          \  }}t          j        |          ra|	j        s'|	j        t
          j        u r|	j        t
          j        u rt)          |	j        |          rX|	j        j        r$|	j        j        du rt-          d| dd          |                    ||	j        t0          j                  }n"|                    ||	t0          j                  }|||<   |j        t4          ur5t)          t7          | ||          |          rt9          | ||j                   h	 ddd           n# 1 swxY w Y   |r,|                                D ]}|                    |           |(|j        r!tA          | |tC          | d	           
           |S )a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        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.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass fields.
    rX   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)codere   N__is_pydantic_dataclass__rH   )"r   r   __dataclass_fields__rm   __mro__r   r   r   rI   r;   rq   r   r   try_eval_typetyper   initr   MISSINGdefault_factoryrt   init_varr   r   r   	DATACLASSr   rn   setattrr   r   r   rN   rx   )r@   rR   rO   rQ   r   rB   r   r   rL   dataclass_fieldglobalnslocalnsr   _rM   rb   s                   r0   collect_dataclass_fieldsr   W  s   & *++J#%F-K/
 %% 2? 2?'-- 	d## .	? .	?-=-C-C-E-E -? -?)/4=#4#45F#K#KKK $/$?!'+9/:NPXZabb! 7AA  (,'/;3FFF'7;;NNN o5zBB &.7 !*275@@"3 !B8  !B  !B  !B%A# # #  !!+!D!D /"9CSC] "E " "JJ ",!D!D /;K;U "E " "J $.x %->>>:C:66
D D> C:+=>>>[-?.	? .	? .	? .	? .	? .	? .	? .	? .	? .	? .	? .	? .	? .	? .	?`  3]]__ 	3 	3E $$\2222!n&M!& $C)DEEE	
 	
 	
 	
 Ms   )E=G33G7	:G7	r`   c                .    |                      d           S )Nr   rw   r_   s    r0   r   r     s    s####r/   c                X    |                      d          o|                      d           S )Nr   __r   r_   s    r0   is_valid_privateattr_namer     s(    ??3=(=(=$==r/   r   3Callable[[], Any] | Callable[[dict[str, Any]], Any]'TypeIs[Callable[[dict[str, Any]], Any]]c                "   	 t          |           }n# t          t          f$ r Y dS w xY wt          |j                                                  }t          |          dk    o-t          |d                   o|d         j        t          j
        u S )zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r	   
ValueErrorr   list
parametersr   lenr   r   r   empty)r   sigr   s      r0   takes_validated_data_argumentr     s    ((	"    uu
 cn++--..Jz??aq$5jm$D$DqTUI^bkbqIqqs    '')r1   r   r2   r!   )r2   r6   )F)r@   rA   rB   rC   rD   rE   r2   rF   )
r@   rP   rQ   r   rR   rS   rO   rT   r2   rU   )r   rA   rL   rv   r2   rF   )r@   rP   rR   r   rO   r   r2   rC   )
r@   r   rR   rS   rO   r   rQ   r   r2   rC   )r`   rv   r2   rE   )r   r   r2   r   )Hr-   
__future__r   _annotationsr   r|   collections.abcr   r   	functoolsr   inspectr   r   r	   rer
   typingr   r   r   r   pydantic_corer   typing_extensionsr   r   typing_inspectionr   typing_inspection.introspectionr   pydanticr   pydantic.errorsr    r   r   _configr   _docs_extractionr   _import_utilsr   r   _namespace_utilsr   _reprr   _utilsr   r?   r!   rB   r#   mainr$   _dataclassesr%   _decoratorsr&   r(   r5   r4   rN   r   r   r   r   r   r   r   r)   r/   r0   <module>r      s`   s s 2 2 2 2 2 2      # # # # # #             < < < < < < < < < <       8 8 8 8 8 8 8 8 8 8 8 8 + + + + + + 0 0 0 0 0 0 0 0 , , , , , , < < < < < < / / / / / / - - - - - - & & & & & & & & " " " " " " 9 9 9 9 9 9 M M M M M M M M ( ( ( ( ( ( ! ! ! ! ! ! % % % % % % ,,,,,,,""""""      //////++++++    ~   	- 	- 	- 	- 
$ 
$ 
$ 
$; ; ; ; ; 26K K K K K K\    ( ( ( (\ &**.+/` ` ` ` ` `F$ $ $ $> > > >r r r r r rr/   