
    *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	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mZ ddl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	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,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK ddlLmMZN ddlOmPZPmQZQ ddlRmSZSmTZT ddlUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb ddlmcZcmdZdmeZemfZf ddlgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZq ddlrmsZs g dZtdeud<   g dZvdeud<   h dZwdeud<    G d d          ZM G d d          ZxdZydeud<   dZzdeud<   dZ{deud<   d Z|deud <   d!Z}deud!<   d"Z~deud"<   d#Zdeud$<    G d% d&ese                   Zd{d+Z G d, d-ej        j                  Zd{d.Zd|d2Z G d3 d4ej        j                  Z G d5 d6eVej        j                  Zd}d9Z G d: d;ej        j                  Zd~d?ZddBZddEZddGZddIZddJZddOZddTZddVZddZZdd^Zdd`ZdddZddgZdhdhdhdhdhdidjddrZddsZdtZduZddwZdddyZedzk    r e             dS dS )a+  Generator of dynamically typed draft stubs for arbitrary modules.

The logic of this script can be split in three steps:
* parsing options and finding sources:
  - use runtime imports be default (to find also C modules)
  - or use mypy's mechanisms, if importing is prohibited
* (optionally) semantically analysing the sources using mypy (as a single set)
* emitting the stubs text:
  - for Python modules: from ASTs using ASTStubGenerator
  - for C modules using runtime introspection and (optionally) Sphinx docs

During first and third steps some problematic files can be skipped, but any
blocking error during second step will cause the whole program to stop.

Basic usage:

  $ stubgen foo.py bar.py some_directory
  => Generate out/foo.pyi, out/bar.pyi, and stubs for some_directory (recursively).

  $ stubgen -m urllib.parse
  => Generate out/urllib/parse.pyi.

  $ stubgen -p urllib
  => Generate stubs for whole urlib package (recursively).

For C modules, you can get more precise function signatures by parsing .rst (Sphinx)
documentation for extra information. For this, use the --doc-dir option:

  $ stubgen --doc-dir <DIR>/Python-3.4.2/Doc/library -m curses

Note: The generated stubs should be verified manually.

TODO:
 - maybe use .rst docs also for Python modules
 - maybe export more imported names if there is no __all__ (this affects ssl.SSLError, for example)
   - a quick and dirty heuristic would be to turn this on if a module has something like
     'from x import y as _y'
 - we don't seem to always detect properties ('closed' in 'io', for example)
    )annotationsN)FinalIterable)build)CompileErrorErrors)InvalidSourceListcreate_source_list)BuildSourceFindModuleCacheModuleNotFoundReasonSearchPathsdefault_lib_path)ModuleInspectis_pyc_only))	ARG_NAMEDARG_POSARG_STAR	ARG_STAR2IS_ABSTRACTNOT_ABSTRACTAssignmentStmtBlock	BytesExprCallExprClassDefComparisonExprComplexExpr	DecoratorDictExprEllipsisExpr
ExpressionExpressionStmt	FloatExprFuncBaseFuncDefIfStmtImport	ImportAll
ImportFrom	IndexExprIntExprListExpr
MemberExprMypyFileNameExprOpExprOverloadedFuncDefSetExpr	StatementStrExprTempNode	TupleExprTypeInfo	UnaryExprVar)Options)ArgSigFunctionSig)InspectionStubGeneratorgenerate_stub_for_c_module)BaseStubGenerator
CantImport	ClassInfoFunctionContextcommon_dir_prefixfail_missingfind_module_path_and_all_py3generate_guardedinfer_method_arg_typesinfer_method_ret_typeremove_misplaced_type_commentsreport_missingwalk_packages)all_yield_expressionshas_return_statementhas_yield_expressionhas_yield_from_expression)
OVERLOAD_NAMESTPDICT_NAMESTYPED_NAMEDTUPLE_NAMESAnyTypeCallableTypeInstance	TupleTypeTypeUnboundTypeget_proper_type)NodeVisitor)packagesvendorvendored_vendor_vendored_packagesr   VENDOR_PACKAGES)z/six.py
z
/vendored/z/vendor/z	/_vendor/z/_vendored_packages/	BLACKLIST>   __eq____ge____gt____le____lt____ne____hash____iter__METHODS_WITH_RETURN_VALUEc                      e Zd ZdZddZdS )r;   zPRepresents stubgen options.

    This class is mutable to simplify testing.
    	pyversiontuple[int, int]	no_importboolinspectdoc_dirstrsearch_path	list[str]interpreter
parse_onlyignore_errorsinclude_private
output_dirmodulesr\   filesverbosequietexport_lessinclude_docstringsreturnNonec                   || _         || _        || _        || _        || _        || _        || _        || _        || _        |	| _	        |
| _
        || _        || _        || _        || _        || _        || _        || _        d S N)rm   ro   rq   rr   rt   rv   decointerpreterrw   rx   ry   rz   r{   r\   r|   r}   r~   r   r   )selfrm   ro   rq   rr   rt   rv   rw   rx   ry   rz   r{   r\   r|   r}   r~   r   r   s                     ,lib/python3.11/site-packages/mypy/stubgen.py__init__zOptions.__init__   s    * #"&&*$*.$ 

&"4    N)$rm   rn   ro   rp   rq   rp   rr   rs   rt   ru   rv   rs   rw   rp   rx   rp   ry   rp   rz   rs   r{   ru   r\   ru   r|   ru   r}   rp   r~   rp   r   rp   r   rp   r   r   )__name__
__module____qualname____doc__r    r   r   r;   r;      s2         
&5 &5 &5 &5 &5 &5r   r;   c                  V    e Zd ZdZ	 dddZddZedd            Zedd            ZdS )
StubSourcezA single source for stub: can be a Python or C module.

    A simple extension of BuildSource that also carries the AST and
    the value of __all__ detected at runtime.
    Nmodulers   path
str | Noneruntime_alllist[str] | Noner   r   c                N    t          ||d           | _        || _        d | _        d S r   )r   sourcer   ast)r   r   r   r   s       r   r   zStubSource.__init__   s*     "$55&$(r   c                    d| j          dS )NzStubSource()r   r   s    r   __repr__zStubSource.__repr__   s    +T[++++r   c                    | j         j        S r   )r   r   r   s    r   r   zStubSource.module   s    {!!r   c                    | j         j        S r   )r   r   r   s    r   r   zStubSource.path   s    {r   )NN)r   rs   r   r   r   r   r   r   )r   rs   )r   r   )	r   r   r   r   r   r   propertyr   r   r   r   r   r   r      s          UY) ) ) ) ), , , , " " " X"       X     r   r   EMPTYFUNCCLASSEMPTY_CLASSVAR
NOT_IN_ALLz<ERROR>ERROR_MARKERc                  t     e Zd ZdZd fdZdd
Zd dZd!dZd"dZd#dZ	d$dZ
d%dZd&dZd'dZd(dZ xZS ))AliasPrinterzVisitor used to collect type aliases _and_ type variable definitions.

    Visit r.h.s of the definition to get the string representation of type alias.
    stubgenASTStubGeneratorr   r   c                V    || _         t                                                       d S r   )r   superr   )r   r   	__class__s     r   r   zAliasPrinter.__init__  s&    r   noder   rs   c                   |j                             |           }g }t          |j        |j        |j                  D ]\  }}}|t          k    r)|                    |                    |                      :|t          k    r,|                    d|                    |           z              q|t          k    r,|                    d|                    |           z              |t          k    r.|                    | d|                    |                       t          d| d          | dd                    |           dS )	N***=zUnknown argument kind z in call(, r   )calleeacceptzip	arg_namesargs	arg_kindsr   appendr   r   r   
ValueErrorjoin)r   r   r   r   nameargkinds          r   visit_call_exprzAliasPrinter.visit_call_expr  sH    ##D))"4>49dnMM 
	J 
	JOD#twCJJt,,----!!C#**T"2"223333""D3::d#3#334444""t88cjj&6&6889999 !H$!H!H!HIII--499T??----r   r0   c                X    | j         j                            |j                   |j        S r   )r   import_trackerrequire_namer   r   r   s     r   visit_name_exprzAliasPrinter.visit_name_expr"  s%    #00;;;yr   or.   c                   |}d}t          |t                    r)d|j        z   |z   }|j        }t          |t                    )t          |t                    st
          S | j        j                            |j                   |j        |z   S )N .)	
isinstancer.   r   exprr0   r   r   r   r   )r   r   r   trailers       r   visit_member_exprzAliasPrinter.visit_member_expr&  s    z** 	DIo/G9D z** 	 $)) 	 #00;;;y7""r   r5   c                *    t          |j                  S r   )reprvaluer   s     r   visit_str_exprzAliasPrinter.visit_str_expr1  s    DJr   r+   c                   |j                             |           }|j                            |           }t          |          dk    r4|                    d          r|                    d          r
|dd         }| d| dS )N   r   r      [])baser   indexlen
startswithendswith)r   r   r   r   s       r   visit_index_exprzAliasPrinter.visit_index_expr4  s    y%%
!!$''u::>>e..s33>s8K8K>!B$KE!!!!!!r   r7   c                X     dd                      fd|j        D                        dS )Nr   r   c              3  B   K   | ]}|                               V  d S r   r   .0nr   s     r   	<genexpr>z0AliasPrinter.visit_tuple_expr.<locals>.<genexpr><  -      @@QXXd^^@@@@@@r   r   r   itemsr   s   ` r   visit_tuple_exprzAliasPrinter.visit_tuple_expr;  7    C499@@@@TZ@@@@@CCCCr   r-   c                X     dd                      fd|j        D                        dS )Nr   r   c              3  B   K   | ]}|                               V  d S r   r   r   s     r   r   z/AliasPrinter.visit_list_expr.<locals>.<genexpr>?  r   r   r   r   r   s   ` r   visit_list_exprzAliasPrinter.visit_list_expr>  r   r   r    c                    g }|j         D ]\\  }}t          |t                    sJ |                    |                    |            d|                    |                       ]dd                    |           dS )N: {r   })r   r   r5   r   r   r   )r   r   
dict_itemskeyr   s        r   visit_dict_exprzAliasPrinter.visit_dict_exprA  s    
' 	K 	KJCc7+++++D!1!1IIU\\$5G5GIIJJJJ-DIIj))----r   r!   c                    dS )N...r   r   s     r   visit_ellipsiszAliasPrinter.visit_ellipsisI  s    ur   r1   c                    |j                             |            d|j         d|j                            |            S )N )leftr   oprightr   r   s     r   visit_op_exprzAliasPrinter.visit_op_exprL  s<    &--%%EEEEqw~~d/C/CEEEr   )r   r   r   r   )r   r   r   rs   )r   r0   r   rs   )r   r.   r   rs   )r   r5   r   rs   )r   r+   r   rs   )r   r7   r   rs   )r   r-   r   rs   )r   r    r   rs   )r   r!   r   rs   )r   r1   r   rs   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r     s        
     . . . .$   	# 	# 	# 	#       " " " "D D D DD D D D. . . .   F F F F F F F Fr   r   filer/   r   set[str]c                V    t                      }|                     |           |j        S r   )DefinitionFinderr   namesr  finders     r   find_defined_namesr	  P  s'    FKK<r   c                  *    e Zd ZdZddZddZdd	Zd
S )r  z:Find names of things defined at the top level of a module.r   r   c                ,    t                      | _        d S r   )setr  r   s    r   r   zDefinitionFinder.__init__[  s    "uu


r   r   r   c                D    | j                             |j                   d S r   r  addr   r   s     r   visit_class_defz DefinitionFinder.visit_class_def_      
qvr   r&   c                D    | j                             |j                   d S r   r  r   s     r   visit_func_defzDefinitionFinder.visit_func_defc  r  r   Nr   r   r   r   r   r   r   r&   r   r   )r   r   r   r   r   r  r  r   r   r   r  r  V  sV        DD% % % %        r   r  c                V    t                      }|                     |           |j        S r   )ReferenceFinderr   refsr  s     r   find_referenced_namesr  h  s'    FKK;r   r   r"   rp   c                B    t          | t                    o
| j        dk    S )Nr   )r   r0   r   )r   s    r   is_none_exprr  n  s    dH%%=$)v*==r   c                  `     e Zd ZdZddZd fdZdd
Zd fdZddZddZ	ddZ
ddZ xZS )r  z1Find all name references (both local and global).r   r   c                ,    t                      | _        d S r   )r  r  r   s    r   r   zReferenceFinder.__init__w  s    !ee			r   blockr   c                \    |j         s#t                                          |           d S d S r   is_unreachabler   visit_block)r   r  r   s     r   r#  zReferenceFinder.visit_block{  s6    # 	'GG&&&&&	' 	'r   er0   c                D    | j                             |j                   d S r   )r  r  r   )r   r$  s     r   r   zReferenceFinder.visit_name_expr  s    	afr   trV   c                    |                      |j        j                   t                                          |           d S r   )add_reftyper   r   visit_instance)r   r&  r   s     r   r*  zReferenceFinder.visit_instance  s7    QV[!!!q!!!!!r   rY   c                L    |j         r|                     |j                    d S d S r   )r   r(  )r   r&  s     r   visit_unbound_typez"ReferenceFinder.visit_unbound_type  s0    6 	!LL     	! 	!r   rW   c                D    |j         D ]}|                    |            d S r   )r   r   )r   r&  items      r   visit_tuple_typez ReferenceFinder.visit_tuple_type  s2    G 	 	DKK	 	r   rU   c                x    |j         D ]}|                    |            |j                            |            d S r   )	arg_typesr   ret_type)r   r&  r   s      r   visit_callable_typez#ReferenceFinder.visit_callable_type  sD    ; 	 	CJJt	
$r   fullnamers   c                    | j                             |           d|v r<|                    dd          d         }| j                             |           d|v :d S d S )Nr   r   r   )r  r  rsplit)r   r4  s     r   r(  zReferenceFinder.add_ref  s^    	hXoosA..q1HIMM(### Xoooooor   r  )r  r   r   r   )r$  r0   r   r   )r&  rV   r   r   )r&  rY   r   r   )r&  rW   r   r   )r&  rU   r   r   )r4  rs   r   r   )r   r   r   r   r   r#  r   r*  r,  r/  r3  r(  r   r  s   @r   r  r  r  s        ;;$ $ $ $' ' ' ' ' '   " " " " " "! ! ! !   
       $ $ $ $ $ $ $ $r   r  c                      e Zd ZdZ	 	 	 	 	 d^d_ fdZd` fdZdadZdbdZdcdZdddZ	dedZ
dfdZdgd!Zdgd"Zdhd&Zdi fd(Zdjd+Zdjd,Zdkd-Zdl fd/Zdmd1Zdnd3Zdnd4Zdod7Zdpd;Zdnd<Zdpd=Zdqd>ZdrdsdAZdtdBZdu fdDZdvdFZdwdHZ dxdJZ!	 dydzdMZ"d{dNZ#d|d}dQZ$d~dRZ%ddTZ&	 dddWZ'ddXZ(ddZZ)d fd]Z* xZ+S )r   z#Generate stub text from a mypy AST.NF_all_r   ry   rp   analyzedr   r   r   r   c                    t                                          ||||           g | _        g g| _        t          | _        d | _        || _        t                      | _	        d| _
        d S NF)r   r   _decorators_varsr   _state_current_classr9  r  method_namesprocessing_dataclass)r   r8  ry   r9  r   r   r   s         r   r   zASTStubGenerator.__init__  se     	>PQQQ&(')d
/3 &)ee$)!!!r   r   r/   c                   |j         | _        |j        | _        |                     t	          |                     t          |          | _        t                                          |           | 	                                 d S r   )
r4  module_namer   set_defined_namesr	  r  referenced_namesr   visit_mypy_filecheck_undefined_namesr   r   r   s     r   rF  z ASTStubGenerator.visit_mypy_file  ss    :F	1!44555 5a 8 8"""""$$$$$r   r2   c                   d}|j         D ]}t          |t                    s|                     |j        j        |j        j                  rC|                     |           |s)|                     |j                   |j        j	        rd}|j        j	        r|                     |j                   | 
                                 dS )zD@property with setters and getters, @overload chain and some others.FTN)r   r   r   is_private_namefuncr   r4  process_decoratorr  is_overloadclear_decorators)r   r   overload_chainr.  s       r   visit_overloaded_func_defz*ASTStubGenerator.visit_overloaded_func_def  s    G 	( 	(DdI.. ##DINDI4FGG ""4(((! (##DI...9( *%)N& (##DI.... %%''''	( 	(r   func_defr&   ctxrC   r=   c                    |                      ||          }|                     ||          }t          |j        ||          S r   )_get_func_args_get_func_returnr=   r   )r   rQ  rR  r   retnames        r   get_default_function_sigz)ASTStubGenerator.get_default_function_sig  s@    ""8S11''#668=$888r   list[ArgSig]c           
     F   g }t          |j                  D ]\  }}|j        }|j        }|j        }t          |j        t                    r|j        j        |         nd }	|dk    o|dk    }
|dk    o|dk    }d }|	r;|
s9|s7t          t          |	          t                    s|                     |	          }|                                r;t          d |D                       s"|                    t          d                     d}|j        rS|s|                     |j        dd          }|                     |j                  \  }}|rt'          |          d	k    r|}n!|t(          k    rd| }n|t*          k    rd
| }|                    t          ||t-          |j                  |                     |j        Gt1          d |D                       r.t3          |j        |j        j        d |D                       }||}| j        o"| j        o|j        j        |j                 j        }|j        dk    ra|r_d
d |D             v rQd                     d |D                       }|D ]/}|j        dk    rd| d|_        |j        d
k    rd
| d|_        0|S )Nr   r   clsc              3  J   K   | ]}|j                             d           V  dS r   N)r   r   r   r   s     r   r   z2ASTStubGenerator._get_func_args.<locals>.<genexpr>  s2      *T*T38+>+>s+C+C*T*T*T*T*T*Tr   r   r   TF   r   )defaultdefault_valuec              3  :   K   | ]}|j         d u o|j        du V  d S r;  )r)  r_  r]  s     r   r   z2ASTStubGenerator._get_func_args.<locals>.<genexpr>  sF       .
 .
:=CH5!5.
 .
 .
 .
 .
 .
r   c                    g | ]	}|j         
S r   r   r]  s     r   
<listcomp>z3ASTStubGenerator._get_func_args.<locals>.<listcomp>  s    3M3M3MCH3M3M3Mr   r   c                    g | ]	}|j         
S r   rc  r   as     r   rd  z3ASTStubGenerator._get_func_args.<locals>.<listcomp>  s    G]G]G]STG]G]G]r   r   c              3  J   K   | ]}|j                             d           V  dS r\  )r   striprf  s     r   r   z2ASTStubGenerator._get_func_args.<locals>.<genexpr>  s0      ??Qqv||C00??????r   ___)!	enumerate	argumentsvariabler   r   r   unanalyzed_typerU   r1  rZ   rT   print_annotationis_namedanyr   r<   initializerget_str_type_of_nodeget_str_default_of_noder   r   r   rp   
class_infoallrH   self_varr9  rA  infor  plugin_generatedr   )r   r   rR  r   iarg_varr   r   annotated_typeis_self_arg
is_cls_argtypenamer_  potential_defaultvalidnew_argsis_dataclass_generatednew_namer   s                       r   rT  zASTStubGenerator._get_func_args  s2    -- %	 %	GAt-C9D8D a/>>!+A..  q&3TV^Ka1DEMJ#'H Ek E* E "/."A"A7KK E#44^DDH}} )s*T*Tt*T*T*T'T'T )F3KK(((G 	# X#889I4QVWWH+/+G+GHX+Y+Y(!5 0S!233s::/G!!!4zz"""D{{KKtXtD4D/E/EU\]]]    >%# .
 .
AE.
 .
 .
 +
 +
% .#.13M3M3M3M3M H # Mad7aAFL<P<a 	 6Z$:tG]G]X\G]G]G]?]?]ww??$?????H 1 18s??.8CHHX%%0H000CHr   r   c                x   |j         dk    rgt          |j        t                    rMt          t	          |j        j                  t                    rd S |                     |j        j                  S |j        t          k    s|j         t          v rd S t          |j                   }||S t          |          st          |          r|                     d          }d}d}d}t          |          r|                     d          x}}n\t          |          D ]L\  }}	|j        )t#          |j                  s|                     d          }|	r|                     d          }Mt%          |          r|                     d          }| d| d| d| dS t%          |          s|j        t&          k    rdS d S )Nr   zcollections.abc.Generatorr   _typeshed.Incompleter   r   r   )r   r   ro  rU   rZ   r2  rT   rp  abstract_statusr   rk   rI   rO   rP   add_namerM   r   r  rN   r   )
r   r   rR  rV  generator_name
yield_name	send_namereturn_namer   in_assignments
             r   rU  z!ASTStubGenerator._get_func_return  s   6ZJq/@,$O$O/!*;*DEEwOO I t,,Q->-GHHH++qv9R/R/R 4'//N"" 	Q&?&B&B 	Q!]]+FGGNJI K(++ J)-7M)N)NN
YY+@+C+C J J'D-y,\$)5L5L,%)]]3I%J%J
$ J$(MM2H$I$I	#A&& D"mm,BCC$PPzPPYPP+PPPP#A&& 	1+<+L+L6tr   r   c                    |j         j         sd S |j         j         d         }t          |t                    r&t          |j        t                    r|j        j        S d S )Nr   )bodyr   r#   r   r5   r   )r   r   r   s      r   _get_func_docstringz$ASTStubGenerator._get_func_docstring8  sU    y~ 	4y~a dN++ 	#
49g0N0N 	#9?"tr   c                   | j         o"| j        o|j        j        |j                 j        }|r|j        dk    rd S |                     |j        |j                  s;|                     |j                  s!| 	                    |j                  r|j
        s|                                  d S |                                 r*| j        t          t          fvr|                     d           |                                 sNt#          |          }|D ]<\  }}|| j        v r|                     ||          }|r|                     |           =| j        It+          |j                  r|j        d         j        j        }nd}t1          | j        j        |          }nd }t3          | j        |j        |                     |          |j        t:          k    |          }	|                     |j                   |                     ||	          }
|                      |
| j!        |	          }| "                    ||j#        | j$        |	j%                  D ]}|                     |dz              |                                  t          | _        d S )Nr   
r   r   )rC  r   	docstringis_abstractrv  )is_coroutine
decoratorsr  )&r9  rA  ry  r  r   rz  rJ  r4  is_not_in_allis_recorded_namerM  rN  is_top_levelr>  r   r   r  find_self_initializersr@  get_initr?  r   rm  rn  rB   rC   rC  r  r  r   record_namerW  get_signaturessig_generatorsformat_func_defr  r<  r  )r   r   r  
self_initsinitr   	init_coderx  rv  rR  default_sigsigsoutputs                r   r  zASTStubGenerator.visit_func_def@  s   Mad7aAFL<P<a 	 " 	af
&:&:F  44	!!!&))	 %%af--	 78m	
 !!###F 	4;udm#C#CHHTNNN  "" 	(/22J) ( (e4,,, MM$66	 (HHY'''*1; ";q>27!"4#6#;XFFJJJ(..q11)\9!
 
 
 	   33As;;"";0CSII**q~$:JVYVc + 
 
 	$ 	$F HHVd]####r   r   c                    |                      |j        j        |j        j                  rd S |                     |           |                     |j                   d S r   )rJ  rK  r   r4  rL  r  r   s     r   visit_decoratorz ASTStubGenerator.visit_decoratorx  sW    QV_== 	Fq!!!AF#####r   c                   d|j         _        |j        D ]}t          |t          t
          f          s t          |          }|                     |          }|dv r|                     |d           `|dv r$d|j         _	        |                     |d           |dk    r)|                     |d           t          |j         _        |dv r|                    d          d	         }|s| j                            d
           |t          d          d         }|                     |d           |                     |pd
 dd           t          |j         _        O|t           v r%|                     |d           d|j         _        }|                    d          r|                     |d           dS )zsProcess a series of decorators.

        Only preserve certain special decorators such as @abstractmethod.
        F)zbuiltins.propertyzbuiltins.staticmethodzbuiltins.classmethodzfunctools.cached_propertyT)r   )zasyncio.coroutinezasyncio.coroutines.coroutineztypes.coroutinezabc.abstractmethod)zabc.abstractpropertyzabc.abstractstaticmethodzabc.abstractclassmethodr   r   abczabc.abstractNz.abstractmethodz.setter)rK  rM  original_decoratorsr   r0   r.   get_qualified_nameget_fullnameadd_decoratoris_awaitable_coroutiner   r  
rpartitionr   
add_importr   rQ   r   )r   r   	decoratorqualnamer4  
abc_modulebuiltin_decorator_replacements          r   rL  z"ASTStubGenerator.process_decorator~  s   
 #. &	A &	AIi(J)?@@ ))44H((33H    ""8$"????   
 15-""8$"????111""8$"???)4&&   
 &0055a8
! :'22599908^9L9L9N9N0O-""#@u"UUU""j&9E#J#J#JY]"^^^)4&&^++""8$"???%)""""9-- A""8%"@@@M&	A &	Ar   r   r"   rs   c                   | j         rPt          |t          t          f          r4|j        r-t          |j        t                    r|j        j        s|j        S t          |          }d|vrM| j	        j
                            |          }| j	        j                            ||          }||| j        vrd}n9|                    dd          \  }}| j	        j                            ||          }||n| d| }|S )z:Return the full name resolving imports and import aliases.r   Nbuiltinsr   )r9  r   r0   r.   r4  r   r:   is_suppressed_importr  r   
module_forgetreverse_aliasdefined_namessplit)r   r   r   real_module
real_shortname_moduleresolved_names          r   r  zASTStubGenerator.get_fullname  s    M	!4(J!788	! 	!  	3//		! 59I4R		! = !$''d??-8<<TBBK,:>>tTJJJ"z9K'K'K(&*jja&8&8#K-;??[YYK&1&9

+?\?\PZ?\?\r   r   c                b   || _         t          |j        j                  | _        d }|                                 r9| j        t          k    r)t          | j	                  }| 
                    d           |                     |          }|D ]"}| 
                    | j         d| d           #|                     |j                   |                     |          }|r|D ]}| j                            |           t%          |j        t(          t*          f          r@|j                            t/          |                     }|                    d|z              nh| j        ra|j        j        rU|j        j        sI|                    d           | j                            d           | j                            d           |rdd                    |           dnd	}| 
                    | j         d
|j         | d           |                                  | j         rJ|j!        rCtD          j#        $                    |j!                  }	| 
                    | j         |	 d           t          | j	                  }
| j%                            g            tM                      '                    |           | (                                 | j%        )                                 | j%        d                             |j                   t          | j	                  |
k    rW| j        tT          k    r|
d	| j	        |<   | j         r|j!        s | j	        d         d d         dz   | j	        d<   tT          | _        ntV          | _        tY                      | _        d| _-        d | _         d S )Nr  @z
metaclass=zmetaclass=abc.ABCMetar  r   r   r   r   class z:
r    ...
F).r?  find_method_namesdefsr  r@  r  r>  r   r   _outputr  get_class_decorators_indentr  r   get_base_typesr   r   r   	metaclassr0   r.   r   r   r   r9  ry  r  is_protocolr  r   indent_include_docstringsr  mypyutilquote_docstringr=  r   r  dedentpopr   r   r  rA  )r   r   sepr  d
base_typesr   metabasesr  r   r   s              r   r  z ASTStubGenerator.visit_class_def  s}   -afk:: 	4;%#7#7dl##CHHTNNN..q11
 	. 	.AHH,,q,,,----   ((++
 	7" 7 7#006666akHj#9:: 	4;%%l4&8&899DlT12222] 	4qv1 	4!&:L 	45666**5111,,U3330:B,DIIj)),,,,DL::::::;;;# 	5 	5	11!+>>IHH3i333444
""""

2af%%%t|!!{k))co$&S!, D D#'<#3CRC#88#CR %DKKDKEE$)!"r   cdefru   c           	        g }t          |           }|j        |j        z   D ]}t          |t          t
          f          r<|                     |          dk    r"|                    t          |                     [t          |t                    r)|                    |
                    |                     t          |t                    rE|                     |          r|                     |          }t          |j        d         t                    sJ |j        d         j        }|*|                    |                     d                     9d                    d |D                       }|                     d          }|                    | d|d	| d
           |                     |          r*|                    |
                    |                     |                    |                     d                     |j                                        D ]9\  }	}
|	dk    r|                    |	 d|

                    |                      :|S )z%Get list of base classes for a class.zbuiltins.objectr   Nr  r   c              3  .   K   | ]\  }}d |d| dV  dS )r   r   r   Nr   )r   fr&  s      r   r   z2ASTStubGenerator.get_base_types.<locals>.<genexpr>  s4      *Q*Qtq!?q??a???*Q*Q*Q*Q*Q*Qr   typing.NamedTupler   z, [z])r  r   )r   base_type_exprsremoved_base_type_exprsr   r0   r.   r  r   r  r+   r   r   is_namedtuple_get_namedtuple_fieldsr   r5   r   r  r   is_typed_namedtuplekeywordsr   )r   r  r  pr   	nt_fieldsr  
fields_strnamedtuple_namer   r   s              r   r  zASTStubGenerator.get_base_types  si    "
(4+GG  	M  	MD$: 677 M$$T**.???%%&8&>&>???D),, M!!$++a..1111D(++ M %%d++ M $ ; ;D A AI%dilG<<<<<#y|1H ("))$--8N*O*OPPP !%*Q*Qy*Q*Q*Q!Q!QJ&*mm4G&H&HO%%&X&X8&X&X*&X&X&XYYYY--d33 M%%dkk!nn5555 %%dmm4J&K&KLLL=..00 	; 	;KD%{""99Q99::::r   c                   g }t          |           }|j        D ]m}|                     |          rV|                    |                    |                     | j                            t          |                     d| _        n|S )NT)	r   r  is_dataclassr   r   r   r   r  rA  )r   r  r  r  r  s        r   r  z%ASTStubGenerator.get_class_decorators  s     "
 	1 	1A  ## 1!!!((1++...#001CA1F1FGGG,0)r   c                l    t          |t                    r|j        }|                     |          dk    S )Nzdataclasses.dataclass)r   r   r   r  r   r   s     r   r  zASTStubGenerator.is_dataclass$  s5    dH%% 	;D  &&*AAAr   r   c                \    |j         s#t                                          |           d S d S r   r!  rH  s     r   r#  zASTStubGenerator.visit_block)  s8      	#GG"""""	# 	#r   r   c                Z   g }|j         D ]}t          |t                    rt          |j        t                    r|                     |j                  s|                     |j                  r1|                     ||j                   |                    d           | 	                    |j                  r1| 
                    ||j                   |                    d           t          |t                    rX|                     |j                  s>|j        s7|                     |j                  r|                     ||j                   Ot          |t           t"          f          rB|j        }t          |j        t&                    r|j        j        }nd gt)          |          z  }n|g}|j        g}d}d}t+          ||          D ]\  }}	t          |t                    r|                     |j        |j        |	          }
|
rcd}|s0|                                 r| j        t2          t4          fvrd|
z   }
d}|                     |
           |                     |j                   |                    |           t;          |          rt4          | _        d S d S )NFTr  )lvaluesr   r0   rvaluer   r  r  process_namedtupler   is_typeddictprocess_typeddictrJ  r   ro  is_alias_expressionprocess_typealiasr7   r-   r   rW   r   r   r  r  r>  r   r   r  r  rw  )r   r   foundllvaluer   r   r  foundr.  
annotationr  s              r   visit_assignment_stmtz&ASTStubGenerator.visit_assignment_stmt/  s   i (	! (	!F&(++ 
18X0N0N %%ah// 43K3KAH3U3U ++FAH===MM%((($$QX.. **618<<<MM%(((68,,,,V[99 )	
 ,,QX66 &&vqx888&9h"788 2a/;; 69:9J9PKK#'&3u::"5KK 01CE$'{$;$; 	4 	4 jdH-- 4==AHjIID 4 $" 't'8'8':': 't{SXZ]R^?^?^#'$;D"&C((333MM%    v;; 	DKKK	 	r   r   c                >    |                      |j                  dk    S )Nzcollections.namedtuple)r  r   r  s     r   r  zASTStubGenerator.is_namedtuple_  s      --1IIIr   c                D    |                      |j                  t          v S r   )r  r   rS   r  s     r   r  z$ASTStubGenerator.is_typed_namedtupleb  s      --1GGGr   calllist[tuple[str, str]] | Nonec                  	 |                      |          r|j        d         }t          |t                    r.|j                            dd                                          }n]t          |t          t          f          r?g }|j	        D ]4}t          |t                    s d S |
                    |j                   5nd S |r#|                     d          		fd|D             S g S |                     |          r|j        d         }t          |t          t          f          sd S g }t          |           }|j	        D ]}t          |t                    rt          |j	                  dk    s d S |j	        \  }}t          |t                    s d S |
                    |j        |                    |          f           |S d S )Nr   ,r   r  c                    g | ]}|fS r   r   )r   
field_name
incompletes     r   rd  z;ASTStubGenerator._get_namedtuple_fields.<locals>.<listcomp>t  s    OOOZZ0OOOr   r   )r  r   r   r5   r   replacer  r-   r7   r   r   r  r  r   r   r   )
r   r  
fields_argfield_namesfieldfieldsr  r  
field_typer  s
            @r   r  z'ASTStubGenerator._get_namedtuple_fieldse  s   d## !	1J*g.. 	(.66sC@@FFHHJ9(=>>  '- 4 4E%eW55 $#tt&&u{33334
 t !]]+ABB
OOOO;OOOO	%%d++ 	1Jj8Y*?@@ t,.FT""A#) H H"5)44  U[9I9IQ9N9N44).&
J!*g66  44z/1B1B11E1EFGGGGM4r   r  r0   r  c           	        | j         t          k    r|                     d           t          |j        d         t
                    s|                     |           d S |                     |          }||                     |           d S |                     d          }| j	         d|j
         d| d}t          |          dk    r&|                     | d           t          | _         d S | j         t          t          fvr|                     d           |                     | d           |D ](\  }}|                     | j	         d| d	| d           )t          | _         d S )
Nr  r   r  r  r   ):r      r   )r>  r   r  r   r   r5   annotate_as_incompleter  r  r  r   r   r   r   )r   r  r  r	  r  	class_deff_namef_types           r   r  z#ASTStubGenerator.process_namedtuple  sv   ;%HHTNNN&+a.'22 	''///F,,V44>''///F122|BB6;BBBBB	v;;!HH	)))***%DKKK{5%.00HH	%%%&&&"( D DDLBBfBBBBBCCCCDKKKr   c                D    |                      |j                  t          v S r   )r  r   rR   r  s     r   r  zASTStubGenerator.is_typeddict  s      --==r   c           
        | j         t          k    r|                     d           t          |j        d         t
                    s|                     |           d S g }d }t          |j                  dk    r|j        d         t          k    rt          |j        d         t                    s|                     |           d S |j        d         j        D ]N\  }}t          |t
                    s|                     |            d S |                    |j        |f           Ot          |j                  dk    rK|j        d         t          k    s|j        d         dk    r|                     |           d S |j        d         }n}t!          |j        dd          |j        dd                    D ]R\  }}t          |t"                    s|                     |            d S |dk    r|};|                    ||f           St%          |           }	t'          d |D                       rH|                     | j         |j         d|                    |	           d           t.          | _         d S |                     d          }
||
d	|                    |	           z  }
| j         d
|j         d|
 d}t          |          dk    r&|                     | d           t2          | _         d S | j         t4          t          fvr|                     d           |                     | d           |D ];\  }}|                     | j         d| d|                    |	           d           <t          | _         d S )Nr  r   r   r   totalc              3  n   K   | ]0\  }}|                                  pt          j        |          V  1d S r   )isidentifierkeyword	iskeyword)r   r   rj  s      r   r   z5ASTStubGenerator.process_typeddict.<locals>.<genexpr>  sE      TTFC3##%%%?):3)?)?TTTTTTr    = ztyping_extensions.TypedDictz, total=r  r   r  r  r  r   )r>  r   r  r   r   r5   r  r   r   r   r    r   r   r   r   r   r   rs   r   rr  r  r   r   r   r  r   r   )r   r  r  r   r  	attr_name	attr_typearg_namer   r  r  r  r   key_types                 r   r  z"ASTStubGenerator.process_typeddict  s   ;%HHTNNN&+a.'22 	''///F.0#'v{aF$4Q$77$B$Bfk!nh77 ++F333(.A(< ; ;$	9!)W55 //777FFioy9::::6;!###A&)33v7G7Jg7U7U//777FA!$V%5abb%96;qrr?!K!K 2 2#!(C00 //777FFw&&EELL(C1111TTeTTTTT 	$HHJfkJJfmmA6F6FJJJKKKDKKKMM"?@@E 5ELLOO555<FFv{FFUFFFI5zzQI---...);uen44HHTNNNI)))***%* Q QMCHHOO#OO9K9KOOOPPPP#r   c                    |                      d          }|                     | j         |j         d| d           t          | _        d S )Nr  r   r  )r  r  r  r   r   r>  )r   r  r  s      r   r  z'ASTStubGenerator.annotate_as_incomplete  sK    ]]#9::
DL?&+?????@@@r   T	top_levelc                &    t          |t                    r                     |j                  dv rdS t          |t                    r| S t          |t
                    r4|j        dv rdS |j        dk    r| S                      |j                   S t          |t                    rj j	        rc|r't          |j
        t          t          t          f          pt          |j
        t                    o                     |j
        j                   S t          |t"                    rt          |j        t
                    r͉                     |j        j                  st          |j        t(                    r|j        j        }n|j        g}|j        j        dk    rTt-          |          dk    rA|\  }}t          |t                    r|g}n#t          |t.                    r|j        |gz   }ndS t1           fd|D                       S dS )	zReturn True for things that look like target for an alias.

        Used to know if assignments look like type aliases, function alias,
        or module alias.
        )ztyping.TypeVarztyping_extensions.TypeVarztyping.ParamSpecztyping_extensions.ParamSpecztyping.TypeVarTupleztyping_extensions.TypeVarTupleTTrueFalseFr   Callabler   c              3  F   K   | ]}                     |d           V  dS )F)r  N)r  )r   r{  r   s     r   r   z7ASTStubGenerator.is_alias_expression.<locals>.<genexpr>  s6      UUt//U/CCUUUUUUr   )r   r   r  r   r!   r0   r   rJ  r.   r9  r   r&   r   r/   r8   is_private_memberr4  r+   r   r   r7   r   r   r-   rw  )r   r   r  indicesr   rets   `     r   r  z$ASTStubGenerator.is_alias_expression  s%    dH%% ,	$*;*;DK*H*H M
 +
 +
 4l++ #	 = h'' !	y---uf$$$}$//	::::j)) 	dm 	  Jty7Ix*HII3di22A ,,TY-?@@@	A tY''	49h//	 ((88	
 $*i00 '**:,y~++G0A0A#	cdL11 !"eGGh// !"jC50GG 5UUUUWUUUUUU5r   c                   t          |           }|                     | j         |j         d|                    |           d           |                     |j                   | j        d                             |j                   d S )Nr  r  r   )r   r  r  r   r   r  r=  r   )r   r  r  r  s       r   r  z"ASTStubGenerator.process_typealias  s    DLF&+FF&--2B2BFFFGGG%%%
2fk*****r   r'   c                f   |j         d         }t          |t                    rlt          |j        d         t                    rLt          |j        d         t
                    r,|j        d         j        dk    rd|j        d         j        v rd S t                      	                    |           d S )Nr   r   r   __main__)
r   r   r   operandsr0   r5   r   r   r   visit_if_stmt)r   r   r   r   s      r   r-  zASTStubGenerator.visit_if_stmt  s    vayt^,,	4=+X66	 4=+W55	 a %33dmA.444Fa     r   r)   c                V    |                      dd|j        z   |j         d           d S )Nzfrom r   z
 import *
)add_import_linerelativeidr   s     r   visit_import_allz!ASTStubGenerator.visit_import_all*  s6    HS1:%5HqtHHHIIIIIr   r*   c                N    t                      }g }t          |j        |j                  \  }} j        rGt
          j                             j        || j        	                    d                    \  }}|s|}n|}|dk    rd S |j
        D ]{\  }}	|dk    r$                     t          dg                     /                     |||	d u          r j                            |           |}	|                    ||	f           | j                            d|z  |z   |            j        d                             d |D                        |D ]\  }}
                     |
p|            j        r* fd|j
        D             }|                    |           d S d S )	Nz.__init__.py
__future__six)r5  Nr   r   c              3  $   K   | ]\  }}|p|V  d S r   r   )r   r   aliass      r   r   z5ASTStubGenerator.visit_import_from.<locals>.<genexpr>E  s*      LLeemtLLLLLLr   c                B    g | ]\  }}|j         v ||j        v|S r   )r8  IGNORED_DUNDERS)r   r   r7  r   s      r   rd  z6ASTStubGenerator.visit_import_from.<locals>.<listcomp>K  sE       D%4:%%%-DH\<\<\ <\<\<\r   )r  translate_module_namer1  r0  rC  r  r  correct_relative_importr   r   r  visit_importr(   should_reexportr   reexportr   add_import_fromr=  extendr  r8  update)r   r   exported_namesimport_namesr   r0  full_moduleokr   as_namer7  r  s   `           r   visit_import_fromz"ASTStubGenerator.visit_import_from-  s   #&550qzBB 	!"i?? (FDI4F4F~4V4V OK  %$ K\!!FW 	1 	1MD'u}}!!&-"9"9:::##D+wd7JKK #,,T222w0000++C(NV,C\RRR
2LL|LLLLLL' 	, 	,KD%U]d++++: 	)   #$7  E
 !!%(((((	) 	)r   r(   c                    |j         D ]u\  }}| j                            ||           ||                    d          d         }n|}| j        d                             |           |                     |           vd S )Nr   r   r   )idsr   r  r  r=  r   r  )r   r   r1  as_idtarget_names        r   r<  zASTStubGenerator.visit_importR  s     	* 	*IB**2u555} hhsmmA.#JrN!!+...[))))	* 	*r   r  Type | Nonec                ^   || j         d         v rdS |                     |          s|                     |          rdS | j         d                             |           ||                     |          }t          |t                    rV|j        sO|j        dk    rD| j	        j
                            d          | j        v r|                     |          }|d| dz  }n(| j        r| j         | dS |                     |          }|                     |          }| j         | d| | dS )	zReturn initializer for a variable.

        Return None if we've generated one already or if the variable is internal.
        r   Nr   r   r   z = ...
r   r  )r=  rJ  r  r   rp  r   rY   r   r   r   r  r  TYPING_MODULE_NAMESrt  rA  r  get_assign_initializer)r   r  r  r  r  	final_argrs  s          r   r  zASTStubGenerator.get_init\  s`    TZ^##4'' 	4+=+=f+E+E 	4
2f%%%!,,Z88H:{33-"- Ow..'266w??4C[[[ !55f==	,	,,,,& 	9l4F44440088H11&99,CCC(CKCCCCr   c                    | j         sdS | j         j        r(| j         j        j        rt          |t                    sdS | j        rt          |t                    r|j        sdS dS )z5Does this rvalue need some special initializer value?r   z = ...)r?  ry  is_named_tupler   r6   rA  no_rhs)r   r  s     r   rO  z'ASTStubGenerator.get_assign_initializer}  s    " 	2
 $	#(7	 vx00	
 8$ 	j.J.J 	v} 	8 rr   r   r   c                x    |r| j                             |           | j                            d|            d S )Nr  )r   r   r<  r   )r   r   r   s      r   r  zASTStubGenerator.add_decorator  sD     	3,,T222
D

+++++r   c                8    | j                                          d S r   )r<  clearr   s    r   rN  z!ASTStubGenerator.clear_decorators  s         r   r4  c                d     |                     d          }t           fd|D                       S )Nr   c              3  B   K   | ]}                     |          V  d S r   )rJ  )r   partr   s     r   r   z5ASTStubGenerator.is_private_member.<locals>.<genexpr>  s1      @@$4''--@@@@@@r   )r  rr  )r   r4  partss   `  r   r&  z"ASTStubGenerator.is_private_member  s7    s##@@@@%@@@@@@r   can_infer_optional
can_be_anyc                   |                      |          }t          |t                    rdS t          |t                    rdS t          |t                    rdS t          |t
                    rdS t          |t                    rdS t          |t                    re|j        dv r\t          |                      |j	                  t                    s-t          |                      |j
                  t                    rdS t          |t                    r|j        dv rdS |r8t          |t                    r#|j        d	k    r|                     d
           dS |r|                     d
          S dS )Nintrs   bytesfloatcomplex)-+r!  rp   r   r  z | Noner   )maybe_unwrap_unary_exprr   r,   r5   r   r$   r   r1   r   r   r   r0   r   r  )r   r  r[  r\  s       r   rt  z%ASTStubGenerator.get_str_type_of_node  s    --f55fg&& 	5fg&& 	5fi(( 	7fi(( 	7fk** 	9ff%% 	!&)z*A*A$66v{CC[QQ !U_,,V\::KV V ! !yfh'' 	FK;L,L,L6 	E*VX">"> 	E6;RXCXCXmm$:;;DDDD 	==!78882r   c                F   t          |t                    s|S d}|j        |v rjt          |t                    rS|j        |vs-t          |j        t          t
          t          t          f          sn|j        }t          |t                    S|S |j        dk    rt          |t                    rr|j        dk    s!t          |j        t          t          f          snEt          |j        t                    r|j        j        dvrn|j        }t          |t                    r|S |S )a
  Unwrap (possibly nested) unary expressions.

        But, some unary expressions can change the type of expression.
        While we want to preserve it. For example, `~True` is `int`.
        So, we only allow a subset of unary expressions to be unwrapped.
        )rc  rb  notr!  )	r   r9   r   r   r,   r$   r   r0   r   )r   r   math_opss      r   rd  z(ASTStubGenerator.maybe_unwrap_unary_expr  s*    $	** 	K 7hT9-- !7(***IKK3 3* y T9-- ! K 7eT9-- !7e##:di(IAV+W+W#di22 ty~M^7^7^y T9-- ! K r   tuple[str, bool]c                ,   t          |t                    r|j        dv r	|j        dfS nt          |t          t          f          r
|j         dfS t          |t                    r:t          |j        t          t          f          r|j         |j        j         dfS nut          |t                    rt          |j                  dfS t          |t                    r-dt          |j                                      dd          z   dfS t          |t                    rug }|j        D ]3}|                     |          \  }}|s nL|                    |           4t#          |          dk    rdnd}d	d
                    |          z   |z   }|dfS n~t          |t&                    r^g }|j        D ]3}|                     |          \  }}|s n5|                    |           4dd
                    |          z   dz   }|dfS nt          |t(                    r_g }|j        D ]3}|                     |          \  }}|s n7|                    |           4|rdd
                    |          z   dz   }|dfS nt          |t*                    rg }|j        D ]Y\  }}	| np|                     |          \  }
}|                     |	          \  }}|r|s n:|                    |
 d|            Zdd
                    |          z   dz   }|dfS dS )zGet a string representation of the default value of a node.

        Returns a 2-tuple of the default and whether or not it is valid.
        )r   r"  r#  Tbz\\\r   z,)r   r   r   r   r   r   r   Nr   )r   F)r   r0   r   r,   r$   r   r9   r   r   r5   r   r   r  r7   r   ru  r   r   r   r-   r3   r    )r   r  items_defaultsr$  	e_defaultr  closingr_  kv	k_defaultk_valid	v_defaultv_valids                 r   ru  z(ASTStubGenerator.get_str_default_of_node  s   
 fh'' 8	%{777{D(( 8) 455 5	%l$d**	** 3	%&+';<< ? )8V[%688$>>?(( 0	%%%t++	** .	%fl++33FDAAA4GG	** ,	%N\ % %#'#?#?#B#B 	5 E%%i0000"%n"5"5":":$$		. 9 99GC}$  )) !	%N\ % %#'#?#?#B#B 	5 E%%i0000		. 9 99C?}$	 
 (( 	%N\ ) )#'#?#?#B#B 	5 E%%i0000! )!DIIn$=$==CG"D=()) 	%N 
% 
%19E%)%A%A!%D%D"	7%)%A%A!%D%D"	7 G E%%&A&Ai&A&ABBBB		. 9 99C?}$|r   rD  name_is_aliasc                    |                      ||dz   |z             }|s)|| j        vr | j        r	|| j        v r|s|d| j        z   vrdS t                                          |||          S )Nr   )r  asyncioT)rJ  rE  r8  r9  rN  r   r=  )r   r   rD  ru  
is_privater   s        r   r=  z ASTStubGenerator.should_reexport  s    ))$c0AD0HII

	D111Z 2#'4+?#?#? $@#58P#PPP
 4ww&&t[-HHHr   )NFFFF)r8  r   ry   rp   r9  rp   r   rp   r   rp   r   r   )r   r/   r   r   )r   r2   r   r   )rQ  r&   rR  rC   r   r=   )r   r&   rR  rC   r   rX  )r   r&   rR  rC   r   r   )r   r&   r   r   r  )r   r   r   r   )r   r"   r   rs   r  )r  r   r   ru   r   r"   r   rp   )r   r   r   r   r   r   r   r   )r   r   r   rp   )r  r   r   r  )r  r0   r  r   r   r   )r  r0   r   r   )T)r   r"   r  rp   r   rp   )r  r0   r  r"   r   r   )r   r'   r   r   )r   r)   r   r   )r   r*   r   r   )r   r(   r   r   r   )r  rs   r  r"   r  rL  r   r   )r  r"   r   rs   )F)r   rs   r   rp   r   r   r  )r4  rs   r   rp   )FT)r  r"   r[  rp   r\  rp   r   rs   )r   r"   r   r"   )r  r"   r   rh  )r   rs   rD  rs   ru  rp   r   rp   ),r   r   r   r   r   rF  rP  rW  rT  rU  r  r  r  rL  r  r  r  r  r  r#  r  r  r  r  r  r  r  r  r  r  r-  r2  rG  r<  r  rO  r  rN  r&  rt  rd  ru  r=  r   r  s   @r   r   r     s       -- #' %!#(* * * * * * **% % % % % %( ( ( ((9 9 9 9
> > > >@! ! ! !F   6 6 6 6p$ $ $ $,A ,A ,A ,A\   *,# ,# ,# ,# ,# ,#\) ) ) )V   B B B B
# # # # # #. . . .`J J J JH H H H" " " "H       4> > > >5$ 5$ 5$ 5$n   
3 3 3 3 3j+ + + +! ! ! ! ! !J J J J#) #) #) #)J* * * * JND D D D DB   (, , , , ,
! ! ! !A A A A
 X\    :       D> > > >@I I I I I I I I I Ir   r   r  list[Statement]c                z   t                      }| D ]}t          |t                    r|                    |j                   2t          |t
                    r |                    |j        j                   gt          |t                    r-|j        D ]%}|	                    t          |g                     &|S r   )r  r   r&   r  r   r   rK  r2   r   rA  r  )r  resultdefnr.  s       r   r  r  ,  s    UUF 9 9dG$$ 	9JJty!!!!i(( 	9JJty~&&&&/00 	9
 9 9/778888Mr   c                      e Zd ZddZd	dZdS )
SelfTraverserr   r   c                    g | _         d S r   )resultsr   s    r   r   zSelfTraverser.__init__;  s    57r   r   r   c                    |j         d         }t          |t                    rRt          |j        t                    r:|j        j        dk    r,| j                            |j        |j        f           d S d S d S d S )Nr   r   )	r  r   r.   r   r0   r   r  r   r  )r   r   r  s      r   r  z#SelfTraverser.visit_assignment_stmt>  s    1vz**	96;11	9  F**Lah 788888	9 	9 	9 	9 +*r   Nr  rz  )r   r   r   r   r  r   r   r   r  r  :  s<        8 8 8 89 9 9 9 9 9r   r  fdefr%   list[tuple[str, Expression]]c                V    t                      }|                     |           |j        S )znFind attribute initializers in a method.

    Return a list of pairs (attribute name, r.h.s. expression).
    )r  r   r  )r  	traversers     r   r  r  H  s(    
 IKK	r   r   rs   c                    t          | t                    r| j        S t          | t                    rt	          | j                   d| j         S t          S )Nr   )r   r0   r   r.   r  r   r   )r   s    r   r  r  R  sS    !X v	Az	"	" $QV,,77qv777r   r{   list[StubSource]c                    d | D             S )Nc                H    g | ]}|j         t          |j                   | S r   )r   is_blacklisted_pathr   r   s     r   rd  z.remove_blacklisted_modules.<locals>.<listcomp>\  s8       (;CVW]WbCcCc(;(;(;(;r   r   )r{   s    r   remove_blacklisted_modulesr  [  s#     $   r   )tuple[list[StubSource], list[StubSource]]c                    g }g }| D ]A}t          |j                  r|                    |           ,|                    |           B||fS r   )r   r   r   )r{   
py_modulespyc_modulesmods       r   split_pyc_from_pyr  a  sf    JK # #sx   	#s####c""""
""r   r   c                D     t           fdt          D                       S )Nc              3  @   K   | ]}|t                    d z   v V  dS )r  N)normalize_path_separators)r   substrr   s     r   r   z&is_blacklisted_path.<locals>.<genexpr>m  s6      ZZfv3D99D@AZZZZZZr   )rr  rb   r   s   `r   r  r  l  s'    ZZZZPYZZZZZZr   c                R    t           j        dk    r|                     dd          S | S )Nwin32rk  /)sysplatformr  r  s    r   r  r  p  s(    
|w||D#&&&Kr   options	mypy_optsMypyOptions;tuple[list[StubSource], list[StubSource], list[StubSource]]c                   | j         s| j        rZ| j        r)t          | j        | j         | j        | j                  }g }n~t          | j        | j         | j        | j                  \  }}nT	 t          | j
        |          }n/# t          $ r"}t          t          |                    |d}~ww xY wd |D             }g }t          |          }t          |          \  }}|||fS )zsCollect files for which we need to generate stubs.

    Return list of py modules, pyc modules, and C modules.
    Nc                B    g | ]}t          |j        |j                  S r   r   r   r   r   ms     r   rd  z)collect_build_targets.<locals>.<listcomp>  s&    HHHqj1622HHHr   )r\   r{   ro   find_module_paths_using_searchrt   rm   find_module_paths_using_importsr}   r~   r
   r|   r	   
SystemExitrs   r  r  )r  r  r  	c_modulessource_listr$  pyc_modpy_mods           r   collect_build_targetsr  v  s
     7?  		7!173FHY J +-II %D!17?GM% %!J		
	,,W]IFFKK  	, 	, 	,SVV$$!+	,HHKHHH
	+J77J'
33OGV7I%%s   *B   
B,
B''B,ru   r\   r}   r~   c           	     R   t                      5 }g }g }t          t          |||                    }| |z   } d | D             } | D ]}	 t          |||          }	nc# t          $ rV}
t          j                    }|rt          j        	                    |           |st          ||
j        |           Y d}
~
pd}
~
ww xY w|	s#|                    t          |                     |	\  }}|                    t          |||                     ||fcddd           S # 1 swxY w Y   dS )zFind path and runtime value of __all__ (if possible) for modules and packages.

    This function uses runtime Python imports to get the information.
    c                0    g | ]}t          |          |S r   )is_non_library_module)r   r  s     r   rd  z3find_module_paths_using_imports.<locals>.<listcomp>  s6     
 
 
*?*D*D

 
 
r   N)r   listrL   rF   rA   	traceback
format_excr  stdoutwriterK   messager   r   )r{   r\   r}   r~   rq   r  r  r  r  r}  r$  tbr   r   s                 r   r  r    s    
 %G')
&(	]7Hg>>??E/
 
"
 
 
  	F 	FC5gsGLL   )++ )J$$R((( 7"3	2666  F  C1111$*!k!!*S$"D"DEEEE9$/% % % % % % % % % % % % % % % % % %s=   8DAD
B:$AB50D5B::ADD #D r   c                    |                      d          rdS |                     d          d                             d          rdS d| v sd| v sd| v sd	| v rdS d
S )z0Does module look like a test module or a script?)z.testsz.testz.testing_tests_test_suite	test_util
test_utils	test_basez	.__main__z	.conftestz.setupTr   r   test_z.tests.z.test.z	.testing.z
.SelfTest.F)r   r  r   r   s    r   r  r    s    	
   t||C''00 tVv&  6!!t5r   r0  r^  tuple[str, int]c                    t           D ]m}dD ]h}| d| }|                     d|z             s| |k    r
|r|dfc c S d|z   dz   | v r-|dz   |                     d|z   dz             d         z   dfc c S in| |fS )N)z	six.movesr5  r   r   r   )ra   r   	partition)r   r0  pkgaltr  s        r   r:  r:    s     N N% 	N 	NC^^c^^FsV|,, 61A1Ah1AAvV|c!V++Sy6#3#3C&L34F#G#G#JJAMMMMMM ,		N 8r   rt   rm   rn   c                z   g }t          t          j                                        |d          }t	          dt          |          z   ddt          |                    }t          |dd          }| D ]d}|                    |          }	t          |	t                    rt          ||	           d}
n|	}
|                    t          ||
                     e|D ]T}|                    |          }|rt          |t          j                   d |D             }|                    |           Ud |D             }|S )a  Find sources for modules and packages requested.

    This function just looks for source files at the file system level.
    This is used if user passes --no-import, and will not find C modules.
    Exit if some of the modules or packages can't be found.
    N)r   r   )fscacher  c                B    g | ]}t          |j        |j                  S r   r  r  s     r   rd  z2find_module_paths_using_search.<locals>.<listcomp>  s&    BBBA:ah//BBBr   c                :    g | ]}t          |j                  |S r   )r  r   r  s     r   rd  z2find_module_paths_using_search.<locals>.<listcomp>  s(    GGGA'<QX'F'FGaGGGr   )r   r  r   default_data_dirr   tupler   find_moduler   r   rE   r   r   find_modules_recursive	NOT_FOUNDr@  )r{   r\   rt   rm   r}  typeshed_pathsearch_pathscacher   m_resultmodule_pathpackagep_resultsourcess                 r   r  r    sS     "F$TZ%@%@%B%BItTTMvk(:(::BE-DXDXYYLL$EEEE 7 7$$V,,h 455 	#***KK"Kj556666  //88 	B"6"@AAABBBBBgGGGGGFMr   stubgen_optionsc                p   t                      }d|_        d|_        d|_        d|_        | j        |_        d|_        t          |_	        d|_
        | j        |_        t          j        dd          }|                                r||_        t          j                            |j                  |_        |S )z4Generate mypy options using the flag passed by user.skipFTMYPY_CACHE_DIRr   )r  follow_importsincrementalrx   semantic_analysis_onlyrm   python_versionshow_tracebackrJ   transform_sourcepreserve_astsr   osgetenvri  	cache_dirr   
expanduser)r  r  environ_cache_dirs      r   mypy_optionsr    s    mmG#GG G%)G",6G!G=G G!0!CG 	"2B77   .-**7+<==GNr   r  r  r   c                T   | j         
J d            t          | j         d          5 }|                                }ddd           n# 1 swxY w Y   t          j                            |          }t          |          }t          j                            || j         | j        ||          | _	        | j        | j	        _
        |                                rO|                                D ]$}t          j                            | d           %t          j        d           dS dS )zParse a source file.

    On success, store AST in the corresponding attribute of the stub source.
    If there are syntax errors, print them and exit.
    N Not found module was not skippedrb)fnamr   errorsr  r  r   )r   openreadr  r  decode_python_encodingr   parser   r   	_fullnameis_blockersnew_messagesr  stderrr  exit)r  r  r  datar   r  r  s          r   parse_source_filer    sR    8!C	ch		 vvxx              Y--d33FL!!FjSXcj   CG 
CG $$&& 	' 	'AJXXX&&&&	 s   AAAr  rw   c                   | sdS |r t          dt          |            d           |r| D ]}t          ||           dS 	 t          d | D             |          }n%# t          $ r}t          d|           |d}~ww xY w| D ]F}|j        |j                 j        |_	        |j
        !|j        j        j        |j                 |_
        GdS )z8Use mypy to parse (and optionally analyze) source files.NzProcessing z	 files...c                    g | ]	}|j         
S r   r   r  s     r   rd  z-generate_asts_for_modules.<locals>.<listcomp>;  s    <<<vV]<<<r   z)Critical error during semantic analysis: )printr   r  r   r   r  graphr   treer   r   managersemantic_analyzer
export_map)r  rw   r  r}   r  resr$  s          r   generate_asts_for_modulesr  -  s      86C
OO666777  	1 	1Cc<0000Q<<<<<lKK Q Q QHQHHIIqPQ  S S)CJ',?"!k;FszRCO	S Ss   A 
A>&A99A>Fr   )rw   rq   ry   r   r   rr   targetrq   ry   r   r   rr   all_modulesc          	     v   |rIt          | j        || j        ||||          }	|	                                 |	                                }
nYt          | j        || ||          }| j        
J d            | j                            |           |                                }
t          j	        
                    |          }|r3t          j	                            |          st          j        |           t          |dd          5 }|                    |
           ddd           dS # 1 swxY w Y   dS )zUse analysed (or just parsed) AST to generate type stub for single file.

    If directory for target doesn't exist it will created. Existing stub
    will be overwritten.
    )rC  known_modulesr8  rr   ry   r   r   )ry   r9  r   r   Nz5This function must be used only with analyzed moduleswzutf-8)encoding)r>   r   r   generate_moduler  r   r   r   r  r   dirnameisdirmakedirsr  r  )r  r  rw   rq   ry   r   r   rr   r  ngenr  gensubdirr  s                 r   generate_stub_for_py_moduler  F  s   "  &
%/+#1
 
 
 	 O+#^#1
 
 
 w""$["""s W__V$$F bgmmF++ 
F	fcG	,	,	, 

6                 s   D..D25D2c                  
 t          |           }t          | |          \  }}}||z   |z   }t          d |D                       }t          || j        || j                   g }||z   D ]

j        
J d            
j                            dd          }t          j        
                    
j                  dv r|dz  }n|dz  }t          j                            | j        |          }|                    |           t          
j        || j        | j                  5  t!          
|| j        | j        p
|v | j        | j        | j        | j        |		  	         ddd           n# 1 swxY w Y   |D ]
t-          
fd
|D                       r
j                            dd          dz   }n
j                            dd          dz   }t          j                            | j        |          }|                    |           t          
j        || j        | j                  5  t/          
j        ||| j        | j        | j        | j                   ddd           n# 1 swxY w Y   t1          |          }	| j        ss|	dk    rot5          d|	z             t1          |          dk    rt5          d|d                     dS t5          dt7          |           t          j        z              dS dS dS )z!Main entry point for the program.c              3  $   K   | ]}|j         V  d S r   r  r  s     r   r   z!generate_stubs.<locals>.<genexpr>}  s$      <<1ah<<<<<<r   Nr  r   r  )z__init__.pyz__init__.pycz/__init__.pyiz.pyi)rw   rq   ry   r   r   rr   r  c              3  \   K   | ]&}|j                             j         d z             V  'dS )r   N)r   r   )r   r  r  s     r   r   z!generate_stubs.<locals>.<genexpr>  s:      TTfv}''
S(899TTTTTTr   )r  rr   ry   r   r   r   zProcessed %d modulesr   z
Generated zGenerated files under )r  r  sortedr  rw   r}   r   r   r  r  basenamer   rz   r   rG   rx   r  rq   ry   r   r   rr   rr  r?   r   r~   r  rD   r  )r  r  r  r  r  r  all_module_namesr|   r  num_modulesr  s             @r   generate_stubsr  x  s   W%%I)>w	)R)R&JY{*Y6K<<<<<<<j'*<iYYYEK'  x##%G#####C--7CH%%)HHHo%FFfFg0&99Vcj&'2GYY 	 	'"-=3++= ' 7#/#*#=,
 
 
 
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   TTTTTTTTT 	;Z''S11OCFFZ''S11F:Fg0&99Vcj&'2GYY 		 		&
. ' 7#/#*#=   		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 k""K= P[1__${2333u::??)uQx))*****E+<U+C+CEENOOOOOP P__s$   $;E++E/	2E/	/0I++I/	2I/	z^%(prog)s [-h] [more options, see -h]
                     [-m MODULE] [-p PACKAGE] [files ...]z
Generate draft stubs for modules.

Stubs are generated in directory ./out, to avoid overriding files with
manual changes.  This directory is assumed to exist.
r   c           	     J   t          j        dt          t                    }|                    ddd           |                    ddd           |                    d	d
ddd           |                    dddd           |                    ddd           |                    ddd           |                    ddd           |                    dddd           |                    dddd           |                    dddd !           |                    d"ddd#!           |                    d$d%dd&d'd()           |                    d*d+d,d-d.g d/0           |                    d1d2d,d3d4g d50           |                    d6d7d6d89           |                    |           }t          j        d d:         }t          j        |_	        |j
        |j        z   r|j        r|                    d;           |j        r|j        r|                    d<           |j        r|j        r|                    d=           t$          j                            |j                  st%          j        |j                   t/          dJi d>|d?|j        d|j        d@|j        dA|j                            dB          dC|j	        dD|j        d|j        dE|j        d&|j        d.|j
        d4|j        d6|j        dF|j        dG|j        dH|j        dI|j        S )KNr   )progusagedescriptionz--ignore-errors
store_truez7ignore errors when trying to generate stubs for modules)actionhelpz--no-importz{don't import the modules, just parse and analyze them (doesn't work with C extension modules and might not respect __all__)z--no-analysisz--parse-onlyrw   zdon't perform semantic analysis of sources, just parse them (only applies to Python modules, might affect quality of stubs. Not compatible with --inspect))destr  r  z--inspect-moderq   zimport and inspect modules instead of parsing source code.This is the default behavior for c modules and pyc-only packages, but it is also useful for pure python modules with dynamically generated members.z--include-privatezqgenerate stubs for objects and members considered private (single leading underscore and no trailing underscores)z--export-lesszQdon't implicitly export all names imported from other modules in the same packagez--include-docstringsz*include existing docstrings with the stubsz-vz	--verbosezshow more verbose messagesz-qz--quietzshow fewer messagesz	--doc-dirPATHr   zuse .rst documentation in PATH (this may result in better stubs in some cases; consider setting this to DIR/Python-X.Y.Z/Doc/library))metavarr_  r  z--search-pathzaspecify module search directories, separated by ':' (currently only used if --no-import is given)z-oz--outputrz   outz2change the output directory [default: %(default)s])r"  r   r_  r  z-mz--moduler   MODULEr{   z5generate stub for module; can repeat for more modules)r  r"  r   r_  r  z-pz	--packagePACKAGEr\   z7generate stubs for package recursively; can be repeatedr|   r   z-generate stubs for given files or directories)r"  nargsr   r  r   z3May only specify one of: modules/packages or files.z.Cannot specify both quiet and verbose messageszACannot specify both --parse-only/--no-analysis and --inspect-moderm   ro   rr   rt   :rv   rx   ry   r}   r~   r   r   r   ) argparseArgumentParserHEADERDESCRIPTIONadd_argument
parse_argsr  version_info
executablerv   r{   r\   r|   errorr~   r}   rq   rw   r  r   existsrz   r  r;   ro   rr   rt   r  rx   ry   r   r   )r   parsernsrm   s       r   parse_optionsr4    s   $)6{[[[F
F    
      )     X	     B     `    
 9    
 k,Eabbb
iCXYYY
(	     8	     A     D     F     <	     
		4	 	 B !$I^BN	zBK LBH LJKKK	x GBJ GEFFF	z Zbm ZXYYY 7>>"-(( #
BM"""   ),, 

 

	
 N((--- NN && == ** == 

  hh 

 hh  NN!" 00# r   r   c                $   t           j                            d           dt          j        v s.dt          j        v s t          j                            dd           t          | t          j        dd          n|           }t          |           d S )Nr   r   r   r   r   )	r  r  check_python_versionr  r   insertr4  argvr  )r   r  s     r   mainr9  D  sx    I""9--- #(NNcSXoo2DLCHQRRLLdCCG7r   r+  )r  r/   r   r  ry  )r  r{  r   r  )r  r%   r   r  )r   r"   r   rs   )r{   r  r   r  )r{   r  r   r  )r   rs   r   rp   )r   rs   r   rs   )r  r;   r  r  r   r  )
r{   ru   r\   ru   r}   rp   r~   rp   r   r  )r   rs   r   rp   )r   rs   r0  r^  r   r  )
r{   ru   r\   ru   rt   ru   rm   rn   r   r  )r  r;   r   r  )r  r   r  r  r   r   )
r  r  rw   rp   r  r  r}   rp   r   r   )r  r   r  rs   rw   rp   rq   rp   ry   rp   r   rp   r   rp   rr   rs   r  ru   r   r   )r  r;   r   r   )r   ru   r   r;   r   )r   r   r   r   )r   r4  r   r(  r  r  os.pathr  r  typingr   r   
mypy.buildr  mypy.mixedtraverser
mypy.parsemypy.traverser	mypy.utilr   mypy.errorsr   r   mypy.find_sourcesr	   r
   mypy.modulefinderr   r   r   r   r   mypy.moduleinspectr   r   
mypy.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   mypy.optionsr;   r  mypy.stubdocr<   r=   mypy.stubgencr>   r?   mypy.stubutilr@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   
mypy.typesrQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   mypy.visitorr[   ra   __annotations__rb   rk   r   r   r   r   r   r   r   r   rs   r   r	  r  TraverserVisitorr  r  r  mixedtraverserMixedTraverserVisitorr  r   r  r  r  r  r  r  r  r  r  r  r  r:  r  r  r  r  r  r  r*  r+  r4  r9  r   r   r   r   <module>rP     s	  & & &P # " " " " "   				  



     " " " " " " " "                           , , , , , , , , C C C C C C C C              : 9 9 9 9 9 9 9* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *V 0 / / / / / , , , , , , , , M M M M M M M M                                                                % $ $ $ $ $ ]\\ \ \ \ \  	    	$ 	$ 	$  	 	 	 	,5 ,5 ,5 ,5 ,5 ,5 ,5 ,5^               8             " " " " "     
        
      GF GF GF GF GF;s# GF GF GFT       t~6   $   > > > >'$ '$ '$ '$ '$d)? '$ '$ '$TMI MI MI MI MI($.*I MI MI MI`   9 9 9 9 9DN3 9 9 9         # # # #[ [ [ [   & & & &@% % % %B   <      B   ,   ,S S S S: !$/ / / / / /d7P 7P 7P 7Pt
=D D D DN     zDFFFFF r   