
    h	.                     >   S SK r S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
JrJr  SSKJrJr  \
" S\\\4   S9r\
" S	\\\4   S9rS
\	S\4S jrS rS\\   4S jrS\S\S\4S jr S(S\S\S\SS4S jjrS\S\4S jrS\ R2                  S\ R2                  S\S\S\S\4S jrS\ R2                  S\ R2                  S\S\S\S\S\4S  jrS!\S"\S#\S\ R2                  S$\ R                  S\4S% jrS\ R2                  S\ R2                  S\S\SS4
S& jrS\S\S\4S' jrg))    N)	Parameter)FunctionType)CallableDictOptionalTupleTypeTypeVarUnionget_type_hints   )get_args	issubtype_WrappedMethod)bound_WrappedMethod2treturnc                 x    [        U [        5      (       a  g[        U 5       H  n[        U5      (       d  M    g   g)aK  Recursively check if `t` or any types contained by `t` is a `TypeVar`.

Examples where we return `True`: `T`, `Optional[T]`, `Tuple[Optional[T], ...]`, ...
Examples where we return `False`: `int`, `Optional[str]`, ...

:param t: Type to evaluate.
:return: `True` if the input type contains an unbound `TypeVar`, `False` otherwise.
TF)
isinstancer
   r   _contains_unbound_typevar)r   args     fC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\overrides/signature.pyr   r      s7     !W {$S))      c                     [        U 5      (       a  gUc  g[        U5      (       a  g [        X5      $ ! [         a     gf = f)NT)r   r   	TypeError)leftrights     r   
_issubtyper   "   sH     &&} ''%% s   
3 
A A c                 F     [        U 5      $ ! [        [        4 a     g f = fN)r   	NameErrorr   callables    r   _get_type_hintsr%   0   s)    h''y! s   
   	callable1	callable2c                     U R                   R                  S5      S   n[        USS 5      nUc  gUR                  S5      S   nX#:H  $ )N.r   
__module__F)r*   splitgetattr)r&   r'   mod1mod2s       r   _is_same_moduler/   7   sO    %%c*1-D 9lD1D|::c?1D<r   super_callablesub_callable	is_staticc           	      |   [        U 5      n [        U5      n [        R                  " U 5      n[	        U 5      n[        R                  " U5      n[	        U5      nUR
                  n[        X5      nUb-  Ub*  [        XFU5        [        X5XFX'5        [        UUUUUUU5        [        X5X'5        g! [         a     gf = f)a  Ensure that the signature of `sub_callable` is compatible with the signature of `super_callable`.

Guarantees that any call to `super_callable` will work on `sub_callable` by checking the following criteria:

1. The return type of `sub_callable` is a subtype of the return type of `super_callable`.
2. All parameters of `super_callable` are present in `sub_callable`, unless `sub_callable`
   declares `*args` or `**kwargs`.
3. All positional parameters of `super_callable` appear in the same order in `sub_callable`.
4. All parameters of `super_callable` are a subtype of the corresponding parameters of `sub_callable`.
5. All required parameters of `sub_callable` are present in `super_callable`, unless `super_callable`
   declares `*args` or `**kwargs`.

:param super_callable: Function to check compatibility with.
:param sub_callable: Function to check compatibility of.
:param is_static: True if staticmethod and should check first argument.
N)_unbound_funcinspect	signature
ValueErrorr%   __qualname__r/    ensure_return_type_compatibility ensure_all_kwargs_defined_in_sub)ensure_all_positional_args_defined_in_subensure_no_extra_args_in_sub)	r0   r1   r2   	super_sigsuper_type_hintssub_sigsub_type_hintsmethod_namesame_main_modules	            r   ensure_signature_is_compatiblerC   B   s    * #>2N .L%%n5	 '~6-G$\2N++K&|D#(B()9;W( 0)	
 	2	
  	IK1  s   B. .
B;:B;r$   c                 b    [        U S5      (       a  [        U S5      (       a  U R                  $ U $ )N__self____func__)hasattrrF   r#   s    r   r4   r4   w   s,    x$$:)F)F   Or   r=   r?   r>   r@   check_first_parameterrA   c                 |   [        S UR                  R                  5        5       5      n[        U R                  R	                  5       5       GH  u  nu  pUS:X  a	  U(       d  M  U	R
                  [        R                  :X  a  M8  U	R
                  [        R                  :X  a  MX  [        USXaU	5      (       d  [        U SU S35      eXR                  ;   d  M  U	R
                  [        R                  :w  d  M  [        UR                  R                  5       5      R                  U5      n
UR                  U   nU	R
                  UR
                  :w  aZ  U	R
                  [        R                  :X  a  UR
                  [        R                   :X  d  [        U SU SU	R
                   S35      eXz:  a2  U	R
                  [        R                  :w  a  [        U SU SU S35      eX;   d  GM  X;   d  GM  [#        X(   X8   5      (       a  GM  [        SU S	U S
U	R$                   SUR$                   S3	5      e   g )Nc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr!   kindr   VAR_KEYWORD.0ps     r   	<genexpr>3ensure_all_kwargs_defined_in_sub.<locals>.<genexpr>   s!      1LA)'''1L   )+r   T: `z` is not present.
` is not ``z` is not parameter at index `: z must be a supertype of `
` but is `)any
parametersvalues	enumerateitemsrL   r   VAR_POSITIONALPOSITIONAL_ONLYis_param_defined_in_subr   rM   listkeysindexKEYWORD_ONLYPOSITIONAL_OR_KEYWORDr   
annotation)r=   r?   r>   r@   rH   rA   sub_has_var_kwargssuper_indexnamesuper_param	sub_index	sub_params               r   r:   r:   }   s     181C1C1J1J1L  -6i6J6J6P6P6R,S((d!$9y777y888&$*[
 
 {m3tf4EFGG'''K,<,<	@U@U,UW//4467==dCI**40I9>>1  I$:$::NNi&E&EE;-s4&
;CSCSBTTU VWW([-=-=AWAW-W"m3tf,I+VWX  (*"#3#9>;OPP}Btf,EkF\F\E]]ghqh|h|g}}~ ; -Tr   is_same_main_modulec                 h   UR                   R                  5        Vs/ s H5  nUR                  [        R                  [        R
                  4;  d  M3  UPM7     nnU R                   R                  5        Vs/ s H5  nUR                  [        R                  [        R
                  4;  d  M3  UPM7     n	n[        S U 5       5      n
[        S U	 5       5      nU
(       d&  [        U5      [        U	5      :  a  [        U S35      eSn[        U5       GH  u  pUS:X  a	  U(       d  M  X-   [        U	5      :  a  UR                  [        R                  :X  a  MF  UR                  [        R                  :X  a   UR                  [        R                  :w  a  M  UR                  [        R                  :X  a  M  [        U SUR                   S35      eUR                  [        R                  :X  a    g XU-      nUR                  [        R                  :X  a  US-  nUR                  [        R                  :X  a%  U
(       d  [        U SUR                   S35      eGML  UR                  UR                  :w  a  UR                  [        R                  :X  a  UR                  [        R                  :X  dZ  UR                  [        R                  :X  a  U(       d5  [        U SUR                   S	UR                   S
UR                   S35      eUR                  U;   d
  U(       d  GM  [!        UR#                  UR                  S 5      UR#                  UR                  S 5      5      (       a  GM^  [        SU SUR                   SUR$                   SUR$                   S3	5      e   g s  snf s  snf )Nc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr!   rL   r   r^   rN   s     r   rQ   <ensure_all_positional_args_defined_in_sub.<locals>.<genexpr>   s!      4Hq)***4HrS   c              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr!   rp   rN   s     r   rQ   rq      s!      4Jq)***4JrS   z: parameter list too shortr   rT   z8` positionally required in subclass but not in supertyper   z` must be presentrU   z
` and is `rV   rW   z$ overriding must be a supertype of `rX   )rZ   r[   rL   r   rd   rM   rY   lenr   r\   r^   r_   defaultemptyre   ri   r   getrf   )r=   r?   r>   r@   rH   rm   rA   vsub_parameter_valuessuper_parameter_valuessub_has_var_argssuper_has_var_argssuper_shiftrc   rl   rj   s                   r   r;   r;      sc    ##**,,A66)00)2G2GHH 	
,   %%,,..A66)00)2G2GHH 	
.  
  4H   4J  $8 9C@V<W W;-'ABCCK%&:;A:3#&<"==~~!9!99)";";;%%8~~!@!@@-s9>>"22jk  >>Y555,[-@Ay7771Ky777#;-s;3C3C2DDU VWW	.  I$=$==NNi&E&EE^^y'@'@@EW-s9>>"2*[=M=M<NjYbYgYgXhhij   004G4G  !1!148y~~t4
 
 K=9>>"22VWbWmWmVnnx  zC  zN  zN  yO  OP  Q U <'
s   2N*N*72N/-N/ri   rz   rg   rj   c                    XR                   ;   =(       d    UR                  [        R                  :H  =(       a    U=(       d    UR                  [        R                  :H  =(       a    U=(       d    UR                  [        R
                  :H  =(       a    U=(       d\    UR                  [        R                  :H  =(       a    U=(       a    U=(       d&    UR                  [        R                  :H  =(       a    U$ r!   )rZ   rL   r   r^   rM   r_   re   rd   )ri   rz   rg   r?   rj   s        r   r`   r`      s     	""" 		O	 8 88M=M		O	 5 55L:L		O 	 9 99N>N		O
 	 ? ?? # #"		O 	 6 66M;Mr   c                    U R                   R                  5       n[        S U 5       5      n[        S U 5       5      n[        UR                   R	                  5       5       GHh  u  nu  pU	R
                  [        R                  :X  a;  [        U5      U:  a,  [        U5      U   R
                  [        R                  :X  a  Mb  XR                   ;  d  Ms  U	R                  [        R                  :X  d  M  U	R
                  [        R                  :w  d  M  U	R
                  [        R                  :w  d  M  U	R
                  [        R                  :X  a	  U(       a  M  U	R
                  [        R                  :X  a
  U(       a  GM"  U	R
                  [        R                  :X  a
  U(       a  GMJ  US:  d
  U(       d  GMZ  [!        U SU S35      e   g )Nc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr!   rp   rN   s     r   rQ   .ensure_no_extra_args_in_sub.<locals>.<genexpr>  s     R\9#;#;;\rS   c              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr!   rK   rN   s     r   rQ   r     s     QLq66Y%:%::LrS   r   rT   z` is not a valid parameter.)rZ   r[   rY   r\   r]   rL   r   r_   rs   ra   rt   ru   r^   rM   rd   re   r   )
r=   r?   rH   rA   super_paramssuper_var_argssuper_var_kwargsrk   ri   rl   s
             r   r<   r<   
  sL    ''..0LR\RRNQLQQ(1'2D2D2J2J2L(M$	$DNNi777L!I-\"9-22i6O6OO,,,!!Y__4)":"::)"7"77^^y'='==BRBR^^y'@'@@^^)"A"AAnnQ"7"7{m3tf4OPQQ' )Nr   c                     U R                  SS 5      nUR                  SS 5      n[        XC5      (       d  Ub  [        U SU SU S35      eg g )Nr   z: return type `z` is not a `z`.)rv   r   r   )r>   r@   rA   super_return
sub_returns        r   r9   r9   )  se     $''$7L##Hd3Jj//L4Lm?:,l<.PRS
 	
 5M/r   )F) r5   r   typesr   typingr   r   r   r   r	   r
   r   r   typing_utilsr   r   r   r   boolr   r   r%   r/   rC   r4   	Signaturestrr:   r;   r`   r<   r9    r   r   <module>r      s"      X X X -)|X7M1NO+5x9O3PQ $ ,$ ~ / d  2L"2L!2L 2L 
	2LjN ~ *  ** * 	*
  * *ZH  HH H 	H
  H H HV
  	
 "" 
*R  RR  R 	R
 
R>

,0
?B
r   