
    ?g	.                     4   d dl Z d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZ  e
deeef         Z e
d	eeef         Zd
e	defdZd Zdee   fdZdededefdZ	 d(dedededdfdZdedefdZde j2                  de j2                  dedededefdZde j2                  de j2                  dededededefd Zd!ed"ed#ede j2                  d$e j                  defd%Zde j2                  de j2                  dededdf
d&Zdededefd'Zy))    N)	Parameter)FunctionType)CallableDictOptionalTupleTypeTypeVarUnionget_type_hints   )get_args	issubtype_WrappedMethod)bound_WrappedMethod2treturnc                 `    t        | t              ryt        |       D ]  }t        |      s y y)a_  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     H/var/www/openai/venv/lib/python3.12/site-packages/overrides/signature.pyr   r      s1     !W {$S)      c                 p    t        |       ry|yt        |      ry	 t        | |      S # t        $ r Y yw xY w)NT)r   r   	TypeError)leftrights     r   
_issubtyper   "   sD     &} 'u%% s   ) 	55c                 D    	 t        |       S # t        t        f$ r Y y w xY wN)r   	NameErrorr   callables    r   _get_type_hintsr%   0   s)    h''y! s   
 	callable1	callable2c                     | j                   j                  d      d   }t        |dd       }|y|j                  d      d   }||k(  S )N.r   
__module__F)r*   splitgetattr)r&   r'   mod1mod2s       r   _is_same_moduler/   7   sQ    %%c*1-D 9lD1D|::c?1D4<r   super_callablesub_callable	is_staticc           	         t        |       } t        |      }	 t        j                  |       }t	        |       }t        j                  |      }t	        |      }|j
                  }t        ||       }|0|.t        |||       t        ||||||       t        |||||||       t        ||||       y# t        $ r Y yw xY w)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(w 0.)[	
 	2	
  	7I{K1  s   B1 1	B=<B=r$   c                 N    t        | d      rt        | d      r| j                  S | S )N__self____func__)hasattrrF   r#   s    r   r4   r4   w   s&    x$:)F   Or   r=   r?   r>   r@   check_first_parameterrA   c                 >   t        d |j                  j                         D              }t        | j                  j	                               D ]  \  }\  }}	|dk(  r|s|	j
                  t        j                  k(  r0|	j
                  t        j                  k(  rNt        |d|||	      st        | d| d      ||j                  v s}|	j
                  t        j                  k7  st        |j                  j                               j                  |      }
|j                  |   }|	j
                  |j
                  k7  rX|	j
                  t        j                  k(  r|j
                  t        j                   k(  st        | d| d|	j
                   d      ||
kD  r1|	j
                  t        j                  k7  rt        | d| d| d      ||v s||v st#        ||   ||         rt        d| d	| d
|	j$                   d|j$                   d	       y )Nc              3   V   K   | ]!  }|j                   t        j                  k(   # y wr!   kindr   VAR_KEYWORD.0ps     r   	<genexpr>z3ensure_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((dK!$9y777y888&$*G[
 {m3tf4EFGGW'''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y([-=-=AWAW-W"m3tf,I+VWX  ((N*"#3D#9>$;OP}Btf,EkF\F\E]]ghqh|h|g}}~ ; -Tr   is_same_main_modulec                    |j                   j                         D cg c]0  }|j                  t        j                  t        j
                  fvr|2 }}| j                   j                         D cg c]0  }|j                  t        j                  t        j
                  fvr|2 }	}t        d |D              }
t        d |	D              }|
s%t        |      t        |	      k  rt        | d      d}t        |      D ]e  \  }}|dk(  r|s||z   t        |	      k\  r|j                  t        j                  k(  r>|j                  t        j                  k(  r|j                  t        j                  k7  ry|j                  t        j                  k(  rt        | d|j                   d      |j                  t        j                  k(  r y |	||z      }|j                  t        j                  k(  r|dz  }|j                  t        j                  k(  r|
st        | d|j                   d      7|j                  |j                  k7  r|j                  t        j                  k(  r|j                  t        j                  k(  sT|j                  t        j                  k(  r|s5t        | d|j                   d	|j                   d
|j                   d      |j                  |v s|st!        |j#                  |j                  d       |j#                  |j                  d             r2t        d| d|j                   d|j$                   d|j$                   d	       y c c}w c c}w )Nc              3   V   K   | ]!  }|j                   t        j                  k(   # y wr!   rL   r   r]   rN   s     r   rQ   z<ensure_all_positional_args_defined_in_sub.<locals>.<genexpr>   s$      4Hq)***4HrR   c              3   V   K   | ]!  }|j                   t        j                  k(   # y wr!   ro   rN   s     r   rQ   z<ensure_all_positional_args_defined_in_sub.<locals>.<genexpr>   s$      4Jq)***4JrR   z: parameter list too shortr   rS   z8` positionally required in subclass but not in supertyper   z` must be presentrT   z
` and is `rU   rV   z$ overriding must be a supertype of `rW   )rY   rZ   rL   r   rc   rM   rX   lenr   r[   r]   r^   defaultemptyrd   rh   r   getre   )r=   r?   r>   r@   rH   rl   rA   vsub_parameter_valuessuper_parameter_valuessub_has_var_argssuper_has_var_argssuper_shiftrb   rk   ri   s                   r   r;   r;      sa    ##**,,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%&:;yA:3;#&<"==~~!9!99)";";;%%8~~!@!@@-s9>>"22jk  >>Y555,U[-@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04G  !1!148y~~t4
 K=9>>"22VWbWmWmVnnx  zC  zN  zN  yO  OP  Q U <'
s   5M)05M.rh   rx   rf   ri   c                    | |j                   v xs |j                  t        j                  k(  xr |xs |j                  t        j                  k(  xr |xsk |j                  t        j
                  k(  xr |xsH |j                  t        j                  k(  xr |xr |xs! |j                  t        j                  k(  xr |S r!   )rY   rL   r   r]   rM   r^   rd   rc   )rh   rx   rf   r?   ri   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                 P   | j                   j                         }t        d |D              }t        d |D              }t        |j                   j	                               D ]A  \  }\  }}	|	j
                  t        j                  k(  r8t        |      |kD  r*t        |      |   j
                  t        j                  k(  r_|| j                   vsn|	j                  t        j                  k(  s|	j
                  t        j                  k7  s|	j
                  t        j                  k7  s|	j
                  t        j                  k(  r|r|	j
                  t        j                  k(  r|r	|	j
                  t        j                  k(  r|r*|dkD  s|s3t!        | d| d       y )Nc              3   V   K   | ]!  }|j                   t        j                  k(   # y wr!   ro   rN   s     r   rQ   z.ensure_no_extra_args_in_sub.<locals>.<genexpr>  s      R\9#;#;;\rR   c              3   V   K   | ]!  }|j                   t        j                  k(   # y wr!   rK   rN   s     r   rQ   z.ensure_no_extra_args_in_sub.<locals>.<genexpr>  s      QLq166Y%:%::LrR   r   rS   z` is not a valid parameter.)rY   rZ   rX   r[   r\   rL   r   r^   rq   r`   rr   rs   r]   rM   rc   rd   r   )
r=   r?   rH   rA   super_paramssuper_var_argssuper_var_kwargsrj   rh   rk   s
             r   r<   r<   
  sF    ''..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'='==BR^^y'@'@@^)"A"AAnQ"7{m3tf4OPQQ' )Nr   c                     | j                  dd       }|j                  dd       }t        ||      s|t        | d| d| d      y y )Nr   z: return type `z` is not a `z`.)rt   r   r   )r>   r@   rA   super_return
sub_returns        r   r9   r9   )  sd     $''$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   