o
    2g                     @  s  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
mZ d dlmZ d dlZd dlmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d d	l'm(Z(m)Z) d d
l*m+Z+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 G dd de	j7Z8G dd de	j7Z9G dd de	j7Z:G dd de	j7Z;G dd de2Z<eddZ=G dd dZ>G dd de>Z?G dd de	j7Z@G dd  d e	j7ZAG d!d" d"e	j7ZBG d#d$ d$e	j7ZCd+d)d*ZDdS ),    )annotationsN)
ModuleType)Any)CompileError)InspectErrorModuleInspect)
ArgSigFunctionSigbuild_signaturefind_unique_signatures!infer_arg_sig_from_anon_docstringinfer_prop_type_from_docstringinfer_sig_from_docstringis_valid_typeparse_all_signaturesparse_signature)Optionscollect_build_targetsgenerate_stubsis_blacklisted_pathis_non_library_modulemypy_optionsparse_options)InspectionStubGeneratorinfer_c_method_args)	ClassInfocommon_dir_prefixinfer_method_ret_typeremove_misplaced_type_commentswalk_packages)DataDrivenTestCase	DataSuite)assert_equalassert_string_arrays_equallocal_sys_path_setc                      s   e Zd ZdZeejdkddddZeejdkdddd	Z	eejdkddd
dZ
dddddZdd fddZ  ZS )StubgenCmdLineSuitezATest cases for processing command-line options and finding files.win32clean up fails on WindowsreturnNonec              
   C  s  t  }t v}zft | t d | dd | dd t t jdd | ddd t	dg}t
|t|\}}}t|g  t|g  dd |D }t|t jdddt jddt jddh W t | nt | w W d    d S 1 sw   Y  d S )Nsubdira.pyb.pypack__init__.pyc                 S  s   h | ]}|j qS  )path.0modr/   r/   M/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/test/teststubgen.py	<setcomp>D   s    z7StubgenCmdLineSuite.test_files_found.<locals>.<setcomp>)osgetcwdtempfileTemporaryDirectorychdirmkdir	make_filer0   joinr   r   r   r"   selfcurrenttmpoptspy_modspyi_modsc_modsfilesr/   r/   r4   test_files_found5   s.   





	"z$StubgenCmdLineSuite.test_files_foundc              
   C  s   t  }t m}z]t | t d | jdddd | dd | dd tddg}t|t	|\}}}t
|g  t
|g  dd	 |D }t
|t jddt jddt jddh W t | nt | w W d    d S 1 sxw   Y  d S )
Nr-   r.   zfrom . import a, bcontentr+   r,   z-pc                 S  s   h | ]}t j|jpd qS )FAIL)r6   r0   relpathr1   r/   r/   r4   r5   ^   s    z:StubgenCmdLineSuite.test_packages_found.<locals>.<setcomp>)r6   r7   r8   r9   r:   r;   r<   r   r   r   r"   r0   r=   r>   r/   r/   r4   test_packages_foundP   s,   




	"z'StubgenCmdLineSuite.test_packages_foundc              
   C  s   t  }t }|t_t A}z-t | | j	|ddd t
ddg}t|t| | dks3J W tjt_t | n
tjt_t | w W d    d S 1 sSw   Y  d S )Nzmymodule.pyzimport arH   -mmymodule )r6   r7   ioStringIOsysstdoutr8   r9   r:   r<   r   r   r   getvalue
__stdout__)r?   r@   captured_outputrA   rB   r/   r/   r4   test_module_not_foundj   s   

"z)StubgenCmdLineSuite.test_module_not_foundrO   rH   r0   strrI   c                G  sF   t jj| }t|d}|| W d    d S 1 sw   Y  d S )Nw)r6   r0   r=   openwrite)r?   rI   r0   filefr/   r/   r4   r<   z   s   "zStubgenCmdLineSuite.make_fileNresult
Any | Nonec                   s6   t   t |W  d    S 1 sw   Y  d S N)r$   superrun)r?   r^   	__class__r/   r4   rb      s   
$zStubgenCmdLineSuite.runr(   r)   )r0   rX   rI   rX   r(   r)   r`   )r^   r_   r(   r_   )__name__
__module____qualname____doc__unittestskipIfrR   platformrG   rL   rW   r<   rb   __classcell__r/   r/   rc   r4   r%   2   s    r%   c                   @     e Zd ZdddZdS )StubgenCliParseSuiter(   r)   c                 C  s   t  5}ttt|dgdh ttt|ddgddh tt|dg}| |h d W d    d S 1 s;w   Y  d S )Nmypy.errorsmypy.stubgenmypy>   	mypy.testmypy.test.helpersrr   rp   rq   )r   r"   setr   
assertTrue
issuperset)r?   mall_mypy_packagesr/   r/   r4   test_walk_packages   s   "z'StubgenCliParseSuite.test_walk_packagesNre   )rf   rg   rh   rz   r/   r/   r/   r4   ro          ro   c                   @  s8  e Zd ZdZd@ddZd@ddZd@dd	Zd@d
dZd@ddZd@ddZ	d@ddZ
d@ddZdAddZd@ddZd@ddZd@ddZd@d d!Zd@d"d#Zd@d$d%Zd@d&d'Zd@d(d)Zd@d*d+Zd@d,d-Zd@d.d/Zd@d0d1Zd@d2d3Zd@d4d5Zd@d6d7Zeejd8kd9d@d:d;Z eejd8kd<d@d=d>Z!d?S )BStubgenUtilSuitez)Unit tests for stubgen utility functions.r(   r)   c                 C  s   |  ddg g f d S )Nzfunc()funcassert_parse_signaturer?   r/   r/   r4   test_parse_signature   s   z%StubgenUtilSuite.test_parse_signaturec                 C  s.   |  dddgg f |  ddddgg f d S )Nz	func(arg)r}   argzdo(arg, arg2)doarg2r~   r   r/   r/   r4   test_parse_signature_with_args   s   z/StubgenUtilSuite.test_parse_signature_with_argsc                 C  D   |  ddg dgf |  dddgdgf |  ddg ddgf d S )Nzfunc([arg])r}   r   zfunc(arg[, arg2])r   zfunc([arg[, arg2]])r~   r   r/   r/   r4   'test_parse_signature_with_optional_args      z8StubgenUtilSuite.test_parse_signature_with_optional_argsc                 C  r   )Nzfunc(arg=None)r}   r   zfunc(arg, arg2=None)r   zfunc(arg=1, arg2="")r~   r   r/   r/   r4   %test_parse_signature_with_default_arg   r   z6StubgenUtilSuite.test_parse_signature_with_default_argc                 C  s   |  dddgg f d S )NzClassName.func(arg)r}   r   r~   r   r/   r/   r4   ,test_parse_signature_with_qualified_function   s   z=StubgenUtilSuite.test_parse_signature_with_qualified_functionc                 C  s   |  ddddgdgf d S )NzClassName.func(arg, *, arg2=1)r}   r   *r   r~   r   r/   r/   r4   %test_parse_signature_with_kw_only_arg   s   z6StubgenUtilSuite.test_parse_signature_with_kw_only_argc                 C     |  ddddgg f d S )NzClassName.func(arg, *args)r}   r   *argsr~   r   r/   r/   r4   "test_parse_signature_with_star_arg      z3StubgenUtilSuite.test_parse_signature_with_star_argc                 C  r   )NzClassName.func(arg, **args)r}   r   z**argsr~   r   r/   r/   r4   'test_parse_signature_with_star_star_arg   r   z8StubgenUtilSuite.test_parse_signature_with_star_star_argsigrX   r^    tuple[str, list[str], list[str]]c                 C  s   t t|| d S r`   )r"   r   )r?   r   r^   r/   r/   r4   r      s   z'StubgenUtilSuite.assert_parse_signaturec                 C  sd   t tg g d t tdgg d t tddgg d t tdgdgd t tdgddgd d S )	N()r   (arg)r   (arg, arg2)z(arg, arg2=...)z**xz(arg, arg2=..., **x))r"   r
   r   r/   r/   r4   test_build_signature   s
   z%StubgenUtilSuite.test_build_signaturec                 C  s   t tg dddgg f d S )N)zrandom textz.. function:: fn(argz.. function:: fn()z  .. method:: fn2(arg))fnr   )fn2r   )r"   r   r   r/   r/   r4   test_parse_all_signatures   s   
z*StubgenUtilSuite.test_parse_all_signaturesc                 C  s   t tg dddg d S )N)r}   r   r   )func2r   )r   r   func3r   r   r   )r"   r   r   r/   r/   r4   test_find_unique_signatures   s   	z,StubgenUtilSuite.test_find_unique_signaturesc              	   C  s8  t tddtdtddgddg t tddtdtddgddg t tddtdtddtd	d
dgddg t tddtdtddtd	d
dgddg t tddtdtddtd	d
dgddg t tddg  t tddg  t tddtdtdd
dgddg t tddg  t tddtdtdddgddg t tddtdtddd
dgddg t tddtdtdd d
dgddg t tddtdg ddg t tddtdtddd
dgddg t tddtdtddd
dgddg t tddtdtdddgddg t tddtdtdddtd ddgddg t td!dtdtdd"dgddg t td#dtdtdd$d
dgddg t td%dtdtddd
dgddg t td&dg  t td'dtdtdd dgddg t td(dtdtddd
dgddg d S ))Nz
func(x) - yr}   xnamer   r   argsret_typez
func(x)z
func(x, Y_a=None)Y_aT)r   defaultz
func(x, Y_a=3)z
func(x, Y_a=[1, 2, 3])z
afunc(x) - yz

func(x, yz
func(x=z(y))z
func xz
func(x: int)intr   typez
func(x: int=3)r   r   r   z

func(x=3)z
func() -> intz
func(x: int=3) -> intz
func(x: int=3) -> int   
z 
func(x: Tuple[int, str]) -> strzTuple[int,str]rX   z9
func(x: Tuple[int, Tuple[str, int], str], y: int) -> strTuple[int,Tuple[str,int],str]yz
func(x: foo.bar)foo.barz
func(x: list=[1,2,[3,4]])listz
func(x: str="nasty[")z
func[(x: foo.bar, invalid]z&
func(x: invalid::type<with_template>)z
func(x: str="")r"   r   r	   r   r   r/   r/   r4   test_infer_sig_from_docstring   s   					

		z.StubgenUtilSuite.test_infer_sig_from_docstringc                 C  s0   t tddtdtddtddgddg d S )Nz$
func(x, x) -> str
func(x, y) -> intr}   r   r   r   r   r   r   r   r/   r/   r4   ,test_infer_sig_from_docstring_duplicate_args~  s   z=StubgenUtilSuite.test_infer_sig_from_docstring_duplicate_argsc                 C  s   t tddd  d S )Nz:
            x
              x
             x
            r}   )r"   r   r   r/   r/   r4   -test_infer_sig_from_docstring_bad_indentation  s   z>StubgenUtilSuite.test_infer_sig_from_docstring_bad_indentationc                 C  sH   t tdtddtddg t tdtdddd	td
ddd	g d S )Nz(*args, **kwargs)r   r   z**kwargszB(x: Tuple[int, Tuple[str, int], str]=(1, ('a', 2), 'y'), y: int=4)r   r   Tr   r   r   )r"   r   r   r   r/   r/   r4   &test_infer_arg_sig_from_anon_docstring  s   z7StubgenUtilSuite.test_infer_arg_sig_from_anon_docstringc                 C  s<   t tdd t tdd t tdd t tdd  d S )Nzstr: A string.rX   zOptional[int]: An int.zOptional[int]zTuple[int, int]: A tuple.zTuple[int, int]z
str: A string.)r"   r   r   r/   r/   r4   #test_infer_prop_type_from_docstring  s   z4StubgenUtilSuite.test_infer_prop_type_from_docstringc                 C  s   t ddg ks	J d S )Nz*fetch_row([maxrows, how]) -- Fetches stuff	fetch_row)r   r   r/   r/   r4   -test_infer_sig_from_docstring_square_brackets  s   z>StubgenUtilSuite.test_infer_sig_from_docstring_square_bracketsc                 C  s   d}t t|| d S )Nu   
        ሴ
        def f(x):  # type: (int) -> int

        def g(x):
            # type: (int) -> int

        def h():

            # type: () int

        x = 1  # type: int
        r"   r   )r?   goodr/   r/   r4   %test_remove_misplaced_type_comments_1  s   z6StubgenUtilSuite.test_remove_misplaced_type_comments_1c                 C     d}d}t t|| d S )Nz
        def f(x):
            # type: Callable[[int], int]
            pass

        #  type:  "foo"
        #  type:  'bar'
        x = 1
        # type: int
        z?
        def f(x):

            pass



        x = 1

        r   r?   bad	bad_fixedr/   r/   r4   %test_remove_misplaced_type_comments_2     

z6StubgenUtilSuite.test_remove_misplaced_type_comments_2c                 C  r   )Nz
        def f(x):
            """docstring"""
            # type: (int) -> int
            pass

        def g(x):
            """docstring
            """
            # type: (int) -> int
            pass
        z
        def f(x):
            """docstring"""

            pass

        def g(x):
            """docstring
            """

            pass
        r   r   r/   r/   r4   %test_remove_misplaced_type_comments_3     z6StubgenUtilSuite.test_remove_misplaced_type_comments_3c                 C  r   )Nz
        def f(x):
            '''docstring'''
            # type: (int) -> int
            pass

        def g(x):
            '''docstring
            '''
            # type: (int) -> int
            pass
        z
        def f(x):
            '''docstring'''

            pass

        def g(x):
            '''docstring
            '''

            pass
        r   r   r/   r/   r4   %test_remove_misplaced_type_comments_4  r   z6StubgenUtilSuite.test_remove_misplaced_type_comments_4c                 C  r   )Nz
        def f(x):
            # type: (int, List[Any],
            #        float, bool) -> int
            pass

        def g(x):
            # type: (int, List[Any])
            pass
        z{
        def f(x):

            #        float, bool) -> int
            pass

        def g(x):

            pass
        r   r   r/   r/   r4   %test_remove_misplaced_type_comments_5  r   z6StubgenUtilSuite.test_remove_misplaced_type_comments_5c                 C  r   )Ns   
        
        def f(x):  # type: (int) -> int

        def g(x):
            # type: (int) -> int
            pass

        def h():
            # type: int
            pass

        x = 1  # type: int
        s   
        
        def f(x):  # type: (int) -> int

        def g(x):
            # type: (int) -> int
            pass

        def h():

            pass

        x = 1  # type: int
        r   )r?   originaldestr/   r/   r4   )test_remove_misplaced_type_comments_bytes$  s   z:StubgenUtilSuite.test_remove_misplaced_type_comments_bytesr&   z0Tests building the paths common ancestor on *nixc                 C  s   t g dksJ t dgdksJ t dgdksJ t dgdks#J t ddgdks-J t ddgdks7J t d	dgdksAJ t d
dgdksKJ t d	dgdksUJ t d
dgdks_J t ddgdksiJ t dgdksrJ t dgdks{J d S )N.x.pyiz./x.pyifoo/bar/x.pyizfoo/barzfoo/bar/y.pyiz	foo/y.pyifooz	foo/x.pyizfoo/bar/zar/x.pyizfoo/bar/zar/y.pyifoo/bar\x.pyifoo\bar/x.pyifoo\barr   r   r/   r/   r4   test_common_dir_prefix_unixE  s   z,StubgenUtilSuite.test_common_dir_prefix_unixz3Tests building the paths common ancestor on Windowsc                 C  s   t dgdks	J t dgdksJ t dgdksJ t ddgdks%J t ddgdks/J t d	dgdks9J t d
dgdksCJ t d	dgdksMJ t d
dgdksWJ t ddgdksaJ t dgdksjJ t dgdkssJ t dgdks|J d S )Nr   r   z.\x.pyizfoo\bar\x.pyir   zfoo\bar\y.pyiz	foo\y.pyir   z	foo\x.pyizfoo\bar\zar\x.pyizfoo\bar\zar\y.pyir   r   r   r   r   r/   r/   r4   test_common_dir_prefix_winU  s   z+StubgenUtilSuite.test_common_dir_prefix_winNre   )r   rX   r^   r   r(   r)   )"rf   rg   rh   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rj   rk   rR   rl   r   r   r/   r/   r/   r4   r|      sB    












 
"









!
r|   c                   @  s    e Zd ZdddZdddZdS )	StubgenHelpersSuiter(   r)   c                 C  sd   t drJ t drJ t drJ t drJ t dsJ t ds$J t ds*J t ds0J d S )	Nz
foo/bar.pyzfoo.pyzfoo/xvendor/bar.pyzfoo/vendorx/bar.pyzfoo/vendor/bar.pyzfoo/vendored/bar.pyzfoo/vendored/bar/thing.pyz
foo/six.py)r   r   r/   r/   r4   test_is_blacklisted_pathi  s   z,StubgenHelpersSuite.test_is_blacklisted_pathc                 C  s   t drJ t drJ t drJ t drJ t drJ t ds$J t ds*J t ds0J t d	s6J t d
s<J t dsBJ t dsHJ t dsNJ t dsTJ t dsZJ t ds`J t dsfJ t dslJ t dsrJ t dsxJ d S )Nr   r   zfoo.bartestzfoo.bartestszfoo.testbarzfoo.testzfoo.test.fooz	foo.testszfoo.tests.foozfoo.testing.foozfoo.SelfTest.foozfoo.test_barzfoo.bar_testszfoo.testingzfoo.conftestzfoo.bar_test_utilzfoo.bar_test_utilszfoo.bar_test_basez	foo.setupzfoo.__main__)r   r   r/   r/   r4   test_is_non_library_modules  s(   z.StubgenHelpersSuite.test_is_non_library_moduleNre   )rf   rg   rh   r   r   r/   r/   r/   r4   r   h  s    

r   c                   @  sb   e Zd ZdZdZdZdgZee	j
dkddddZdddZd ddZd!ddZd"ddZdS )#StubgenPythonSuitea'  Data-driven end-to-end test cases that generate stub files.

    You can use these magic test case name suffixes:

    *_semanal
        Run semantic analysis (slow as this uses real stubs -- only use
        when necessary)
    *_import
        Import module and perform runtime introspection (in the current
        process!)

    You can use these magic comments:

    # flags: --some-stubgen-option ...
        Specify custom stubgen options

    # modules: module1 module2 ...
        Specify which modules to output (by default only 'main')
    Tr   zstubgen.testr&   r'   testcaser    r(   r)   c                 C  s6   t   | | W d    d S 1 sw   Y  d S r`   )r$   run_case_inner)r?   r   r/   r/   r4   run_case  s   "zStubgenPythonSuite.run_casec              
   C  s  g }g }d |j}|jd|fg D ]E\}}|dd dd}|dr-|d\}}}|| d|vr=|d	|g t|d
}	|		| W d    n1 sRw   Y  q| 
||}
tj|
jk rht  | |}d}zvz:|jdr{d|
_n|jdsd|
_|jdsd|
_t|
 g }|D ]}t||}| j||t|dkd qW n ty } z	|j}W Y d }~nd }~ww t|j|d|j d|j d W |D ]}|tjv rtj|= qt !| d S |D ]}|tjv rtj|= qt !| w )N
z	./main.py   /r   z	.__init__z-p rM   rY   out_inspectT_import_semanal   )headerzInvalid output (z, line ))"r=   inputrF   replaceendswith
rpartitionappendextendrZ   r[   parse_flagsrR   version_info	pyversionpytestskipparse_modulesr   inspect	no_import
parse_onlyr   module_to_pathadd_filelenr   messagesr#   outputr\   linemodulesshutilrmtree)r?   r   extramodssourcer\   rI   r3   _r]   optionsr   out_diramodulefnamer/   r/   r4   r     sd   





z!StubgenPythonSuite.run_case_innerprogram_textrX   r   	list[str]r   c                 C  s   t jd|t jd}d }|r0|d }t|D ]\}}|dr.|ddd }||=  nqng }t|| }|rK|dd\}	}
t|	t|
f|_	d|vrTd|_
|S d|_|S )	Nz# flags: (.*)$flagsr   z--python-version==r   z	--verboseT)research	MULTILINEgroupsplit	enumerate
startswithr   r   r   quietverbose)r?   r  r   r	  r   	flag_listiflagr   majorminorr/   r/   r4   r     s*   
zStubgenPythonSuite.parse_flagsc                 C  s*   t jd|t jd}|r|d S dgS )Nz# modules: (.*)$r  r   main)r  r  r  r  r  )r?   r  r   r/   r/   r4   r     s   z StubgenPythonSuite.parse_modulesr0   r^   r   boolc                 C  s   t j|s|d|dd  d S |r!|d|dd    t|dd}||   W d    d S 1 s<w   Y  d S )Nz<%s was not generated>\r   z#    utf8)encoding)	r6   r0   existsr   r   rZ   r   read
splitlines)r?   r0   r^   r   r\   r/   r/   r4   r     s   "zStubgenPythonSuite.add_fileN)r   r    r(   r)   )r  rX   r   r  r(   r   )r  rX   r(   r  )r0   rX   r^   r  r   r  r(   r)   )rf   rg   rh   ri   required_out_section	base_pathrF   rj   rk   rR   rl   r   r   r   r   r   r/   r/   r/   r4   r     s    

.
r   r?   r   c                   @     e Zd ZdS )TestBaseClassNrf   rg   rh   r/   r/   r/   r4   r%  	      r%  c                   @  r$  )	TestClassNr&  r/   r/   r/   r4   r(    r'  r(  c                   @  sx  e Zd ZdZdMddZdMddZdMdd	ZdMd
dZdMddZdMddZ	dMddZ
dMddZdMddZdMddZdMddZdMddZdMddZdMddZdMd d!ZdMd"d#ZdMd$d%ZdMd&d'ZdMd(d)ZdMd*d+ZdMd,d-ZdMd.d/ZdMd0d1ZdMd2d3ZdMd4d5ZdMd6d7ZdMd8d9ZdMd:d;ZdMd<d=Z dMd>d?Z!dMd@dAZ"dMdBdCZ#dMdDdEZ$dMdFdGZ%dMdHdIZ&dMdJdKZ'dLS )NStubgencSuitezoUnit tests for stub generation from C modules using introspection.

    Note that these don't cover a lot!
    r(   r)   c                 C  s"   t tdtg t tdd d S )N__hash__r   )r"   r   self_argr   r   r/   r/   r4   test_infer_hash_sig  s   z!StubgencSuite.test_infer_hash_sigc                 C  s   t tdttddg d S )N__getitem__indexr   r"   r   r+  r   r   r/   r/   r4   test_infer_getitem_sig  s   z$StubgencSuite.test_infer_getitem_sigc                 C  s2   t tdttddtddg t tdd d S )N__setitem__r.  r   objectr)   )r"   r   r+  r   r   r   r/   r/   r4   test_infer_setitem_sig  s
   z$StubgencSuite.test_infer_setitem_sigc                 C  s0   dD ]}t td| dttdddg qd S )N)eqneltlegtge__otherr2  r   r/  r?   opr/   r/   r4   test_infer_eq_op_sig%  s
   z"StubgencSuite.test_infer_eq_op_sigc                 C  s.   dD ]}t td| dttddg qd S )N)addraddsubrsubmulrmulr:  r;  r   r/  r<  r/   r/   r4   test_infer_binary_op_sig+  s   "z&StubgencSuite.test_infer_binary_op_sigc                 C  s$   dD ]}t td| dd qd S )N)r4  r5  r6  r7  r8  r9  containsr:  r  r"   r   r<  r/   r/   r4   test_infer_equality_op_sig/     z(StubgencSuite.test_infer_equality_op_sigc                 C  s&   dD ]}t td| dtg qd S )N)negposr:  )r"   r   r+  r<  r/   r/   r4   test_infer_unary_op_sig3  s   z%StubgencSuite.test_infer_unary_op_sigc                 C  s$   dD ]}t td| d| qd S )N)floatr  bytesr   r:  rG  r<  r/   r/   r4   test_infer_cast_sig7  rI  z!StubgencSuite.test_infer_cast_sigc                 C  sT   g }t dd}t|j|jg|d}|dt| t|  g  t|d d d S )Nr  rO   known_modulesr  aliasr   zclass alias:)r   r   rf   generate_class_stubr2  r"   get_importsr!  r?   r   r3   genr/   r/   r4   ,test_generate_class_stub_no_crash_for_object;  s   
z:StubgencSuite.test_generate_class_stub_no_crash_for_objectc                 C  sd   G dd d}g }t dd}t|j|jg|d}|d|| t|  dg t|dd	g d S )
Nc                   @  s   e Zd ZdZdS )z]StubgencSuite.test_generate_class_stub_variable_type_annotation.<locals>.TestClassVariableClsr   N)rf   rg   rh   r   r/   r/   r/   r4   TestClassVariableClsF  s    rX  r  rO   rP  Czfrom typing import ClassVarzclass C:z    x: ClassVar[int] = ...)r   r   rf   rS  r"   rT  r!  )r?   rX  r   r3   rV  r/   r/   r4   1test_generate_class_stub_variable_type_annotationD  s   
z?StubgencSuite.test_generate_class_stub_variable_type_annotationc                 C  sp   G dd d}g }t |jd}t|j|jg|d}d|_|jd|j|td|dt|dd d	d
 t	|dg d S )Nc                   @  s   e Zd Zdddd
dZdS )zPStubgencSuite.test_non_c_generate_signature_with_kw_only_args.<locals>.TestClass   )keyword_only_with_defaultarg0rX   keyword_onlyr\  r   r(   r)   c                S     d S r`   r/   )r?   r]  r^  r\  r/   r/   r4   testR  s   zUStubgencSuite.test_non_c_generate_signature_with_kw_only_args.<locals>.TestClass.testN)r]  rX   r^  rX   r\  r   r(   r)   rf   rg   rh   r`  r/   r/   r/   r4   r(  Q  s    r(  rO   rP  Fr`  r?   ri   self_varclsr   	docstringr   
class_infozbdef test(self, arg0: str, *, keyword_only: str, keyword_only_with_default: int = ...) -> None: ...)
r   rg   r   rf   is_c_modulegenerate_function_stubr`  r   getattrr"   r?   r(  r   r3   rV  r/   r/   r4   /test_non_c_generate_signature_with_kw_only_argsP  s*   
z=StubgencSuite.test_non_c_generate_signature_with_kw_only_argsc                 C  s`   G dd dt }g }td}t|j|jg|d}|d|| t|dg t|  g  d S )Nc                   @  r$  )zAStubgencSuite.test_generate_c_type_inheritance.<locals>.TestClassNr&  r/   r/   r/   r4   r(  n  r'  r(  zmodule, rP  rY  zclass C(KeyError): ...)KeyErrorr   r   rf   rS  r"   rT  r!  rk  r/   r/   r4    test_generate_c_type_inheritancem  s   z.StubgencSuite.test_generate_c_type_inheritancec                 C  sT   g }t tjd}t|j|jg|d}|dt| t|dg t| 	 g  d S )NrO   rP  rY  zclass C(TestBaseClass): ...)
r   r%  rg   r   rf   rS  r(  r"   rT  r!  rU  r/   r/   r4   ,test_generate_c_type_inheritance_same_modulex  s   z:StubgencSuite.test_generate_c_type_inheritance_same_modulec                 C  sn   dd l }G dd d|j}g }tdd}t|j|jg|d}|d|| t|dg t|  d	g d S )
Nr   c                   @  r$  )zNStubgencSuite.test_generate_c_type_inheritance_other_module.<locals>.TestClassNr&  r/   r/   r/   r4   r(    r'  r(  r  rO   rP  rY  zclass C(argparse.Action): ...import argparse)	argparseActionr   r   rf   rS  r"   rT  r!  )r?   rq  r(  r   r3   rV  r/   r/   r4   -test_generate_c_type_inheritance_other_module  s   
z;StubgencSuite.test_generate_c_type_inheritance_other_modulec                 C  sb   G dd dt }g }tdd}t|j|jg|d}|d|| t|dg t|  g  d S )Nc                   @  r$  )zNStubgencSuite.test_generate_c_type_inheritance_builtin_type.<locals>.TestClassNr&  r/   r/   r/   r4   r(    r'  r(  r  rO   rP  rY  zclass C(type): ...)r   r   r   rf   rS  r"   rT  r!  rk  r/   r/   r4   -test_generate_c_type_inheritance_builtin_type  s   
z;StubgencSuite.test_generate_c_type_inheritance_builtin_typec              	   C  r   G dd d}g }t |jd}t|j|jg|d}|jd|j|td|ddd t|d	g t| 	 g  d S )
Nc                   @     e Zd ZdddZdS )	zDStubgencSuite.test_generate_c_type_with_docstring.<locals>.TestClassr]  rX   r(   r)   c                 S     dS )zB
                test(self: TestClass, arg0: int)
                Nr/   r?   r]  r/   r/   r4   r`        zIStubgencSuite.test_generate_c_type_with_docstring.<locals>.TestClass.testNr]  rX   r(   r)   ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   rc  rd  r   rf  %def test(self, arg0: int) -> Any: ...
r   rg   r   rf   ri  r`  r   r"   rT  r!  rk  r/   r/   r4   #test_generate_c_type_with_docstring     z1StubgencSuite.test_generate_c_type_with_docstringc              	   C  ru  )
Nc                   @  rv  )	zPStubgencSuite.test_generate_c_type_with_docstring_no_self_arg.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )z1
                test(arg0: int)
                Nr/   rx  r/   r/   r4   r`    ry  zUStubgencSuite.test_generate_c_type_with_docstring_no_self_arg.<locals>.TestClass.testNrz  ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   r{  rf  r|  r}  rk  r/   r/   r4   /test_generate_c_type_with_docstring_no_self_arg  r  z=StubgencSuite.test_generate_c_type_with_docstring_no_self_argc              	   C  st   G dd d}g }t |jd}t|j|jg|d}|jd|j|td|ddd t|d	d
g t| 	 g  d S )Nc                   @     e Zd ZedddZdS )	zAStubgencSuite.test_generate_c_type_classmethod.<locals>.TestClassr]  rX   r(   r)   c                 S  r_  r`   r/   )rd  r]  r/   r/   r4   r`    s   zFStubgencSuite.test_generate_c_type_classmethod.<locals>.TestClass.testNrz  rf   rg   rh   classmethodr`  r/   r/   r/   r4   r(        r(  rO   rP  r`  rd  r{  rf  @classmethodz#def test(cls, *args, **kwargs): ...r}  rk  r/   r/   r4    test_generate_c_type_classmethod  s   z.StubgencSuite.test_generate_c_type_classmethodc              	   C  v   G dd d}g }t |jd}t|j|jg|d}|jd|j|td|ddd t|g d	 t| 	 d
g d S )Nc                   @  r  )	zPStubgencSuite.test_generate_c_type_classmethod_with_overloads.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )z[
                test(cls, arg0: str)
                test(cls, arg0: int)
                Nr/   rx  r/   r/   r4   r`    s   zUStubgencSuite.test_generate_c_type_classmethod_with_overloads.<locals>.TestClass.testNrz  r  r/   r/   r/   r4   r(    r  r(  rO   rP  r`  rd  r{  rf  )	@overloadr  z$def test(cls, arg0: str) -> Any: ...r  r  z$def test(cls, arg0: int) -> Any: ...from typing import overloadr}  rk  r/   r/   r4   /test_generate_c_type_classmethod_with_overloads  s   	z=StubgencSuite.test_generate_c_type_classmethod_with_overloadsc              	   C  ru  )
Nc                   @  s   e Zd Zd	d
ddZdS )zRStubgencSuite.test_generate_c_type_with_docstring_empty_default.<locals>.TestClassrO   r]  rX   r(   r)   c                 S  rw  )zG
                test(self: TestClass, arg0: str = "")
                Nr/   rx  r/   r/   r4   r`    ry  zWStubgencSuite.test_generate_c_type_with_docstring_empty_default.<locals>.TestClass.testN)rO   rz  ra  r/   r/   r/   r4   r(    s    r(  rO   rP  r`  r?   r{  rf  z+def test(self, arg0: str = ...) -> Any: ...r}  rk  r/   r/   r4   1test_generate_c_type_with_docstring_empty_default  r  z?StubgencSuite.test_generate_c_type_with_docstring_empty_defaultc                 C  b   ddd}g }t | jd}t|j|jg|d}|jd	||d
 t|dg t|  dg dS )zQTest that if argument references type from other module, module will be imported.r]  rX   r(   r)   c                 S  rw  )z5
            test(arg0: argparse.Action)
            Nr/   r]  r/   r/   r4   r`    ry  zEStubgencSuite.test_generate_c_function_other_module_arg.<locals>.testrO   rP  r`  r   z+def test(arg0: argparse.Action) -> Any: ...rp  Nrz  r   rg   r   rf   ri  r"   rT  r!  r?   r`  r   r3   rV  r/   r/   r4   )test_generate_c_function_other_module_arg  s   
z7StubgencSuite.test_generate_c_function_other_module_argc                 C  ^   ddd}g }t dd}t|j|jg|d	}|jd
||d t|dg t|  g  dS )zTest that if annotation references type from same module but using full path, no module
        will be imported, and type specification will be striped to local reference.
        r]  rX   r(   r)   c                 S  rw  zH
            test(arg0: argparse.Action) -> argparse.Action
            Nr/   r  r/   r/   r4   r`    ry  z@StubgencSuite.test_generate_c_function_same_module.<locals>.testrq  rO   rP  r`  r  z%def test(arg0: Action) -> Action: ...Nrz  r   r   rf   ri  r"   rT  r!  r  r/   r/   r4   $test_generate_c_function_same_module     

z2StubgencSuite.test_generate_c_function_same_modulec                 C  r  )zSTest that if annotation references type from other module, module will be imported.r]  rX   r(   r)   c                 S  rw  r  r/   r  r/   r/   r4   r`  *  ry  zAStubgencSuite.test_generate_c_function_other_module.<locals>.testrO   rP  r`  r  z7def test(arg0: argparse.Action) -> argparse.Action: ...rp  Nrz  r  r  r/   r/   r4   %test_generate_c_function_other_module'  s   
z3StubgencSuite.test_generate_c_function_other_modulec                 C  r  )Test that if annotation references type from same module but using full path, no module
        will be imported, and type specification will be stripped to local reference.
        r]  rX   r(   r)   c                 S  rw  )zT
            test(arg0: list[argparse.Action]) -> list[argparse.Action]
            Nr/   r  r/   r/   r4   r`  =  ry  zGStubgencSuite.test_generate_c_function_same_module_nested.<locals>.testrq  rO   rP  r`  r  z1def test(arg0: list[Action]) -> list[Action]: ...Nrz  r  r  r/   r/   r4   +test_generate_c_function_same_module_nested6  r  z9StubgencSuite.test_generate_c_function_same_module_nestedc                 C  r  )r  r]  rX   r(   r)   c                 S  rw  )zj
            test(arg0: Union[argparse.Action, NoneType]) -> Tuple[argparse.Action, NoneType]
            Nr/   r  r/   r/   r4   r`  P  ry  zIStubgencSuite.test_generate_c_function_same_module_compound.<locals>.testrq  rO   rP  r`  r  z?def test(arg0: Union[Action, None]) -> Tuple[Action, None]: ...Nrz  r  r  r/   r/   r4   -test_generate_c_function_same_module_compoundI  r  z;StubgencSuite.test_generate_c_function_same_module_compoundc                 C  sd   ddd}g }t | jd}t|jg d|d	}|jd
||d t|dg t|  ddg dS )zTest that if annotation references type from other module, module will be imported,
        and the import will be restricted to one of the known modules.r]  rX   r(   r)   c                 S  rw  )zC
            test(arg0: foo.bar.Action) -> other.Thing
            Nr/   r  r/   r/   r4   r`  `  ry  zHStubgencSuite.test_generate_c_function_other_module_nested.<locals>.testrO   )r   zfoo.spanglebarrP  r`  r  z2def test(arg0: foo.bar.Action) -> other.Thing: ...z
import foozimport otherNrz  r  r  r/   r/   r4   ,test_generate_c_function_other_module_nested\  s   
z:StubgencSuite.test_generate_c_function_other_module_nestedc                 C  sn   ddd}t dd |_g }t| jd	}t|j|jg|d
}|jd||d t|dg t| 	 g  d S )Nr]  rX   r(   r)   c                 S  r_  r`   r/   r  r/   r/   r4   r`  o  ry  zSStubgencSuite.test_generate_c_function_no_crash_for_non_str_docstring.<locals>.testc                 S  rw  )Nztest(arg0: str) -> Noner/   r   r/   r/   r4   <lambda>q  ry  zWStubgencSuite.test_generate_c_function_no_crash_for_non_str_docstring.<locals>.<lambda>rO   rP  r`  r  zdef test(*args, **kwargs): ...rz  )
propertyri   r   rg   r   rf   ri  r"   rT  r!  r  r/   r/   r4   7test_generate_c_function_no_crash_for_non_str_docstringn  s   
zEStubgencSuite.test_generate_c_function_no_crash_for_non_str_docstringc                 C  sl   G dd d}g }g }t dd}t|j|jg|d}|d|jd |jg || t|g  t|ddg d	S )
z>Signatures included by PyBind11 inside property.fget are read.c                   @  s"   e Zd ZdddZeeddZdS )	zGStubgencSuite.test_generate_c_property_with_pybind11.<locals>.TestClassr(   r)   c                 S  rw  )z:
                (self: TestClass) -> str
                Nr/   r   r/   r/   r4   get_attribute~  ry  zUStubgencSuite.test_generate_c_property_with_pybind11.<locals>.TestClass.get_attributerO   )docNre   )rf   rg   rh   r  r  	attributer/   r/   r/   r4   r(  }  s    
r(  r  rO   rP  r  z	@propertyzdef attribute(self) -> str: ...Nr   r   rf   generate_property_stub__dict__r  r"   r?   r(  readwrite_propertiesreadonly_propertiesr3   rV  r/   r/   r4   &test_generate_c_property_with_pybind11z  s   

z4StubgencSuite.test_generate_c_property_with_pybind11c                 C  sj   G dd d}g }g }t dd}t|j|jg|d}|d|jd |jg || t|dg t|g  d S )Nc                   @  s4   e Zd ZdddZedddZejdd	dZd
S )zJStubgencSuite.test_generate_c_property_with_rw_property.<locals>.TestClassr(   r)   c                 S  s
   d| _ d S )Nr   
_attributer   r/   r/   r4   __init__  s   
zSStubgencSuite.test_generate_c_property_with_rw_property.<locals>.TestClass.__init__r   c                 S  s   | j S r`   r  r   r/   r/   r4   r    s   zTStubgencSuite.test_generate_c_property_with_rw_property.<locals>.TestClass.attributevaluec                 S  s
   || _ d S r`   r  )r?   r  r/   r/   r4   r    s   
Nre   )r(   r   )r  r   r(   r)   )rf   rg   rh   r  r  r  setterr/   r/   r/   r4   r(    s    
r(  r  rO   rP  r  zattribute: Incompleter  r  r/   r/   r4   )test_generate_c_property_with_rw_property  s   
z7StubgencSuite.test_generate_c_property_with_rw_propertyc              	   C  ru  )
Nc                   @  rv  )	zMStubgencSuite.test_generate_c_type_with_single_arg_generic.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )zH
                test(self: TestClass, arg0: List[int])
                Nr/   rx  r/   r/   r4   r`    ry  zRStubgencSuite.test_generate_c_type_with_single_arg_generic.<locals>.TestClass.testNrz  ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   r{  rf  z+def test(self, arg0: List[int]) -> Any: ...r}  rk  r/   r/   r4   ,test_generate_c_type_with_single_arg_generic  r  z:StubgencSuite.test_generate_c_type_with_single_arg_genericc              	   C  ru  )
Nc                   @  rv  )	zMStubgencSuite.test_generate_c_type_with_double_arg_generic.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )zM
                test(self: TestClass, arg0: Dict[str, int])
                Nr/   rx  r/   r/   r4   r`    ry  zRStubgencSuite.test_generate_c_type_with_double_arg_generic.<locals>.TestClass.testNrz  ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   r{  rf  z0def test(self, arg0: Dict[str, int]) -> Any: ...r}  rk  r/   r/   r4   ,test_generate_c_type_with_double_arg_generic  r  z:StubgencSuite.test_generate_c_type_with_double_arg_genericc              	   C  ru  )
Nc                   @  rv  )	zIStubgencSuite.test_generate_c_type_with_nested_generic.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )zS
                test(self: TestClass, arg0: Dict[str, List[int]])
                Nr/   rx  r/   r/   r4   r`    ry  zNStubgencSuite.test_generate_c_type_with_nested_generic.<locals>.TestClass.testNrz  ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   r{  rf  z6def test(self, arg0: Dict[str, List[int]]) -> Any: ...r}  rk  r/   r/   r4   (test_generate_c_type_with_nested_generic  r  z6StubgencSuite.test_generate_c_type_with_nested_genericc              	   C  t   G dd d}g }t |jd}t|j|jg|d}|jd|j|td|ddd t|d	g t| 	 d
g d S )Nc                   @  rv  )	z[StubgencSuite.test_generate_c_type_with_generic_using_other_module_first.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )zY
                test(self: TestClass, arg0: Dict[argparse.Action, int])
                Nr/   rx  r/   r/   r4   r`    ry  z`StubgencSuite.test_generate_c_type_with_generic_using_other_module_first.<locals>.TestClass.testNrz  ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   r{  rf  z<def test(self, arg0: Dict[argparse.Action, int]) -> Any: ...rp  r}  rk  r/   r/   r4   :test_generate_c_type_with_generic_using_other_module_first     zHStubgencSuite.test_generate_c_type_with_generic_using_other_module_firstc              	   C  r  )Nc                   @  rv  )	zZStubgencSuite.test_generate_c_type_with_generic_using_other_module_last.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )zY
                test(self: TestClass, arg0: Dict[str, argparse.Action])
                Nr/   rx  r/   r/   r4   r`    ry  z_StubgencSuite.test_generate_c_type_with_generic_using_other_module_last.<locals>.TestClass.testNrz  ra  r/   r/   r/   r4   r(    r{   r(  rO   rP  r`  r?   r{  rf  z<def test(self, arg0: Dict[str, argparse.Action]) -> Any: ...rp  r}  rk  r/   r/   r4   9test_generate_c_type_with_generic_using_other_module_last  r  zGStubgencSuite.test_generate_c_type_with_generic_using_other_module_lastc              	   C  r  )Nc                   @  rv  )	zLStubgencSuite.test_generate_c_type_with_overload_pybind11.<locals>.TestClassr]  rX   r(   r)   c                 S  rw  )z
                __init__(*args, **kwargs)
                Overloaded function.

                1. __init__(self: TestClass, arg0: str) -> None

                2. __init__(self: TestClass, arg0: str, arg1: str) -> None
                Nr/   rx  r/   r/   r4   r    ry  zUStubgencSuite.test_generate_c_type_with_overload_pybind11.<locals>.TestClass.__init__Nrz  )rf   rg   rh   r  r/   r/   r/   r4   r(    r{   r(  rO   rP  r  r?   r{  rf  )r  *def __init__(self, arg0: str) -> None: ...r  5def __init__(self, arg0: str, arg1: str) -> None: ...r  z/def __init__(self, *args, **kwargs) -> Any: ...r  )
r   rg   r   rf   ri  r  r   r"   rT  r!  rk  r/   r/   r4   +test_generate_c_type_with_overload_pybind11  s   z9StubgencSuite.test_generate_c_type_with_overload_pybind11c                 C  s   G dd d}g }t |jd}t|j|jg|d}|jd|j|td|dt|dd dd	 t|g d
 t|	 
 dg d S )Nc                   @  s   e Zd ZdZd	ddZdS )
zLStubgencSuite.test_generate_c_type_with_overload_shiboken.<locals>.TestClassz
            TestClass(self: TestClass, arg0: str) -> None
            TestClass(self: TestClass, arg0: str, arg1: str) -> None
            r]  rX   r(   r)   c                 S  r_  r`   r/   rx  r/   r/   r4   r  8  s   zUStubgencSuite.test_generate_c_type_with_overload_shiboken.<locals>.TestClass.__init__Nrz  )rf   rg   rh   ri   r  r/   r/   r/   r4   r(  2  s    r(  rO   rP  r  r?   ri   rb  rf  )r  r  r  r  r  )r   rg   r   rf   ri  r  r   rj  r"   rT  r!  rk  r/   r/   r4   +test_generate_c_type_with_overload_shiboken1  s(   	
	z9StubgencSuite.test_generate_c_type_with_overload_shibokenNre   )(rf   rg   rh   ri   r,  r0  r3  r>  rE  rH  rL  rO  rW  rZ  rl  rn  ro  rs  rt  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/   r/   r/   r4   r)    sL    









	









 














"r)  c                   @  rn   )ArgSigSuiter(   r)   c                 C  sX   t ttddd t ttddd t ttddd t ttddd	d
d d S )Nzasd"dsar   z0ArgSig(name='asd"dsa', type=None, default=False)zasd'dsaz0ArgSig(name="asd'dsa", type=None, default=False)r}   rX   z.ArgSig(name='func', type='str', default=False)T)r   z-ArgSig(name='func', type='str', default=True))r"   reprr   r   r/   r/   r4   	test_reprV  s   zArgSigSuite.test_reprNre   )rf   rg   rh   r  r/   r/   r/   r4   r  U  r{   r  c                   @  rn   )IsValidTypeSuiter(   r)   c                 C  s  t dsJ t dsJ t dsJ t dsJ t dsJ t ds$J t ds*J t ds0J t d	s6J t d
s<J t dsBJ t dsHJ t dsNJ t dsTJ t dsZJ t ds`J t drfJ t drlJ t drrJ t drxJ t dr~J t drJ d S )Nr   rX   
Foo_Bar234r   z	List[int]zDict[str, int]r)   zLiteral[26]zLiteral[0x1A]zLiteral["hello world"]zLiteral[b"hello world"]zLiteral[u"hello world"]zLiteral[True]zLiteral[Color.RED]zLiteral[None]zWLiteral[26, 0x1A, "hello world", b"hello world", u"hello world", True, Color.RED, None]zfoo-barzx->yTrueFalsezx,yzx, y)r   r   r/   r/   r4   test_is_valid_typee  s0   z#IsValidTypeSuite.test_is_valid_typeNre   )rf   rg   rh   r  r/   r/   r/   r4   r  d  r{   r  c                   @  s4   e Zd ZdddZdddZdddZdd	d
ZdS )ModuleInspectSuiter(   r)   c                 C  s   t  5}|d}|d usJ |jdksJ |jsJ |jd u s"J |jdu s)J |jg ks0J W d    d S 1 s;w   Y  d S )Nr   F)r   get_package_propertiesr   r\   r0   rh  subpackagesr?   rx   pr/   r/   r4   test_python_module  s   

"z%ModuleInspectSuite.test_python_modulec                 C  s   t  =}|d}|d usJ |jdksJ |jsJ |js J |jdu s'J |js,J tdd |jD s8J W d    d S 1 sCw   Y  d S )Nrj   Fc                 s  s    | ]}| d V  qdS )z	unittest.N)r  )r2   rA  r/   r/   r4   	<genexpr>  s    z9ModuleInspectSuite.test_python_package.<locals>.<genexpr>)r   r  r   r\   r0   rh  r  allr  r/   r/   r4   test_python_package  s   



"z&ModuleInspectSuite.test_python_packagec                 C  sz   t  0}|d}|d usJ |jdksJ |jd u sJ |jdu s$J |jg ks+J W d    d S 1 s6w   Y  d S )N_socketT)r   r  r   r0   rh  r  r  r/   r/   r4   test_c_module  s   
"z ModuleInspectSuite.test_c_modulec              	   C  sr   t  ,}| t}|d W d    n1 sw   Y  t|jdks'J W d    d S 1 s2w   Y  d S )Nzfoobar-non-existentz%No module named 'foobar-non-existent')r   assertRaisesr   r  rX   	exception)r?   rx   r  r/   r/   r4   test_non_existent  s   "z$ModuleInspectSuite.test_non_existentNre   )rf   rg   rh   r  r  r  r  r/   r/   r/   r4   r    s
    



	r  r  rX   r  r(   c                 C  sH   t j| |dd d}t j|s"|dd}t j|r"|S |S )Nr   r   z.pyiz/__init__.pyi)r6   r0   r=   r   r  )r  r  r  alt_fnamr/   r/   r4   r     s   r   )r  rX   r  rX   r(   rX   )E
__future__r   rP   os.pathr6   r  r   rR   r8   rj   typesr   typingr   r   mypy.errorsr   mypy.moduleinspectr   r   mypy.stubdocr   r	   r
   r   r   r   r   r   r   r   mypy.stubgenr   r   r   r   r   r   r   mypy.stubgencr   r   mypy.stubutilr   r   r   r   r   mypy.test.datar    r!   mypy.test.helpersr"   r#   r$   TestCaser%   ro   r|   r   r   r+  r%  r(  r)  r  r  r  r   r/   r/   r/   r4   <module>   sN    0$	R   U)
u    H&