
    *e@                   |   U d Z ddlmZ ddlZddlZddlZddlZddlZddl	Zddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl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mZm Z m!Z!m"Z" dd	lm#Z#m$Z$ ddl%Z&ddl'Z&ddl(Z&ddl)Z&ddl*Z&ddl+Z&dd
l&m,Z, ddl-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8  G d d          Z9 e9            Z:de;d<    e!d          Z<e"e<e9f         Z=de;d<    G d d          Z> e>            Z?de;d<    e5ej@        ejA        d          ZBde;d<   dd ZCdd#ZD G d$ d%eE          ZF G d& d'          ZGdd*ZHdd,ZIedd3            ZJdd7ZKdd9ZLeJM                    e,jN                  dd;            ZOdd>ZPddAZQeJM                    e,jR                  ddC            ZSddDZTddHZUddNZVddOZWddSZX G dT dUee<                   ZYddXZZeJM                    e,j[                  ddZ            Z\eJM                    e9          dd[            Z]eJM                    e,j^                  dd]            Z_eJM                    e,j`                  dd_            ZaeJM                    e,jb                  dda            ZceJM                    e,jd                  ddc            ZeddeZfddgZgddhZhddlZieJM                    e,jj                  ddm            ZkeJM                    e,jl                  ddo            Zm enh dp          Zode;dq<    enh dr          Zpde;ds<   ddtZqdduZrddwZsddyZtdd}ZuddZvddZwi axde;d<   dddZyddZz	 dddZ{ddZ|ddZ} G d d          Z~ enh d          Zde;d<   dddZddZddZedk    r ej         e                       dS dS )ziTests for stubs.

Verify that various things in stubs are consistent with how things behave at runtime.

    )annotationsN)defaultdict)redirect_stderrredirect_stdout)singledispatch)Path)AbstractSetAnyGenericIteratorTypeVarUnion)
get_originis_typeddict)nodes)parse_config_file)UNKNOWNevaluate_expression)Options)FancyFormatterbytes_to_human_readable_repr	is_dunderplural_sc                      e Zd ZdZddZdS )MissingzGMarker object for things that are missing (from a stub or the runtime).returnstrc                    dS )NMISSING selfs    -lib/python3.11/site-packages/mypy/stubtest.py__repr__zMissing.__repr__1   s    y    Nr   r   __name__
__module____qualname____doc__r$   r    r%   r#   r   r   .   s.        QQ     r%   r   ztyping_extensions.Finalr   Tztyping_extensions.TypeAliasMaybeMissingc                      e Zd ZdZddZdS )Unrepresentablez5Marker object for unrepresentable parameter defaults.r   r   c                    dS )N<unrepresentable>r    r!   s    r#   r$   zUnrepresentable.__repr__>   s    ""r%   Nr&   r'   r    r%   r#   r/   r/   ;   s.        ??# # # # # #r%   r/   UNREPRESENTABLEF
_formattermessager   kwargsr
   r   c                R    |                     dd           t          j        | fi |S )z.Wrapper around mypy.util for fancy formatting.colornone)
setdefaultr3   style)r4   r5   s     r#   _styler;   H   s1    
gv&&&G..v...r%   lengthintc                L    t          |           |k    r| d |dz
           dz   S | S )N   ...)len)r4   r<   s     r#   	_truncaterB   N   s0    
7||f|!|$u,,Nr%   c                      e Zd ZdS )StubtestFailureNr(   r)   r*   r    r%   r#   rD   rD   T   s        Dr%   rD   c                  8    e Zd ZdddddZddZddZdddZdS )ErrorN	stub_descruntime_descobject_path	list[str]r4   r   stub_objectMaybeMissing[nodes.Node]runtime_objectMaybeMissing[Any]rI   
str | NonerJ   r   Nonec                  || _         d                    |          | _        || _        || _        || _        |pt          t          |d|                    | _        |qt          |          }|$t          t          |          d          | _        dS t          j        |          }t          ||          }	t          |	d          | _        dS || _        dS )a  Represents an error found by stubtest.

        :param object_path: Location of the object with the error,
            e.g. ``["module", "Class", "method"]``
        :param message: Error message
        :param stub_object: The mypy node representing the stub
        :param runtime_object: Actual object obtained from the runtime
        :param stub_desc: Specialised description for the stub object, should you wish
        :param runtime_desc: Specialised description for the runtime object, should you wish

        .typeNd   is_async)rK   joinobject_descr4   rM   rO   r   getattrrI   safe_inspect_signaturerB   reprrJ   inspectiscoroutinefunctiondescribe_runtime_callable)
r"   rK   r4   rM   rO   rI   rJ   runtime_sigruntime_is_asyncdescriptions
             r#   __init__zError.__init__Y   s    * '88K00&,"Tc'+v{*S*S&T&T0@@K"$-d>.B.BC$H$H!!!#*#>~#N#N 7N^___$-k3$?$?!!! ,Dr%   boolc                6    t          | j        t                    S )z@Whether or not the error is for something missing from the stub.)
isinstancerM   r   r!   s    r#   is_missing_stubzError.is_missing_stub   s    $*G444r%   c                    d| j         v S )zOWhether or not the error is for something being (or not being) positional-only.zleading double underscore)r4   r!   s    r#   is_positional_only_relatedz Error.is_positional_only_related   s     +dl::r%   Fconcisec                   |r!t          | j        d          dz   | j        z   S d}d}t          | j        t
                    s| j        j        }t          | j        d                   }|	|j	        pd}d}|r|dt          |           z  }|r||rdnd	 | z  }d}d}t          | j        t
                    si	 t          j        | j                  d
         }n# t          t          t           f$ r Y nw xY w	 t          j        | j                  }n# t          $ r Y nw xY wd}|r|dt          |           z  }|r||rdnd	 | z  }t          ddd          t          | j        d          d| j        ddt          |d          dt          | j        dz   dd          dt          |d          dt          | j        dz   dd          g}	d                    |	          S )zxReturns a description of the error.

        :param concise: Whether to return a concise, one-line description

        T)bold Nr    z	 in file :z	 at line    zerror: redr7   rm   
zStub:)dimblue)r7   ru   zRuntime:)r;   rZ   r4   rg   rM   r   lineget_stubrK   pathr   rO   r^   getsourcelinesOSError	TypeErrorSyntaxErrorgetsourcefilerI   rJ   rY   )
r"   rk   	stub_line	stub_file	stub_nodestub_loc_strruntime_lineruntime_fileruntime_loc_stroutputs
             r#   get_descriptionzError.get_description   sh     	L$*666<t|KK		$*G44 	.(-IT-a011	 !.$I 	:9Y999L 	Ni@ss[M)MMML$-w77 	&5d6IJJ1MY4   &4T5HII     	@?4+=+=???O 	W"F##;VVVVO 9E5554#$///L<T***4>D(DAAA?---4$t+6tDDD
 wwvs$   :C C43C48D 
DD)rK   rL   r4   r   rM   rN   rO   rP   rI   rQ   rJ   rQ   r   rR   )r   re   F)rk   re   r   r   )r(   r)   r*   rd   rh   rj   r   r    r%   r#   rG   rG   X   s|         !%#'%- %- %- %- %- %-N5 5 5 5; ; ; ;
8 8 8 8 8 8 8r%   rG   module_nametypes.ModuleTypec           	        t          t          j        d          5 }t          j                    5  t          |          5  t          |          5  t          j        d           t          j	        |           }t          | dg           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |S )Nwignore*)fromlist)openosdevnullwarningscatch_warningsr   r   simplefilter	importlibimport_module
__import__)r   r   runtimes      r#   silent_import_moduler      s   	bj#		 4'$&& 	4 	4(@(@ 	4 	4/RYBZBZ 	4 	4!(+++-k::G {cU3333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 Ns{   CCB-;B	
B-BB-BB-!C-B11C4B15C8CC	CC	CC"CIterator[Error]c              #    K   t          |           }|ut          |                     d          d                   sK| t          j        v rt          t          j        |                    nd}t          | gdt          d|          V  dS 	 t          |           }np# t          $ r  t          $ rY}d}t          |t                    rd}t          | gd	| d
t          |          j         d| |t                    V  Y d}~dS d}~ww xY wt          j                    5  t          j        d           	 t%          ||| g          E d{V  n# t&          $ r}t)          t+          j        |j                            d         d         }|j                            dd          }|dk    s|                    d          d         dk    r t          | gdt          |          j         d| ||ddt+          j                                                    z             V  Y d}~nd}~ww xY wddd           dS # 1 swxY w Y   dS )zTests a given module's stub against introspecting it at runtime.

    Requires the stub to have been built already, accomplished by a call to ``build_stubs``.

    :param module_name: The module to test

    NrT   N/Azfailed to find stubsrJ   ro   z7 Maybe install the runtime package or alter PYTHONPATH?zfailed to import.rn   : r   r   r(   __main__mypyzencountered unexpected error, zThis is most likely the fault of something very dynamic in your library. It's also possible this is a bug in stubtest.
If in doubt, please open an issue at https://github.com/python/mypy

rH   )rx   is_probably_privatesplitsysmodulesr]   rG   r   r   KeyboardInterruptBaseExceptionrg   ModuleNotFoundErrorrU   r(   r   r   r   verify	Exceptionlist	tracebackwalk_tb__traceback__	f_globalsget
format_excstrip)r   stubrJ   r   enotebottom_framebottom_modules           r#   test_moduler      s      K  D|";#4#4S#9#9"#=>> 	=HCK=W=W4K 8999]bL5wS_      	&{33      a,-- 	MLDMMtMMd1gg6FMM!MMtU\
 
 	
 	
 	
 	 
	 	"	"  h'''	dGk];;;;;;;;;; 	 	 		 1!/ B BCCBGJL(266z2FFM 
**m.A.A#.F.Fq.IV.S.SHa1AHHQHHJ  *,,22445          		                 sV   
B D.ADDH93EH9
H)C	H$H9$H))H99H= H=r   rN   r   rP   rK   rL   c              #  2   K   t          |d| |          V  dS )zEntry point for comparing a stub to a runtime object.

    We use single dispatch based on the type of ``stub``.

    :param stub: The mypy node representing a part of the stub
    :param runtime: The runtime object corresponding to ``stub``

    zis an unknown mypy nodeNrG   r   r   rK   s      r#   r   r     s)       6g
F
FFFFFFr%   nodes.MypyFileruntime_all_as_setset[str]c           	   #    K   d|j         v sJ d |j                                         D             }t          ||z
            }t          ||z
            }|s|sd S t          | dgz   dt          t          d| d|           V  d S )N__all__c                &    h | ]\  }}|j         |S r    )module_public).0mos      r#   	<setcomp>z)_verify_exported_names.<locals>.<setcomp>!  s#    PPP$!QPAPPPr%   znames exported from the stub do not correspond to the names exported at runtime. This is probably due to things being missing from the stub or an inaccurate `__all__` in the stubz/Names exported in the stub but not at runtime: z/Names exported at runtime but not in the stub: )rM   rO   rI   rJ   )namesitemssortedrG   r   )rK   r   r   public_names_in_stubnames_in_stub_not_runtimenames_in_runtime_not_stubs         r#   _verify_exported_namesr     s       
""""PP$**:*:*<*<PPP &';>P'P Q Q &'9<P'P Q Q% )B 
yk!p ]B[]] ^B[]]!       r%   frozenset[str] | Nonec                `   	 t          j        |           }n# t          t          t          f$ r Y dS w xY w|                                st                      S 	 t          j        || j        d          }n# t          $ r Y dS w xY wt          d |	                                D                       S )a  Retrieve the names in the global namespace which are known to be imported.

    1). Use inspect to retrieve the source code of the module
    2). Use symtable to parse the source and retrieve names that are known to be imported
        from other modules.

    If either of the above steps fails, return `None`.

    Note that if a set of names is returned,
    it won't include names imported via `from foo import *` imports.
    Nexecc              3  f   K   | ],}|                                 |                                V  -d S N)is_importedget_name)r   syms     r#   	<genexpr>z-_get_imported_symbol_names.<locals>.<genexpr>V  s<      bbPSP_P_PaPabS\\^^bbbbbbr%   )
r^   	getsourcer{   r|   r}   r   	frozensetsymtabler(   get_symbols)r   sourcemodule_symtables      r#   _get_imported_symbol_namesr   ;  s    "7++Y,   tt <<>>  {{"+FG4DfMM   tt bb/J/J/L/Lbbbbbbs    22A4 4
BBMaybeMissing[types.ModuleType]c              #    	
K   t          t                    rt          |d|           V  d S t          t          j                  st          |d|           V  d S t          d          r5t          j                  }d| j        v rt          || |          E d {V  nd }fd| j        
                                D             }t                    
d
fd	||n	fdt                    D             }|                    |           |                    t                     t!          |          D ]}|| j        v r| j        |         j        nt$          }t          |t&          j                  r?|J 	 t+          |t$                    }n# t,          $ r Y gw xY wt/          ||||gz             E d {V  d S )Nis not present at runtimezis not a moduler   c                f    h | ]-\  }}|j         t          |          rt          |          +|.S r    )module_hiddenr   hasattr)r   r   r   r   s      r#   r   z"verify_mypyfile.<locals>.<setcomp>p  s^       Aq )<A(>(> CJ'STBUBU	  r%   rr   attrr   r   re   c                   t          | |          }t          |t          j                  rdS t	          |          rF	 |j        }t          |t                    rt          || j        k              S n# t          $ r Y nw xY w|vS dS )zFHeuristics to determine whether a name originates from another module.FNT)
r[   rg   types
ModuleTypecallabler)   r   re   r(   r   )r   r   objobj_modimported_symbolss       r#   _belongs_to_runtimez,verify_mypyfile.<locals>._belongs_to_runtimex  s    ac5+,, 	5C== 		77. gs++ 71: 56667    
 '///ts   A3 3
B ?B c                J    h | ]}t          |           |          | S r    )r   )r   r   r   r   s     r#   r   z"verify_mypyfile.<locals>.<setcomp>  sN     
 
 
&q))
 $#GQ//

 
 
r%   )r   r   r   r   r   re   )rg   r   rG   r   r   r   setr   r   r   r   r   dirupdatedifference_updateIGNORED_MODULE_DUNDERSr   noder   r   MypyFiler[   r   r   )r   r   rK   r   to_checkruntime_public_contentsentry
stub_entryruntime_entryr   r   s    `       @@r#   verify_mypyfiler   Y  sw      '7## K!<dGLLLLLgu/00 K!2D'BBBBB w	"" " 11
"" .k4ASTTTTTTTTT!   J$$&&  H 2'::     * ) 	
 
 
 
 
\\
 
 
  OO+,,,5666!! L L/4
/B/BTZ&++
j%.11 	%%%	#GUG<<MM 	 	 	 H	 *m[E75JKKKKKKKKKKL Ls   F
F('F(nodes.TypeInfo	type[Any]c           
   #    K   	  G d d|          }n_# t           $ rG | j        s=t          |t          j                  s#t          |d| |t          |                     V  Y nt          $ r Y nw xY w	 t          |dd          }n# t          $ r d}Y nw xY w|r,| j        s't          |d| |t          |                     V  d S d S d S )Nc                      e Zd ZdS )_verify_final.<locals>.SubClassNrE   r    r%   r#   SubClassr    s        Dr%   r  zIcannot be subclassed at runtime, but isn't marked with @final in the stubrI   	__final__FzChas `__final__` attribute, but isn't marked with @final in the stub)	r|   is_final
issubclassenumEnumrG   r]   r   r[   )r   r   rK   r  runtime_finals        r#   _verify_finalr
    sj     	 	 	 	 	w 	 	 	 	  	 	 	} 	Z%C%C 	[t**          	e<<     
T] 
Q4jj
 
 
 	
 	
 	
 	
 	

 
 
 
s(    AA/#	A/.A/3B BBis_runtime_typeddictre   c             #  l  K   | j         s| j        s|st          |          }|t          ur!| j        t	          |d| |d|           V  d S |t          u r[| j        Vt
          j                            | j        d          s3t	          |d| || j        j        j         d          V  d S d S d S d S d S d S d S )Nz"is inconsistent, metaclass differsr   rH   )zabc.ABCMetazbuiltins.typezmetaclass mismatch)	is_protocolis_enumrU   metaclass_typerG   r   r   is_named_instancefullname)r   r   rK   r  runtime_metaclasss        r#   _verify_metaclassr    s;       DL 9M  MMD((T-@-H4 13        %%#/ J00#%E  0 $!05>@"       -      &%////r%   MaybeMissing[type[Any]]c           	   #  L  K   | j         r:t          |t                    s#t          |d| |t	          |                     V  d S t          |t                    r%t          |d| |t	          |                     V  d S t          |t
                    s%t          |d| |t	          |                     V  d S t          | ||          E d {V  | j        d uot          |          }t          | |||          E d {V  d | j
        D             }|                    d t          |          D                        | j        r|                    d           |r|                    d	           t          |          D ]"}                    d
          r4                    d
          sd| j                            d            }t)          fd| j        D             t,                    }|J 	 	 t/          ||          }n+# t0          $ r t3          j        ||t,                    }Y nw xY wn# t6          $ r Y w xY wt          |t                    r+t          |t8          j                  rt=          |d          st?          |||gz             E d {V  $d S )N;is marked as "@type_check_only", but also exists at runtimer  r   zis not a type)r  c                :    h | ]}|                                 |S r    )isidentifier)r   names     r#   r   z"verify_typeinfo.<locals>.<setcomp>  s)    CCCt/@/@/B/BCCCCr%   c              3  J   K   | ]}t          |          s|t          v|V  d S r   )r   IGNORABLE_CLASS_DUNDERS)r   r   s     r#   r   z"verify_typeinfo.<locals>.<genexpr>  sG        (;A(>(>CDLcCcCcCcCcCcCc r%   rd   __new_____c              3  N   K   | ]}|j         v |j                  j        V   d S r   )r   r   )r   tr   s     r#   r   z"verify_typeinfo.<locals>.<genexpr>/  s:      YYqQRQXHXHXqwu~2HXHXHXHXYYr%   Texclude_special) is_type_check_onlyrg   r   rG   r]   rU   r
  typeddict_typer   r  r   r   varsr  discardr   
startswithendswithr  lstripnextmror   r[   AttributeErrorr^   getattr_staticr   r   WrapperDescriptorTyper   r   )	r   r   rK   r  r   mangled_entrystub_to_verifyruntime_attrr   s	           @r#   verify_typeinfor2    s}        '7++ 	Mt**      	'7## K!<dGW[\`WaWabbbbbbgt$$ K$4PT::VVVVVVT7K888888888.d:T|G?T?T g{9M          DCCCCHOO  ==       %$$$ $###!! S SD!! 	?%..*>*> 	?>	 0 0 5 5>u>>MYYYYDHYYY[bcc)))	W&w>>! W W W&5g}gVVW 	 	 	 H	 ~w//	S<)DEE	S ->>>	S
 nlK5'<QRRRRRRRRR1S Ss0   :H
H7%H30H72H33H77
IIc                    t          j        | d                   }| dd          D ]1}	 t          j        ||          }# t          $ r t
          cY c S w xY w|S )Nr   rq   )r   r   r^   r-  r,  r   )rK   static_runtimer   s      r#   _static_lookup_runtimer5  F  sx    ,[^<<NQRR  	$3NEJJNN 	 	 	 NNNNN		
 s   >AAnodes.FuncBaser4  Iterator[str]c              #    K   | j         dv rd S t          j        |          r@t          t	          |dd           t
                    }|r| j        sdV  |s| j        rdV  d S |t          u rd S t          |t                    r| j        sdV  t          |t                    s| j        rdV  t          |t                    r| j
        sdV  t          |t                    s| j
        rdV  d S d S d S )N)r  __init_subclass____class_getitem____self__z(runtime is a classmethod but stub is notz(stub is a classmethod but runtime is notz)runtime is a staticmethod but stub is notz)stub is a staticmethod but runtime is not)r  r^   	isbuiltinrg   r[   rU   is_classr   classmethodstaticmethod	is_static)r   r   r4  rK   probably_class_methods        r#   _verify_static_class_methodsrB  S  sQ      yIII!!  !+77J+M+Mt T T  	= 	=<<<<$ 	= 	=<<<<  .+.. 9t} 98888nk22 9t} 98888.,// : :9999nl33 : :999999: : : :r%   stub_argnodes.Argumentruntime_arginspect.Parameterfunction_namec              #  H  K   t          |d          rdS dd} || j        j        d	          |j        k    rdS dd}|j        t          j        j        k    r || j        j        |j                  rdS | j        j        dk    rdS d| j        j         d|j         dV  dS )z$Checks whether argument names match.Tr!  Nsr   prefixr   c                ^    |                      |          r| t          |          d          n| S r   )r'  rA   )rI  rJ  s     r#   strip_prefixz&_verify_arg_name.<locals>.strip_prefixx  s-    #$<<#7#7>qVQ>r%   r  abre   c                    |                      d          } |                     d          }|                     |          p:|                    |           p%t          |           dk    pt          |          dk    S )Nr  rq   )r   r'  rA   )rM  rN  s     r#   names_approx_matchz,_verify_arg_name.<locals>.names_approx_match~  s]    GGCLLGGCLL||AO!,,q//OSVVq[OCFFaKOr%   _selfstub argument "z!" differs from runtime argument "")rI  r   rJ  r   r   r   )rM  r   rN  r   r   re   )r   variabler  kindr^   	ParameterPOSITIONAL_ONLY)rC  rE  rG  rL  rP  s        r#   _verify_arg_namerX  p  s     
 555 ? ? ? ? |H%*D11[5EEEP P P P 7,<<<ASAS 0B B< 	((	>(+0 	> 	>*5*:	> 	> 	>    r%   c              #  *  K   |j         t          j        j        k    rH| j                                        rd|j         dV  dS t          |j                   }| j        j	        p| j
        }t          |t          j        j                  r|j        }|J|Ht          |j                   t           k    r+|j         dur"t#          ||          sd|j         d| d| V  | j        vt'          | j                  }|t(          ur[|durY|j         t*          urM||j         k    s#t          |          t          |j                   ur!d|j         d|j         d|V  dS dS dS dS dS dS | j                                        rd	| j        j         d
V  dS dS )z6Checks whether argument default values are compatible.runtime argument "z0" has a default value but stub argument does notN.z" has a default value of type z0, which is incompatible with stub argument type z" has a default value of z0, which is different from stub argument default rR  z3" has a default value but runtime argument does not)defaultr^   rV  emptyrU  is_requiredr  get_mypy_type_of_runtime_valuerT  rU   type_annotationrg   r   r   TypeVarTypeupper_boundobjectis_subtype_helperinitializerr   r   r2   is_optional)rC  rE  runtime_type	stub_typestub_defaults        r#   _verify_arg_default_valueri    sn      g/555=$$&& -	A[%5 A A A    
 :+:MNNL
 !).J(2JI)TZ%;<< 2%1	(),--77's22),	BB 3Q)9 Q Q3?Q QENQ Q  
 #/283GHH //$C//#+?BB$(;;;  --T+:M5N5NNNZ[-= Z Z2=2EZ ZIUZ Z     0/ 0///BB
 ON =$$&& 	1("3"8 1 1 1    	 	r%   r  argslist[nodes.Argument]c                R    |r$| dv r |d         j         j        dk    r
|dd          S |S )N)r9  r:  r   clsrq   rT  r  )r  rj  s     r#   maybe_strip_clsro    s>     BBB 7 E))8OKr%   c                  f    e Zd ZddZddZedd	            Zedd            Zedd            ZdS )	Signaturer   rR   c                >    g | _         i | _        d | _        d | _        d S r   )poskwonlyvarposvarkwr!   s    r#   rd   zSignature.__init__  s"    $& $#


r%   r   c                   dddddd	dfd
t          | j                                        fd          }d}|d                    fd| j        D             | j        rd | j                  z   gn| j        rdgng z   fd|D             z   | j        rd | j                  z   gng z             z  }|dz  }|S )Nargr
   r   r   c                    t          | t          j                  r| j        S t          | t          j                  r| j        j        S t          r   )rg   r^   rV  r  r   ArgumentrT  AssertionErrorrx  s    r#   r   z#Signature.__str__.<locals>.get_name  sC    #w011  x#u~.. )|((  r%   rQ   c                    t          | t          j                  rd S t          | t          j                  r t          | j        j        p| j                  S t          r   )
rg   r^   rV  r   rz  r   rT  rU   r_  r{  r|  s    r#   get_typez#Signature.__str__.<locals>.get_type  sR    #w011 t#u~.. E3<,C0CDDD  r%   re   c                    t          | t          j                  r't          | j        t          j        j        k              S t          | t          j                  r| j        	                                S t          r   )rg   r^   rV  re   r[  r\  r   rz  rU  re  r{  r|  s    r#   has_defaultz&Signature.__str__.<locals>.has_default  sa    #w011 DCK7+<+BBCCC#u~.. .x++---  r%   c                d     |           } |           |rd| ndz    |           rdndz   S )Nr   ro   z = ...r    )rx  arg_typer   r~  r  s     r#   get_descz#Signature.__str__.<locals>.get_desc  sR    x}}H&.6????B8*{3//788R9r%   c                0     |            |           fS r   r    )rM  r   r  s    r#   <lambda>z#Signature.__str__.<locals>.<lambda>  s    kk!nnhhWXkk=Z r%   keyzdef (z, c                &    g | ]} |          S r    r    r   rx  r  s     r#   
<listcomp>z%Signature.__str__.<locals>.<listcomp>  s!    ///sXXc]]///r%   r   c                &    g | ]} |          S r    r    r  s     r#   r  z%Signature.__str__.<locals>.<listcomp>  s!    000xx}}000r%   z**))rx  r
   r   r   )rx  r
   r   rQ   )rx  r
   r   re   )r   rt  valuesrY   rs  ru  rv  )r"   kw_onlyretr  r   r~  r  s      @@@@r#   __str__zSignature.__str__  s_   	! 	! 	! 	!	! 	! 	! 	!	! 	! 	! 	!	 	 	 	 	 	 	 	 ++--3Z3Z3Z3Z3Z[[[tyy////dh///04_hht{+++,,4;B^3%%\^a00000001 15
Bxx
+++,,D
 
 	
 	s

r%   r   nodes.FuncItemSignature[nodes.Argument]c                   t                      }t          | j        | j                  }|D ]}|j                                        r|j                            |           6|j                                        r||j	        |j
        j        <   d|j        t          j        k    r||_        |j        t          j        k    r||_        t           |S r   )rq  ro  r  	argumentsrU  is_positionalrs  appendis_namedrt  rT  r   ARG_STARru  	ARG_STAR2rv  r{  )r   stub_sig	stub_argsrC  s       r#   from_funcitemzSignature.from_funcitem  s    .7kk#DIt~>>	! 
	% 
	%H}**,, 	%##H----'')) %:B 1 677%.00"*%/11!)$$r%   	signatureinspect.SignatureSignature[inspect.Parameter]c                   t                      }| j                                        D ]}|j        t          j        j        t          j        j        fv r|j        	                    |           F|j        t          j        j
        k    r||j        |j        <   p|j        t          j        j        k    r||_        |j        t          j        j        k    r||_        t"          |S r   )rq  
parametersr  rU  r^   rV  rW  POSITIONAL_OR_KEYWORDrs  r  KEYWORD_ONLYrt  r  VAR_POSITIONALru  VAR_KEYWORDrv  r{  )r  ra   rE  s      r#   from_inspect_signaturez Signature.from_inspect_signature  s    4=KK$/6688 	% 	%K!1!7$   &&{3333!W%6%CCC7B";#344!W%6%EEE%0""!W%6%BBB$/!!$$r%   nodes.OverloadedFuncDefc           	         t           j        d          }i t          t           j                  D ]}|J t           j        |j                  }t          |          D ]b\  }}|j        j        	                    d          s|rd| n|j        j        }
                    |g                               ||f           cdfd	}dfd}d fd}	t                      }
t          |          D ]}|         d         d         j        j        }t          j        t          j        | ||                    dd |	|                    }|j                                        r|
j                            |           |j                                        r||
j        |j        j        <   |j        t          j        k    r||
_        |j        t          j        k    r||
_        t4          |
S )a  Returns a Signature from an OverloadedFuncDef.

        If life were simple, to verify_overloadedfuncdef, we'd just verify_funcitem for each of its
        items. Unfortunately, life isn't simple and overloads are pretty deceitful. So instead, we
        try and combine the overload's items into a single signature that is compatible with any
        lies it might try to tell.

        Tr!  Nr  arg_namer   r   r=   c                B    t          d |          D                       S )Nc              3      K   | ]	\  }}|V  
d S r   r    )r   r  indexs      r#   r   zISignature.from_overloadedfuncdef.<locals>.get_position.<locals>.<genexpr>F  s&      @@Eu@@@@@@r%   )max)r  all_argss    r#   get_positionz6Signature.from_overloadedfuncdef.<locals>.get_positionD  s%    @@Xh-?@@@@@@r%   mypy.types.ProperTypec                    t           j        j                            d          5  d |          D             }t           j                            d |D                       cd d d            S # 1 swxY w Y   d S )NTc                :    g | ]\  }}|j         j        p|j        S r    )rT  rU   r_  r   rx  r  s      r#   r  zFSignature.from_overloadedfuncdef.<locals>.get_type.<locals>.<listcomp>J  s6       AGaCL%<)<  r%   c                    g | ]}||S r    r    r   r   s     r#   r  zFSignature.from_overloadedfuncdef.<locals>.get_type.<locals>.<listcomp>M  s    :U:U:UST:U1:U:U:Ur%   )r   statestrict_optional_settypeopsmake_simplified_union)r  	all_typesr  s     r#   r~  z2Signature.from_overloadedfuncdef.<locals>.get_typeH  s    !55d;; W W KST\K]  	 |99:U:Ui:U:U:UVV	W W W W W W W W W W W W W W W W W Ws   ;A..A25A2nodes.ArgKindc                   d |          D             }t           j        |v rt           j        S t           j        |v rt           j        S t          |                    t          j                  k     pt           j        |v pt           j        |v }t           j        |v pt           j        |v }|r|rt           j        nt           j        S |rt           j        nt           j        S )Nc                "    h | ]\  }}|j         S r    )rU  r  s      r#   r   zESignature.from_overloadedfuncdef.<locals>.get_kind.<locals>.<setcomp>P  s    ???&#qSX???r%   )	r   r  r  rA   r   ARG_OPTARG_NAMED_OPTARG_POS	ARG_NAMED)r  kindsis_optis_posr  r   s       r#   get_kindz2Signature.from_overloadedfuncdef.<locals>.get_kindO  s    ??HX,>???E~&&~%%''&
 HX&''#dj//9 0=E)0&%/ 
 ]e+Eu}/EF H(.Gu}}E4GG$*?5==?r%   r  r   )r_  rd  rU  )r  r   r   r=   )r  r   r   r  )r  r   r   r  )r   r  map _resolve_funcitem_from_decoratorr   ro  r  	enumeraterT  r'  r9   r  rq  r   r   rz  VarrU  r  rs  r  rt  r  ru  r  rv  r{  )r   assume_positional_onlyfuncrj  r  rx  r  r  r~  r  sigr  example_arg_namer  s   `            @r#   from_overloadedfuncdefz Signature.from_overloadedfuncdef)  sr    "+49d!K!K!K@B8$*EE 	C 	CD###"49dn==D'oo C C
s
 |(33D99+=S+LLLL* 
 ##D"--44c5\BBBBC	A 	A 	A 	A 	A 	A	W 	W 	W 	W 	W 	W	@ 	@ 	@ 	@ 	@ 	@ 	@& *3x\::: 	% 	%H'1!4Q7@E.	*HHX,>,>?? $ Xh''	  C x%%'' 	%s####""$$ %03
3<,--U^++ 

U_,,		$$
r%   Nr   rR   r&   )r   r  r   r  )r  r  r   r  )r   r  r   r  )	r(   r)   r*   rd   r  r?  r  r  r  r    r%   r#   rq  rq    s        $ $ $ $' ' ' 'R    \     \$ L L L \L L Lr%   rq  r  r  c              #  
  K   t          | j        |j                  D ]$\  }}t          |||          E d {V  t          ||          E d {V  |j        t
          j        j        k    rt|j        sm|j	        j
                            d          sN|j	        j
                            d          dk    s+t          |d          sd|j	        j
         d|j
         dV  |j        t
          j        j        k    rI|j        s|j	        j
                            d          r#t          |d          sd|j	        j
         d	V  &t          | j                  t          |j                  k    r|j        | j        t          |j                  d          D ]H}|j	        j
        |j        vr!d
|j	        j
         d}|j        |dz  }|V  6d|j	        j
         dV  I| j        d| j        j	        j
         dV  nwt          | j                  t          |j                  k     rM|j        t          | j                  d          D ]+}|j
        | j        vrd|j
         dV  d|j
         dV  ,t          | j                  t          |j                  k    s|j        E| j        |j        d|j        j
         dV  | j        |j        d| j        j	        j
         dV  t%          t'          | j                  t'          |j                  z            D ]I}| j        |         |j        |         }}t          |||          E d {V  t          ||          E d {V  J|j        9t'          |j                                      t'          | j                            st%          t'          | j                  t'          |j                  z
            D ]S}|d |j        D             v r6|d |j        t          | j                  d          D             vrd| dV  Kd
| dV  Tt%          t'          |j                  t'          | j                  z
            D ]Z}|d | j        D             v r=|j        -|d | j        t          |j                  d          D             v sd| dV  Rd| dV  [| j        f|j        _d | j        D             }t'          |j                                      t'          | j                  |z            sd|j        j
         dV  | j         |j        d| j        j	        j
         dV  d S d S d S )Nr  r  r"   Tr!  rR  zN" should be positional-only (rename with a leading double underscore, i.e. "__z")zD" should be positional or keyword (remove leading double underscore)z runtime does not have argument "rS  z7. Maybe you forgot to make it keyword-only in the stub?z" is not keyword-onlyz&runtime does not have *args argument "zstub does not have argument "rZ  z#stub does not have *args argument "c                    h | ]	}|j         
S r    r  r   rE  s     r#   r   z$_verify_signature.<locals>.<setcomp>  s    GGGK{'GGGr%   c                    h | ]	}|j         
S r    r  r  s     r#   r   z$_verify_signature.<locals>.<setcomp>  s    ```K{/```r%   c                &    h | ]}|j         j        S r    rn  r   rC  s     r#   r   z$_verify_signature.<locals>.<setcomp>  s    CCCh8$)CCCr%   c                &    h | ]}|j         j        S r    rn  r  s     r#   r   z$_verify_signature.<locals>.<setcomp>  s    ```xH-2```r%   c                &    h | ]}|j         j        S r    rn  r  s     r#   r   z$_verify_signature.<locals>.<setcomp>  s    JJJX(+0JJJr%   z&stub does not have **kwargs argument "z)runtime does not have **kwargs argument ")ziprs  rX  ri  rU  r^   rV  rW  pos_onlyrT  r  r'  r   r   rA   ru  rt  rv  r   r   issubset)r   r   rG  rC  rE  msgrx  stub_pos_namess           r#   _verify_signaturer  y  sz      "%TXw{!;!;  +#Hk=IIIIIIIII,X{CCCCCCCCC 1 AAA% B%*55d;; B %*0055??mTBBB @Z("3"8 Z ZEPEUZ Z Z  
  1 AAA" B&.&7&<&G&G&M&M BmTBBB B
5("3"8 5 5 5   48}}s7;''''
 >! HS%5%5%7%78 	Z 	Z $)??VX=N=SVVVC}0XXIIIIYH,=,BYYYYYYY{&[t{?S?X[[[[[[	TXW[))	)	)";s48}}7 	S 	SKt{22Ik6FIIIIIIIR;+;RRRRRRR 48}}GK((((GN,B;7>#=N8KNNNNNN;"w~'=W4;;O;TWWWWWW c$+&&W^)<)<<== D D $C 0'.2E+#Hk=IIIIIIIII,X{CCCCCCCCCC }C$7$7$@$@T[AQAQ$R$R #dk**S-@-@@AA 	@ 	@CGG7;GGGGG``7;sSWS[}}C_`````IsIIIIII????????c'.))C,<,<<== 	9 	9CC$(CCCCC &``48CPWP[L\L\L^L^C_`````BBBBBBB8#8888888 zgm7 KJJJJ7>""++C,<,<~,MNN 	QP7=;MPPPPPPz'-"7U$*:M:RUUUUUUUU "7"7r%   r  c              #    K   t          |t                    rt          |d| |          V  d S t          |          s%t          |d| |          V  t	          |          sd S t          |          }t          | t          j                  rOt          | |          D ]}t          ||| |          V  t          | ||          D ]}t          ||| |          V  t          | |||          D ]}t          |d|z   | |          V  t          |          }t          j        |          }|rUt                              |           }t                              |          }	t#          ||          }
t%          |          }nd\  }
}|r| j        st          |d| |||
          V  |sd S t)          ||	| j                  D ]}t          |d|z   | ||
	          V  d S )
Nr   is not a functionis inconsistent, rW   )NNz:is an "async def" function at runtime, but not in the stubrH   rG  r   )rg   r   rG   is_probably_a_functionr   r5  r   FuncDef_verify_abstract_status_verify_final_methodrB  r\   r^   r_   rq  r  r  r`   r   is_coroutiner  r  )r   r   rK   r4  
error_textr4   r  runtime_is_coroutiner  ra   runtime_sig_descrI   s               r#   verify_funcitemr    s      '7## K!<dGLLLLL!'** K!4dGDDDDD   	F ,K88N$&& @1$@@ 	@ 	@JZw??????.tWnMM 	@ 	@JZw??????/g~{[[ O OK!4w!>gNNNNNN&w//I"6w?? 1**40066yAA4YI]^^^MM		&0#)
  
D$5 
H)
 
 
 	
 	
 	
  $X{$)TTT 
 
'))
 
 
 	
 	
 	
 	

 
r%   c              #  2   K   t          |d| |          V  d S )Nzis not present in stubr   r   s      r#   verify_noner     s)       5tW
E
EEEEEEr%   	nodes.Varc              #  $  K   t          |t                    r)t          |          dk    rt          |d| |          V  d S | j        r1t          |          r"| j        s| j        st          |d| |          V  t          |          }|| j	        {t          || j	                  shd}t          |t          j                  r-t          |j                  }|t          || j	                  rd}|rt          |d| | |          V  d S d S d S d S d S )N   r   +is read-only at runtime but not in the stubTFz#variable differs from runtime type )rg   r   rA   rG   is_initialized_in_classis_read_only_propertyis_settable_propertyis_propertyr^  rU   rc  r  r  value)r   r   rK   rf  should_errors        r#   
verify_varr  '  s      '7## {q  %@$PPPPP 	$_!'**_ &_ /3.>_
 K!NPTV]^^^^^1'::L I!!,	:: "  gty)) 	%9'-HHL',=lDI,V,V'$ 	Q<QQSWY`       	! !!!!	 	r%   r  c              #    K   t          |t                    rt          |d| |          V  d S | j        r%t	          |          rt          |d| |          V  d S t          |          s%t          |d| |          V  t          |          sd S | j        d         }t          |t          j	                  r3|j
        r,t          |j        |          D ]}t          ||| |          V  t          |          }t          | |||          D ]}t          |d|z   | |          V  t          |          }|sd S t                               |           }t                               |          }	t'          ||	| j                  D ]M}d|v r|dz  }t          |d|z   | |t+          | j                  d	| z   d
t+          |          z             V  Nd S )Nr   r  r  r   r  r  zhas a default value of typezc. This is often caused by overloads failing to account for explicitly passing in the default value.z
Inferred signature: def rH   )rg   r   rG   r  r  r  r   r   r   	Decoratoris_overloadr  r  r5  rB  r\   rq  r  r  r  r  r   rU   )
r   r   rK   
first_partr  r4  r4   r  r  ra   s
             r#   verify_overloadedfuncdefr  L  sR     
 '7## K!<dGLLLLL  )) 	c%RTXZabbbbb!'** K!4dGDDDDD   	F AJ*eo.. 9:3I 9*:?GDD 	9 	9CS$888888 ,K88N/g~{[[ O OK!4w!>gNNNNNN
 'w//I //55H229==K$X{$)TTT 
 
(G33(G ')49~~)L()L)LL#i..0
 
 
 	
 	
 	
 	

 
r%   nodes.TypeVarExprc              #     K   t          |t                    r#| j        dk    rd S t          |d| |          V  d S t          |t                    st          |d| |          V  d S d S )N_NTr   zis not a TypeVar)rg   r   r  rG   r   r   s      r#   verify_typevarexprr    s       '7##  9FK!<dGLLLLLgw'' K!3T7CCCCC r%   nodes.ParamSpecExprc              #  :  K   t          |t                    rt          |d| |          V  d S t          t          dd           t          t
          dd           f}t          d |D                       }|rt          ||          st          |d| |          V  d S d S )Nr   	ParamSpecc              3     K   | ]}||V  	d S r   r    r  s     r#   r   z'verify_paramspecexpr.<locals>.<genexpr>  s"      NN!ANNr%   zis not a ParamSpec)rg   r   rG   r[   typingtyping_extensionstuple)r   r   rK   maybe_paramspec_typesparamspec_typess        r#   verify_paramspecexprr    s       '7## K!<dGLLLLLT**!;55 NN'<NNNNNO *Wo"F"F K!5tWEEEEE r%   nodes.Decoratorc              #    K   | j         j        sJ t          |t                    r(t	          | j         |j        t                    E d {V  d S t          j        |          rd S t          |          }t          | j         j
        t          j        j                  r| j         j
        j        nd }||t          ||          rd S dV  d S )NzGis inconsistent, cannot reconcile @property on stub with runtime object)r  r  rg   propertyr  fgetr   r^   isdatadescriptorr^  rU   r   r   CallableTyperet_typerc  )r   r   rf  	func_types       r#   _verify_readonly_propertyr    s      9    '8$$ '	7<IIIIIIIII((  2'::L#-dindj>U#V#V`	\`  	 !lI66 " 	
SSSSSSr%   nodes.FuncDefc              #     K   | j         t          j        k    }t          |dd          }|r|s| j        rdnd}d| dV  d S d S d S )N__isabstractmethod__Fr  methodzis inconsistent, runtime z is abstract but stub is not)abstract_statusr   IS_ABSTRACTr[   r  )r   r   stub_abstractruntime_abstract	item_types        r#   r  r    s      (E,==Mw(>FF R R"&"2@JJ	Q)QQQQQQQQR R R Rr%   c              #     K   | j         rd S t          |dd          s|t          urt          |dd          rdV  d S d S d S )Nr  Fz8is decorated with @final at runtime, but not in the stub)r  r[   r   )r   r   r4  s      r#   r  r    sh       } wU++ Ig%%'.+u*U*U%HHHHHH 	&%%%r%   decnodes.OverloadPartnodes.FuncItem | Nonec                     t           t          j                  r S  j        j        rdS d	 fd} j        } j        D ]} |||          }| dS |}|S )
zReturns a FuncItem that corresponds to the output of the decorator.

    Returns None if we can't figure out what that would be. For convenience, this function also
    accepts FuncItems.
    N	decoratornodes.Expressionr  r  r   r"  c                r   t          | t          j                  r>t          | j        t          j                  r| j        j        t          j        j        v r|S t          | t          j                  sd S | j        sd S | j        dv s0| j        t          j        j	        v s| j        t          j        j
        v r|S | j        dk    rr|j        d         j        j        dvr/t          d|j        d         j        j        dj                   t          j        |          }|j        dd          |_        |S d S )N)zbuiltins.staticmethodzabc.abstractmethodzbuiltins.classmethodr   )rm  mcsmetaclszunexpected class argument name z in rq   )rg   r   CallExprcalleeRefExprr  r   r   DEPRECATED_TYPE_NAMESOVERLOAD_NAMESFINAL_DECORATOR_NAMESr  rT  r  rD   copy)r$  r  r  r   s      r#   apply_decorator_to_funcitemzE_resolve_funcitem_from_decorator.<locals>.apply_decorator_to_funcitem  sD    y%.11	9+U];;	  )TZ-MMMK)U]33 	4! 	4"QQQ!TZ%>>>!TZ%EEEK!777~a ).6OOO%)dnQ6G6P6U ) ),) )  
 )D//CM!""-CMJ tr%   )r$  r%  r  r  r   r"  )rg   r   FuncItemr  r  original_decorators)r   r0  r  r$  resulting_funcs   `    r#   r  r    s     #u~&& 

x t! ! ! ! ! !F 8D,  	44YEE!44Kr%   c           	   #    K   | j         j        r:t          |t                    s#t	          |d| |t          |                     V  d S t          |t                    rt	          |d| |          V  d S | j         j        rUt          | |          D ]}t	          ||| |          V  t          | j         |          D ]}t	          ||| |          V  d S t          |           }|t          |||          E d {V  d S d S )Nr  r  r   )r  r#  rg   r   rG   r]   r  r  r  r  r   )r   r   rK   r4   r  s        r#   verify_decoratorr5    s]      y#  '7++ 	Mt**      	'7## K!<dGLLLLLy 0w?? 	= 	=GWdG<<<<<<.ty'BB 	= 	=GWdG<<<<<<+D11D$55555555555 r%   nodes.TypeAliasc           	   #    K   t           j                            | j                  }d| }t	          |t
                    rt          |d| ||          V  d S t          |          p|}t	          |t           j        j                  rt	          |t                    st          |d| ||          V  d S |j	        }	 |j
        }n&# t          $ r t          |dt                    }Y nw xY wt	          |t                    rut          |dt                    }t	          |t                    rJ|dk    s
|dk    r|d	v rd
}| d| }	t          j        dt          j        |j                   |	          rd S t'          |||          E d {V  d S t	          |t           j        j                  rX|t*          urMt,          j        dk    rt	          |t          j                  s#t          |d| |t          |                    V  d S t	          |t           j        j                  r0t2          t          |dd          vrt          |d| ||          V  d S t	          |t           j        j                  r+|t6          j        j        urt          |d| ||          V  d S t	          |t           j        j                  rd S t          |d| ||          V  d S )NzType alias for r   r  z&is inconsistent, runtime is not a typer(   r)   zcollections.abcre>   MatchPatternr  rT   z_?r?   
   zis not a Union__mro__r    zis not a subclass of tuplez is not a type alias for Callablezis not a recognised type alias)r   r   get_proper_typetargetrg   r   rG   r   InstancerU   r*   r,  r[   r   r   r8  	fullmatchescaper  r   	UnionTyper   r   version_info	TupleTyper	  r  collectionsabcCallableAnyType)
r   r   rK   stub_targetrI   runtime_originstub_originruntime_nameruntime_moduleruntime_fullnames
             r#   verify_typealiasrP  /  s_      *,,T[99K/+//I'7## K!<dGW`aaaaaa((3GN+tz233 ".$// 	8#      F!&	H)6LL 	H 	H 	H">:wGGLLL	HlC(( 
	%,^\7%S%SN.#.. !%666"d**|?S/S/S%-N&4#E#E|#E#E < Gbi0D&E&E G GIYZZ F
 +~{CCCCCCCCC+tz344 &&!W,,GU_1U1U,%5tWPST_P`P`aaaaaa+tz344 	2>>>>94T]      	+tz677 !999?wZc      	+tz122 
=tWXa
b
b
bbbbbbs   ?C  C*)C*>   r+   __file__r(   __path____spec__
__author__
__cached__
__loader____getattr____package____version____builtins____copyright____annotations____warningregistry__r   >&   __cmp____div__r+   __args____dict____hash__r  	__slots__
__origin__
__reduce__rW  __nonzero____setattr____unicode____weakref____ctype_be____ctype_le____getstate____setstate____reduce_ex____getnewargs____new_member____orig_bases____parameters____pyx_vtable__r\  __getinitargs____subclasshook____instancecheck____subclasscheck____protocol_attrs____text_signature____abstractmethods____dataclass_fields____dataclass_params____vectorcalloffset____ctypes_from_outparam____callable_proto_members_only__r  c                L    |                      d          ot          |            S )Nr  )r'  r   r  s    r#   r   r     s"    ??37	$$77r%   c                    t          | t          j        t          j        f          pHt          | t          j        t          j        f          p"t          j        |           ot          |           S r   )	rg   r   FunctionTypeBuiltinFunctionType
MethodTypeBuiltinMethodTyper^   ismethoddescriptorr   r   s    r#   r  r    s^    7U/1JKLL 	Gg 0%2IJKK	G&w//EHW4E4Er%   rb  c                >    t          | t                    o| j        d u S r   )rg   r  fsetr  s    r#   r  r    s    gx((AW\T-AAr%   inspect.Signature | Nonec                   	 	 t          j        |           S # t          $ r t          | d          rd| j        v r| j                            dd          }t          j        t           j        | |          }t          |t           j                  sJ d |j	        
                                D             }|                    |          cY S  w xY w# t          $ r Y d S w xY w)Nry  r1   r@   c                Z    g | ](}|j         d u r|                    t                    n|)S ).)r[  )r[  replacer2   )r   	parameters     r#   r  z*safe_inspect_signature.<locals>.<listcomp>  sQ        " !(C// %%o%>>>"  r%   )r  )r^   r  
ValueErrorr   ry  r  _signature_fromstrrq  rg   r  r  r   )r   r  
new_paramss      r#   r\   r\     s   	$W--- 	 	 	!566'7+EEE 0889LeTT01BGSQQ!#w'899999  &)^%:%:%<%<	  
 {{j{99999%	&    
 tts(    B3C
C CC 
CCr  r  rX   c                   |rdnd d|  S )Nzasync ro   r  r    )r  rX   s     r#   r`   r`     s    "*hh;;	;;;r%   leftmypy.types.Typerightc                   t           j                            |           } t           j                            |          }t          | t           j        j                  rEt          | j        t                    r+| j        dv r"t           j                            |d          rdS t          |t           j        j                  r"t           j                            | d          rdS t           j	        j	        
                    d          5  t           j                            | |          cddd           S # 1 swxY w Y   dS )z2Checks whether ``left`` is a subtype of ``right``.)r   rq   zbuiltins.boolTzbuiltins.dictN)r   r   r>  rg   LiteralTyper  r=   r  TypedDictTyper  r  subtypes
is_subtype)r  r  s     r#   rc  rc    sU   :%%d++DJ&&u--E4/00tz3'' J&  J((@@ ! t%122 tz7S7So8 8  t			-	-d	3	3 5 5}''e445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s    D55D9<D9mypy.types.Type | Nonec                >
   | t           j                                        S t          | t                    rdS ddt          | t          j        t          j        t          j        t          j        f          rt          d          }|J |j
        d         j        }t          |t          j                  sJ t           j                            |             g          }t          |           }|rg }g }g }|j                                        D ]}|                                            |                    |j        t(          j        j        k    rdn|j                   |j        t(          j        j        k    }	|j        t(          j        j        k    r.|                    |	rt          j        nt          j                   |j        t(          j        j        k    r/|                    |	rt          j        nt          j                   |j        t(          j        j        k    r/|                    |	rt          j        nt          j                   J|j        t(          j        j         k    r!|                    t          j!                   |j        t(          j        j"        k    r!|                    t          j#                   tH          n0                          g}t          j!        t          j#        g}ddg}t           j        %                    |||             |d          S t          tM          |           j'                  }
|
dS tM          |           j(        }||
j
        vrdS |
j
        |         j        }t          |t          j)                  r|j&        S t          |t          j                  sdS t          | tT                    rcd	 | D             }fd
|D             }t           j                            |             g          }t           j        +                    ||          S t           j                            |fd|j,        D                       }t          | tZ          j.                  r"t          | j        t^                    r| j        }nLt          | t`                    rtc          |           }n't          | td          tf          t^          f          r| }n|S t           j        4                    ||          S )zReturns a mypy type object representing the type of ``runtime``.

    Returns None if we can't find something that works.

    Nr   mypy.types.AnyTypec                 h    t           j                            t           j        j        j                  S r   )r   r   rI  	TypeOfAnyunannotatedr    r%   r#   anytypez/get_mypy_type_of_runtime_value.<locals>.anytype  s     z!!$*"6"BCCCr%   builtinsfunctionT)r  fallbackis_ellipsis_argsc                ,    g | ]}t          |          S r    )r^  )r   vs     r#   r  z2get_mypy_type_of_runtime_value.<locals>.<listcomp>^  s!    MMM8;;MMMr%   c                ,    g | ]}||n	             S r   r    )r   ir  s     r#   r  z2get_mypy_type_of_runtime_value.<locals>.<listcomp>_  s'    MMMq}!!''))MMMr%   c                $    g | ]}             S r    r    )r   r  r  s     r#   r  z2get_mypy_type_of_runtime_value.<locals>.<listcomp>c  s    .V.V.VQwwyy.V.V.Vr%   )r  r  )r   r  )5r   r   NoneTyperg   r  r  r  r  r  rx   r   r   r   TypeInfor@  r\   r  r  r  rU  r^   rV  rW  r  r[  r\  r  r  r  r  r  r  r  r  r  r  r{  r  rU   r)   r(   r  r	  rE  	type_varsr  r  r   bytesr   re   r=   r  )r   r  	type_infor  r  	arg_types	arg_kinds	arg_namesrx  r  r   	type_nameoptional_itemsr   r  r  s                  @r#   r^  r^    s    z""$$$'8$$ tD D D D 		U68H%Jab  ,
 J''###N:.3	)U^44444:&&y7799+>>*733	 	%III +2244 ) )  +++  H(9(IIIDDsx   "kW->-DD8w0@@@$$k%TU]]u}UUUUX!2!HHH$$k%TU]]u}UUUUX!2!???$$%\U__I\]]]]X!2!AAA$$U^4444X!2!>>>$$U_5555((#)& !GGII.I9ItIz&&WYY! ' 
 
 	
 DMM,--D|tW&I
""t
9%*I)UY'' ~i00 t'5!! 5MMWMMMMMMMnMMM:&&y7799+>>z##E8444z""9.V.V.V.V)BU.V.V.VWWH '49%% *W\3*G*G 	GU	#	# ,W55	GdC-	.	. :!!!AAAr%   zdict[str, nodes.MypyFile]
_all_stubsr   optionsr   find_submodulesc           	     T   t           j                                        }t           j                            g ||          }t           j                            |d|          }g g }| D ]1}                    |           |s`|                    |          }t          |t                    sE|                    t           j        
                    ||d                     z|                    |          }	|                    |	                               fd|	D                        	 t          |          }
                    fdt          j        |
j        |
j        dz             D                        # t$          $ r  t&          $ r Y /w xY w|r	 t           j                            ||          }n/# t           j        j        $ r}t-          d|           |d}~ww xY w|j        r*t-          dd	                    |j                  z             |j        aS )
a  Uses mypy to construct stub objects for the given modules.

    This sets global state that ``get_stub`` can access.

    Returns all modules we might want to check. If ``find_submodules`` is False, this is equal
    to ``modules``.

    :param modules: List of modules to build stubs for.
    :param options: Mypy options for finding and building stubs.
    :param find_submodules: Whether to attempt to find submodules of the given modules as well.

    N)fscacher  c              3  8   K   | ]}|j         v|j         V  d S r   module)r   rI  all_moduless     r#   r   zbuild_stubs.<locals>.<genexpr>  s2      ^^A!(R]B]B]qxB]B]B]B]^^r%   c              3  8   K   | ]}|j         v|j         V  d S r   r  )r   r   r  s     r#   r   zbuild_stubs.<locals>.<genexpr>  s>       # #v[00 F0000# #r%   rT   )sourcesr  zfailed mypy compile:
zmypy build errors:
rt   )r   builddefault_data_dirmodulefindercompute_search_pathsFindModuleCacher  find_modulerg   r   BuildSourcefind_modules_recursiveextendr   pkgutilwalk_packagesrR  r(   r   r   errorsCompileErrorrD   rY   filesr  )r   r  r  data_dirsearch_pathfind_module_cacher  r  module_pathfound_sourcesr   resr   r  s                @r#   build_stubsr  z  s|    z**,,H#88WhOOK)99T7 :   KG  6""" 	+77??Kk3// NN4,88fdSSTTTT-DDVLLMNN=)))^^^^^^^^^^
.v66"" # # # #$273CWEUX[E[\\# # #    
 %         		G*""7G"DDCC{' 	G 	G 	G!">1">">??QF	G: 	R!"8499SZ;P;P"PQQQ Y
s+   /AFFF!G G-G((G-r  nodes.MypyFile | Nonec                6    t                               |           S )z?Returns a stub object for the given module, if we've built one.)r  r   r  s    r#   rx   rx     s    >>&!!!r%   custom_typeshed_dirrQ   rD  tuple[int, int] | Nonec                8   t           j                            |           t          j        dd         dfd}| rt          |           }n.t          t           j                                                  d	z  }|d
z  }t                      }|	                    d          D ]r}|j
        dk    r|j        }d                    |                    |          j        dd         |j
        fz             } ||          r|                    |           s|S )zJReturns a list of stdlib modules in typeshed (for current Python version).Nr   r  r  r   r   re   c                    J |                      d          }t          t          |          dd          D ]@}d                    |d |                   }|v r|         \  }}|k    o	|d u p|k    c S AdS )NrT   r   r   F)r   rangerA   rY   )r  partsr  current_moduleminvermaxverstdlib_py_versionsrD  s         r#   exists_in_versionz6get_typeshed_stdlib_modules.<locals>.exists_in_version  s    '''S!!s5zz1b)) 	] 	]A XXeBQBi00N!333!3N!C#v-\6T>3[\U[E[\\\ 4 ur%   typeshedstdlibz*.pyird   rT   r   )r  r   r   re   )r   r  load_stdlib_py_versionsr   rD  r   r  r  r   rglobstemparentrY   relative_tor  add)	r  rD  r  typeshed_dir
stdlib_dirr   ry   r  r  s	    `      @r#   get_typeshed_stdlib_modulesr    s6    *BBCVWW'!,        H/00DJ7799::ZG(JG  ))    9
"";D$**:66<SbSATYLPQQV$$ 	 KKNr%   c                 &   t           j        dk    rt           j        } nt          t           j                  } t          t                    }t          j                    D ]K}t          |j	        t          j        j                  r%||j	                                     |j                   L|                                D ]<\  }}dt!          |j                  j        vrddh|z  r|                     |           =t                      }| D ]}|t(          v r	 t+          |          }|                    |           n# t,          $ r Y ?w xY w	 |j        }|j        }	n# t2          $ r Y _w xY wt          j        ||	dz             D ]}
|
j        }|                    d          s*|                    d          s|                    d          rI	 t+          |           |                    |           o# t:          $ r  t<          $ r Y w xY w|S )	z0Return all importable stdlib modules at runtime.r;  zsite-packages_queuequeuerT   z	.__main__zidlelib.ztest.)r   rD  stdlib_module_namesr   builtin_module_namesr   r  iter_modulesrg   module_finderr   	machinery
FileFinderr  r  r   r   ry   r  r   ANNOYING_STDLIB_MODULESr   ImportErrorrR  r(   r,  r  r(  r'  r   r   )all_stdlib_modulesmodules_by_finderr   findermodule_groupimportable_stdlib_modulesr   r   runtime_pathrM  	submodulesubmodule_names               r#   get_importable_stdlib_modulesr     s    7"" 4 !9::S^_bScSc%'' 	? 	?A!/9+>+IJJ ?!!/266qv>>>$5$;$;$=$= 	8 	8 FLtFK'8'8'>>> w',6 ? #)),777*-%%) 1> 1>111	7*;77G &))+6666  	 	 	H	
	"+L"+LL 	 	 	H	 !.|\C=OPP 	> 	>I&^N ''44!,,Z88 ",,W55
 
>$^444 *--n==== %    !   9	>B %$s6   D>>
E
EE
E+*E+G55HHallowlist_filec              #     K   dd}t          |           5 }|D ]} ||          }|r|V  	 d d d            d S # 1 swxY w Y   d S )NrI  r   r   c                    	 | d |                      d                                                   S # t          $ r |                                 cY S w xY w)N#)r  r   r  )rI  s    r#   strip_commentsz-get_allowlist_entries.<locals>.strip_comments.  s[    	^qwws||^$**,,, 	 	 	7799	s   .1 AA)rI  r   r   r   )r   )r  r  frw   r   s        r#   get_allowlist_entriesr  -  s          
n		  	 	D"N4((E 	                 s   ;??c                  ~    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   ded	<   d
ed<   d
ed<   ded<   d
ed<   dS )
_ArgumentsrL   r   re   rk   ignore_missing_stubignore_positional_only	allowlistgenerate_allowlistignore_unused_allowlistr   mypy_config_filer  check_typeshedversionN)r(   r)   r*   r\  r    r%   r#   r	  r	  ;  s         MMM    !!!!LLLLLr%   r	  >   thisr   antigravityr  use_builtins_fixturesc                ^   d | j         D             }d |D             }t                      }| j        }| j        re| j        r"t	          t          ddd          d           dS t          | j                  }t                      }t          ||z  t          z
            }|s"t	          t          ddd          d	           dS t                      }d
|_        | j        |_        |j        r)t          j                            | j                  |_        | j        |_        ||_        |j        r0dd}	t)          ||	|j        t*          j        t*          j                   	 t1          ||| j                   }n;# t2          $ r.}
t	          t          ddd          d|
            Y d}
~
dS d}
~
ww xY wd}d}|D ]}t5          |          D ]}| j        r|                                r| j        r|                                r:|j        |v rd||j        <   Nd
}|D ]+}||                              |j                  r	d||<   d} n,|rd}| j!        r|"                    |j                   t	          |#                    | j$                             |dz  }ӌ| j%        sA|D ]>}||         s4||                              d          sd}|dz  }t	          d|            ?| j!        r$t          |          D ]}t	          |           d}n| j$        s|rTt	          t          d| dtM          |           dtO          |           dtM          |           d	dd                     n?t	          t          dtO          |           dtM          |           dd                     |S )z.This is stubtest! It's time to test the stubs!c                8    i | ]}t          |          D ]}|d S r   )r  )r   r  r   s      r#   
<dictcomp>ztest_stubs.<locals>.<dictcomp>Q  sI       *>::   	u   r%   c                8    i | ]}|t          j        |          S r    )r8  compile)r   r   s     r#   r  ztest_stubs.<locals>.<dictcomp>V  s$    IIIe
5 1 1IIIr%   zerror:rr   Trs   z7cannot pass both --check-typeshed and a list of modulesrq   zno modules to checkFr   rR   c                     d S r   r    r    r%   r#   set_strict_flagsz$test_stubs.<locals>.set_strict_flagsu  s    Fr%   )r  znot checking stubs due to Nr   )rk   ro   znote: unused allowlist entry zFound z errorz
 (checked z moduler  zSuccess: no issues found in greenr  )(r  r   r   r  printr;   r  r  r   r   r  r   incrementalr   ry   abspathabs_custom_typeshed_dirr  config_filer  r   r   stdoutstderrr  rD   r   r
  rh   r  rj   rZ   rA  r  r  r   rk   r  r   rA   )rj  r  r  allowlist_regexesgenerated_allowlistr   typeshed_modulesruntime_modulesr  r  stubtest_failure	exit_codeerror_countr  erroris_allowlistedr   r   s                     r#   
test_stubsr-  M  s    "n  I
 JIyIII %%lG 	Y< 	xu4888I   16t7OPP799*_<@WWXX fXU6668MNNNqiiGG"&":G" T*,'//$:R*S*S'/G$9G! b	 	 	 	 	'#3W5H#*VYV`aaagwDDW@WXXX   85t444;)9;;	
 	
 	
 qqqqq IK   (( 	 	E' E,A,A,C,C * u/O/O/Q/Q  I--/3	%+,"N  $Q'11%2CDD #'IaL%)NE   I& #''(9:::%'''==>>>1KK1	6 ' ; 	; 	;A Q< ;(9!(<(F(Fr(J(J ;	q 9a99:::  +,, 	 	A!HHHH		\  	K[ K K0E0E K K!$WK K6>w6G6GK K K	      [3w<<[[QXHYHY[[!     s   E8 8
F0#F++F0c                   t          j        d          }|                    ddd           |                    ddd	
           |                    ddd
           |                    ddd
           |                    ddddg d           |                    dddd
           |                    dddd
           |                    ddd           |                    ddd            |                    d!dd"
           |                    d#d$d%t          j        j        z   &           |                    | t                      '          S )(Nz8Compares stubs to objects introspected from the runtime.)rc   r   r   zModules to test)nargshelpz	--concise
store_truez8Makes stubtest's output more concise, one line per error)actionr0  z--ignore-missing-stubzAIgnore errors for stub missing things that are present at runtimez--ignore-positional-onlyzLIgnore errors for whether an argument should or shouldn't be positional-onlyz--allowlistz--whitelistr  FILEzUse file as an allowlist. Can be passed multiple times to combine multiple allowlists. Allowlists can be created with --generate-allowlist. Allowlists support regular expressions.)r2  metavarr[  r0  z--generate-allowlistz--generate-whitelistz:Print an allowlist (to stdout) to be used with --allowlistz--ignore-unused-allowlistz--ignore-unused-whitelistzIgnore unused allowlist entriesz--mypy-config-filezFUse specified mypy config file to determine mypy plugins and mypy path)r4  r0  z--custom-typeshed-dirDIRzUse the custom typeshed in DIRz--check-typeshedz$Check all stdlib modules in typeshedz	--versionr  z	%(prog)s )r2  r  )	namespace)argparseArgumentParseradd_argumentr   r  rY  
parse_argsr	  )rj  parsers     r#   parse_optionsr<    s   $N  F 	3DEEE
G    
 P    
 "[    
 +     I	     ##.	     V    
 5U     <6\     I{T\=U/U     TZ\\:::r%   c                     t           j                            d           t          t	          t
          j        dd                              S )Nstubtestrq   )r   utilcheck_python_versionr-  r<  r   argvr    r%   r#   mainrB    s8    I"":...mCHQRRL11222r%   r   )r4   r   r5   r
   r   r   )r4   r   r<   r=   r   r   )r   r   r   r   )r   r   r   r   )r   rN   r   rP   rK   rL   r   r   )rK   rL   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   rK   rL   r   r   )r   r   r   r   rK   rL   r   r   )
r   r   r   r   rK   rL   r  re   r   r   )r   r   r   r  rK   rL   r   r   )rK   rL   r   rP   )
r   r6  r   r
   r4  rP   rK   rL   r   r7  )rC  rD  rE  rF  rG  r   r   r7  )rC  rD  rE  rF  r   r7  )r  r   rj  rk  r   rk  )r   r  r   r  rG  r   r   r7  )r   r  r   rP   rK   rL   r   r   )r   r   r   rP   rK   rL   r   r   )r   r  r   rP   rK   rL   r   r   )r   r  r   rP   rK   rL   r   r   )r   r  r   rP   rK   rL   r   r   )r   r  r   rP   rK   rL   r   r   )r   r  r   r
   r   r7  )r   r  r   r
   r   r7  )r   r  r   r
   r4  rP   r   r7  )r   r!  r   r"  )r   r  r   rP   rK   rL   r   r   )r   r6  r   rP   rK   rL   r   r   )r  r   r   re   )r   r
   r   re   )r   rb  r   re   )r   r
   r   r  )r  r  rX   re   r   r   )r  r  r  r  r   re   )r   r
   r   r  r   )r   rL   r  r   r  re   r   rL   )r  r   r   r  r   )r  rQ   rD  r  r   r   )r   r   )r  r   r   r7  )rj  r	  r  re   r   r=   )rj  rL   r   r	  )r   r=   )r+   
__future__r   r7  collections.abcrF  r/  r  r   importlib.machineryr^   r   r  r8  r   r   r   r   r  r  r   r   
contextlibr   r   	functoolsr   pathlibr   r	   r
   r   r   r   r   r   r   
mypy.buildr   mypy.modulefinder
mypy.nodes
mypy.state
mypy.typesmypy.versionr   mypy.config_parserr   mypy.evalexprr   r   mypy.optionsr   	mypy.utilr   r   r   r   r   r   r\  r,   r-   r/   r2   r"  r#  r3   r;   rB   r   rD   rG   r   r   r   r   r   registerr   r   r
  r  r  r2  r5  rB  rX  ri  ro  rq  r  r1  r  r  r  r  OverloadedFuncDefr  TypeVarExprr  ParamSpecExprr  r  r  r  r  r  r5  	TypeAliasrP  r   r   r  r   r  r  r\   r`   rc  r^  r  r  rx   r  r   r  r	  r  r-  r<  rB  r(   exitr    r%   r#   <module>rY     s	     # " " " " "                 				  				  



            # # # # # # 7 7 7 7 7 7 7 7 $ $ $ $ $ $       F F F F F F F F F F F F F F F F 6 6 6 6 6 6 6 6                               0 0 0 0 0 0 6 6 6 6 6 6 6 6             W W W W W W W W W W W W        $+799 , , , ,GCLL,1!W*,= = = = =# # # # # # # # ,;?+<+< < < < < '5nSZU&S&S
 S S S S/ / / /   	 	 	 	 	i 	 	 	i i i i i i i ib	 	 	 	5 5 5 5p G G G G   >c c c c<   NL NL NL ! NLb$
 $
 $
 $
N# # # #L   JS JS JS ! JSZ
 
 
 
: : : ::   B8 8 8 8v   a a a a a
 a a aHfV fV fV fVR   :
 :
 :
 ! :
z F F F F ! ! ! !H ())<
 <
 <
 *)<
~ "##   $# $%%   &% T T T T.R R R RI I I I4 4 4 4n !!6 6 6 "!6> !!Dc Dc Dc "!DcX 3<)  3 3     , 4=91 1 134 34  3 3 3 3l8 8 8 8   B B B B   >< < < <5 5 5 5.]B ]B ]B ]BJ )+
 * * * *: : : : :z" " " " MQ    DL% L% L% L%^           4=9=`=`=`3a3a  a a a au u u u up;; ;; ;; ;;|3 3 3 3
 zCHTTVV r%   