
    h,              
       r   S SK r S SKJrJr  S SKJ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  S SKJr  S SKJrJrJr  S S	KJr  S S
KJrJrJrJr  SrSrSr S\!4S jr" " S S\5      r#S\S\4S jr$S\S\4S jr%S\S\S\S\S\4
S jr&S\S\S\S\S\4
S jr'\" SSS5      r(\" S S!S5      r) " S" S#\5      r*g)$    N)DictList)TypeChecker)	ErrorCode)Errors)CallExpr	Decorator
ExpressionFuncDefMypyFileNameExpr)Options)CheckerPluginInterfaceFunctionContextPlugin)
is_subtype)CallableTypeInstanceTypeTypeVarTypezthinc.model.Modelzthinc.types.XY_YZ_OutTzthinc.types.XY_XY_OutTversionc                     [         $ N)ThincPlugin)r   s    D/home/james-whalen/.local/lib/python3.13/site-packages/thinc/mypy.pypluginr      s        c                   B   ^  \ rS rSrS\SS4U 4S jjrS\4S jrSrU =r	$ )	r      optionsreturnNc                 $   > [         TU ]  U5        g r   )super__init__)selfr    	__class__s     r   r$   ThincPlugin.__init__   s    !r   fullnamec                     [         $ r   )function_hook)r%   r(   s     r   get_function_hookThincPlugin.get_function_hook   s    r    )
__name__
__module____qualname____firstlineno__r   r$   strr+   __static_attributes____classcell__r&   s   @r   r   r      s'    " "D "#  r   r   ctxr!   c                 R     [        U 5      $ ! [         a    U R                  s $ f = fr   )get_reducers_typeAssertionErrordefault_return_type)r6   s    r   r*   r*      s-    ' %% '&&&'s   
 &&c           	         [        U R                  [        5      (       d   e[        U R                  [        5      (       d   e[        U R
                  [        5      (       d   eU R
                  R                  n[        U[        5      (       d   eUR                  n[        U[        [        45      (       d   eUR                  n[        U[        5      (       d   eUR                  n[        U[        5      (       d   eUR                  R                  [         :X  d   eUR"                  (       d   e[%        UR"                  5      S:X  d   eUR"                  S   n[        U[&        5      (       d   eUR                  (       d   eUR                  [(        [*        1;  a  U R                  $ [-        [.        R0                  " U R"                  6 5      n/ n[.        R0                  " U R2                  6  Hf  n[        U[        5      (       d   eUR                  R                  [         :X  d   e[%        UR"                  5      S:X  d   eUR5                  U5        Mh     [-        [7        USS USS 5      5      n	[-        [7        USS USS 5      5      n
UR                  [*        :X  a  [7        X5       H  u  u  pu  p[        U[        5      (       d   e[        U[        5      (       d   eUR                  R                  [         :X  d   eUR                  R                  [         :X  d   e[9        XXU R                  S9  M     [	        U R                  R                  US   R"                  S   US   R"                  S   /5      $ UR                  [(        :X  a  [7        X5       H  u  u  pu  p[        U[        5      (       d   e[        U[        5      (       d   eUR                  R                  [         :X  d   eUR                  R                  [         :X  d   e[;        XXU R                  S9  M     [	        U R                  R                  US   R"                  S   US   R"                  S   /5      $  S5       e)a  
Determine a more specific model type for functions that combine models.

This function operates on function *calls*. It analyzes each function call
by looking at the function definition and the arguments passed as part of
the function call, then determines a more specific return type for the
function call.

This method accepts a `FunctionContext` as part of the Mypy plugin
interface. This function context provides easy access to:
* `args`: List of "actual arguments" filling each "formal argument" of the
  called function. "Actual arguments" are those passed to the function
  as part of the function call. "Formal arguments" are the parameters
  defined by the function definition. The same actual argument may serve
  to fill multiple formal arguments. In some cases the relationship may
  even be ambiguous. For example, calling `range(*args)`, the actual
  argument `*args` may fill the `start`, `stop` or `step` formal
  arguments, depending on the length of the list.

  The `args` list is of length `num_formals`, with each element
  corresponding to a formal argument. Each value in the `args` list is a
  list of actual arguments which may fill the formal argument. For
  example, in the function call `range(*args, num)`, `num` may fill the
  `start`, `end` or `step` formal arguments depending on the length of
  `args`, so type-checking needs to consider all of these possibilities.
* `arg_types`: Type annotation (or inferred type) of each argument. Like
  `args`, this value is a list of lists with an outer list entry for each
  formal argument and an inner list entry for each possible actual
  argument for the formal argument.
* `arg_kinds`: "Kind" of argument passed to the function call. Argument
  kinds include positional, star (`*args`), named (`x=y`) and star2
  (`**kwargs`) arguments (among others). Like `args`, this value is a list
  of lists.
* `context`: AST node representing the function call with all available
  type information. Notable attributes include:
  * `args` and `arg_kinds`: Simple list of actual arguments, not mapped to
    formal arguments.
  * `callee`: AST node representing the function being called. Typically
    this is a `NameExpr`. To resolve this node to the function definition
    it references, accessing `callee.node` will usually return either a
    `FuncDef` or `Decorator` node.
* etc.

This function infers a more specific type for model-combining functions by
making certain assumptions about how the function operates based on the
order of its formal arguments and its return type.

If the return type is `Model[InT, XY_YZ_OutT]`, the output of each
argument is expected to be used as the input to the next argument. It's
therefore necessary to check that the output type of each model is
compatible with the input type of the following model. The combined model
has the type `Model[InT, OutT]`, where `InT` is the input type of the
first model and `OutT` is the output type of the last model.

If the return type is `Model[InT, XY_XY_OutT]`, all model arguments
receive input of the same type and are expected to produce output of the
same type. It's therefore necessary to check that all models have the same
input types and the same output types. The combined model has the type
`Model[InT, OutT]`, where `InT` is the input type of all model arguments
and `OutT` is the output type of all model arguments.

Raises:
    AssertionError: Raised if a more specific model type couldn't be
        determined, indicating that the default general return type should
        be used.
      Nl1_argl1_typel2_argl2_typeapir   z;Thinc mypy plugin error: it should return before this point)
isinstancerD   r   r:   r   contextr   calleer   noder   r	   typer   ret_typer(   thinc_model_fullnameargslenr   intoin_outtoout_out_fullnamechained_out_fullnamelist	itertoolschain	arg_typesappendzipcheck_chainedcheck_intoin_outtoout)r6   rG   callee_nodecallee_node_typecallee_return_typeout_typerL   rS   arg_type	arg_pairsarg_types_pairsarg1arg2type1type2s                  r   r8   r8   &   s   J cgg{++++c--x8888 ckk8,,,,[[Ffh''''++KkGY#78888"''&5555
 *22((3333""++/CCCC""""!&&'1,,, "&&q)H
 h,,,,!=?S TT&&& 	*+DIOOS]]3(H----}}%%)====8==!Q&&&" 4 ScrDH-.I3y"~y}=>O 00 -0	,K(LT.5eX....eX....::&&*>>>>::&&*>>>>4CGG -L ##((9Q<+<+<Q+?2ASASTUAV*W
 	
 
		:	: -0	,K(LT.5eX....eX....::&&*>>>>::&&*>>>>!4CGG -L ##((9Q<+<+<Q+?1ARARSTAU*V
 	

 POO5r   r@   rA   rB   rC   rD   c                 4   [        UR                  S   UR                  S   5      (       dm  UR                  SUR                  S    SUR                  S    S3U [        S9  UR                  SUR                  S    SUR                  S    S	3U[        S9  g g )
Nr=   r   zLayer outputs type (z) but the next layer expects (z) as an inputcodezLayer input type (z!) is not compatible with output (z) from previous layer)r   rL   failerror_layer_outputerror_layer_inputr?   s        r   rV   rV      s     gll1ow||A77"7<<?"33QRYR^R^_`RaQbbop# 	 	

 	 a 11RSZS_S_`aSbRccxy" 	 	
 8r   c                 6   UR                   S   UR                   S   :w  al  UR                  SUR                   S    SUR                   S    S3U [        S9  UR                  SUR                   S    SUR                   S    S3U[        S9  UR                   S   UR                   S   :w  am  UR                  SUR                   S    S	UR                   S    S3U [        S9  UR                  SUR                   S    S
UR                   S    S3U[        S9  g g )Nr   zLayer input (z() not compatible with next layer input ()rd   z,) not compatible with previous layer input (r=   zLayer output (z)) not compatible with next layer output (z-) not compatible with previous layer output ()rL   rf   rh   rg   r?   s        r   rW   rW      sG    ||A',,q/)GLLO,,TU\UaUabcUdTeefg" 	 	

 	GLLO,,XY`YeYefgYhXiijk" 	 	

 ||A',,q/)W\\!_--VW^WcWcdeWfVgghi# 	 	

 	W\\!_--Z[b[g[ghi[jZkklm# 	 	
 *r   zlayer-mismatch-inputzInvalid layer inputThinczlayer-mismatch-outputzInvalid layer outputc                   \   ^  \ rS rSrS\S\\\4   S\S\S\S\	S\\
\
4   4U 4S	 jjrS
rU =r$ )IntrospectChecker   errorsmodulesr    treepathr   per_line_checking_time_nsc           	      8   > / U l         [        TU ]	  XX4XVU5        g r   )_error_messagesr#   r$   )	r%   ro   rp   r    rq   rr   r   rs   r&   s	           r   r$   IntrospectChecker.__init__   s$     +-WD:S	
r   )ru   )r.   r/   r0   r1   r   r   r2   r   r   r   intr$   r3   r4   r5   s   @r   rm   rm      sb    

 c8m$
 	

 
 
 
 $(S>
 
r   rm   )+rQ   typingr   r   mypy.checkerr   mypy.errorcodesr   mypy.errorsr   
mypy.nodesr   r	   r
   r   r   r   mypy.optionsr   mypy.pluginr   r   r   mypy.subtypesr   
mypy.typesr   r   r   r   rK   rO   rN   r2   r   r   r*   r8   rV   rW   rh   rg   rm   r-   r   r   <module>r      s     $ %  S S   G G $ @ @* / 7 C & ' '4 'ZP? ZPt ZPz

 
 	

 
 
 
*

 
 	

 
 
 
@ 46KWU 68NPWX 
 
r   