o
    7fd                    @  sR  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@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZL ddlMmNZO ddlPmQZQmRZR ddlSmTZTmUZU ddlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZc ddlmdZdmeZemfZfmgZg ddlhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZr ddlsmtZt g dZudevd< g dZwdevd< h dZxdevd< G dd dZNG dd dZydZzdevd< dZ{devd< dZ|devd< d Z}devd < d!Z~devd!< d"Zdevd"< d#Zdevd$< G d%d& d&ete Zdd+d,ZG d-d. d.ejjZdd/d0Zdd4d5ZG d6d7 d7ejjZG d8d9 d9eWejjZdd<d=ZG d>d? d?ejjZddCdDZddGdHZddKdLZddNdOZddQdRZddSdTZddYdZZdd_d`ZddbdcZddgdhZddldmZddodpZddsdtZddwdxZdydydydydydzd{dddZdddZdZdZdddZddddZedk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 urllib 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StarExpr	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                   @  s   e Zd ZdZd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                 C  sp   || _ || _|| _|| _|| _|| _|| _|| _|| _|	| _	|
| _
|| _|| _|| _|| _|| _|| _|| _d S N)rl   rn   rp   rq   rs   ru   decointerpreterrv   rw   rx   ry   rz   r\   r{   r|   r}   r~   r   )selfrl   rn   rp   rq   rs   ru   rv   rw   rx   ry   rz   r\   r{   r|   r}   r~   r    r   E/home/ertert/spirit/venv/lib/python3.10/site-packages/mypy/stubgen.py__init__   s$   
zOptions.__init__N)$rl   rm   rn   ro   rp   ro   rq   rr   rs   rt   ru   rr   rv   ro   rw   ro   rx   ro   ry   rr   rz   rt   r\   rt   r{   rt   r|   ro   r}   ro   r~   ro   r   ro   r   r   )__name__
__module____qualname____doc__r   r   r   r   r   r;      s    r;   c                   @  sD   e Zd ZdZ	ddddZdddZedddZed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modulerr   path
str | Noneruntime_alllist[str] | Noner   r   c                 C  s   t ||d | _|| _d | _d S r   )r
   sourcer   ast)r   r   r   r   r   r   r   r      s   
zStubSource.__init__c                 C  s   d| j  dS )NzStubSource()r   r   r   r   r   __repr__      zStubSource.__repr__c                 C     | j jS r   )r   r   r   r   r   r   r         zStubSource.modulec                 C  r   r   )r   r   r   r   r   r   r      r   zStubSource.path)NN)r   rr   r   r   r   r   r   r   )r   rr   )r   r   )	r   r   r   r   r   r   propertyr   r   r   r   r   r   r      s    
r   EMPTYFUNCCLASSEMPTY_CLASSVAR
NOT_IN_ALLz<ERROR>ERROR_MARKERc                      s   e Zd ZdZd, fddZd-ddZd.ddZd/ddZd0ddZd1ddZ	d2ddZ
d3ddZd4d!d"Zd5d$d%Zd6d'd(Zd7d*d+Z  ZS )8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                   s   || _ t   d S r   )r   superr   )r   r   	__class__r   r   r     s   zAliasPrinter.__init__noder   rr   c                 C  s   |j | }g }t|j|j|jD ]I\}}}|tkr#|||  q|tkr2|d||   q|t	krA|d||   q|t
krS|| d||   q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kindr   r   r   visit_call_expr  s   zAliasPrinter.visit_call_exprr/   c                 C  s   | j j|j |jS r   )r   import_trackerrequire_namer   r   r   r   r   r   visit_name_expr#  s   zAliasPrinter.visit_name_expror-   c                 C  sX   |}d}t |trd|j | }|j}t |ts	t |tstS | jj|j |j| S )N .)	
isinstancer-   r   exprr/   r   r   r   r   )r   r   r   trailerr   r   r   visit_member_expr'  s   



zAliasPrinter.visit_member_exprr5   c                 C  s
   t |jS r   )reprvaluer   r   r   r   visit_str_expr2     
zAliasPrinter.visit_str_exprr*   c                   s    j |j}|dkr%t|jtrd fdd|jjD S |j S |dkr2|j  dS |j }|j }t	|dkrT|
drT|d	rT|d
d }| d| dS )Nztyping.Unionz | c                   s   g | ]}|  qS r   r   ).0itemr   r   r   
<listcomp>9  s    z1AliasPrinter.visit_index_expr.<locals>.<listcomp>ztyping.Optional | None   r   r      [])r   get_fullnamebaser   indexr7   r   itemsr   len
startswithendswith)r   r   base_fullnamer   r   r   r   r   visit_index_expr5  s    zAliasPrinter.visit_index_exprr7   c                   "   dd  fdd|jD  dS )Nr   r   c                 3      | ]}|  V  qd S r   r   r   nr   r   r   	<genexpr>D      z0AliasPrinter.visit_tuple_expr.<locals>.<genexpr>r   r   r   r   r   r   r   visit_tuple_exprC     "zAliasPrinter.visit_tuple_exprr,   c                   r   )Nr   r   c                 3  r   r   r   r   r   r   r   r   G  r   z/AliasPrinter.visit_list_expr.<locals>.<genexpr>r   r   r   r   r   r   visit_list_exprF  r   zAliasPrinter.visit_list_exprr   c                 C  sT   g }|j D ]\}}t|tsJ |||  d||   qdd| dS )N: {r   })r   r   r5   r   r   r   )r   r   
dict_itemskeyr   r   r   r   visit_dict_exprI  s
   "zAliasPrinter.visit_dict_exprr    c                 C  s   dS )N...r   r   r   r   r   visit_ellipsisQ  s   zAliasPrinter.visit_ellipsisr0   c                 C  s&   |j |  d|j d|j|  S )N )leftr   oprightr   r   r   r   r   visit_op_exprT  s   &zAliasPrinter.visit_op_exprr3   c                 C  s   d|j |  S )Nr   )r   r   r   r   r   r   visit_star_exprW     zAliasPrinter.visit_star_expr)r   r   r   r   )r   r   r   rr   )r   r/   r   rr   )r   r-   r   rr   )r   r5   r   rr   )r   r*   r   rr   )r   r7   r   rr   )r   r,   r   rr   )r   r   r   rr   )r   r    r   rr   )r   r0   r   rr   )r   r3   r   rr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r     s    









r   filer.   r   set[str]c                 C     t  }| | |jS r   )DefinitionFinderr   namesr   finderr   r   r   find_defined_names[     
r   c                   @  s.   e Zd ZdZdddZddd	ZdddZdS )r   z:Find names of things defined at the top level of a module.r   r   c                 C     t  | _d S r   )setr   r   r   r   r   r   f     zDefinitionFinder.__init__r   r   c                 C     | j |j d S r   r   addr   r   r   r   r   visit_class_defj     z DefinitionFinder.visit_class_defr%   c                 C  r  r   r  r   r   r   r   visit_func_defn  r	  zDefinitionFinder.visit_func_defNr   r   r   r   r   r   r   r%   r   r   )r   r   r   r   r   r  r
  r   r   r   r   r   a  s
    

r   c                 C  r   r   )ReferenceFinderr   refsr   r   r   r   find_referenced_namess  r  r  r   r!   ro   c                 C  s   t | to	| jdkS )Nr   )r   r/   r   )r   r   r   r   is_none_expry  s   r  c                      sl   e Zd ZdZdddZd  fdd	Zd!ddZd" fddZd#ddZd$ddZ	d%ddZ
d&ddZ  ZS )'r  z1Find all name references (both local and global).r   r   c                 C  r  r   )r  r  r   r   r   r   r     r  zReferenceFinder.__init__blockr   c                      |j st | d S d S r   is_unreachabler   visit_block)r   r  r   r   r   r       zReferenceFinder.visit_blocker/   c                 C  r  r   )r  r  r   )r   r  r   r   r   r     r   zReferenceFinder.visit_name_exprtrV   c                   s   |  |jj t | d S r   )add_reftyper   r   visit_instancer   r  r   r   r   r    s   zReferenceFinder.visit_instancerY   c                 C  s   |j r| |j  d S d S r   )r   r  r  r   r   r   visit_unbound_type  r  z"ReferenceFinder.visit_unbound_typerW   c                 C  s   |j D ]}||  qd S r   )r   r   )r   r  r   r   r   r   visit_tuple_type  s   
z ReferenceFinder.visit_tuple_typerU   c                 C  s&   |j D ]}||  q|j|  d S r   )	arg_typesr   ret_type)r   r  r   r   r   r   visit_callable_type  s   
z#ReferenceFinder.visit_callable_typefullnamerr   c                 C  s@   | j | d|v r|ddd }| j | d|v s
d S d S )Nr   r   r   )r  r  rsplit)r   r#  r   r   r   r    s
   zReferenceFinder.add_refr  )r  r   r   r   )r  r/   r   r   )r  rV   r   r   )r  rY   r   r   )r  rW   r   r   )r  rU   r   r   )r#  rr   r   r   )r   r   r   r   r   r  r   r  r  r  r"  r  r   r   r   r   r   r  }  s    




r  c                      s  e Zd ZdZ					dd fddZd fddZdddZdddZdddZdd!d"Z	dd$d%Z
dd&d'Zdd)d*Zdd+d,Zdd0d1Zd fd3d4Zdd7d8Zdd9d:Zdd;d<Zd fd>d?ZddAdBZddDdEZddFdGZddJdKZddOdPZddQdRZddSdTZddUdVZdddYdZZdd[d\Zd fd^d_ZddadbZddddeZ ddgdhZ!	dddkdlZ"ddmdnZ#dddqdrZ$ddsdtZ%ddvdwZ&	Wdddzd{Z'dd|d}Z(dddZ)d fddZ*  Z+S )r   z#Generate stub text from a mypy AST.NF_all_r   rx   ro   analyzedr~   r   r   r   c                   sD   t  |||| g | _g g| _t| _d | _|| _t | _	d| _
d S NF)r   r   _decorators_varsr   _state_current_classr&  r  method_namesprocessing_dataclass)r   r%  rx   r&  r~   r   r   r   r   r     s   
zASTStubGenerator.__init__r   r.   c                   s@   |j | _|j| _| t| t|| _t | | 	  d S r   )
r#  module_namer   set_defined_namesr   r  referenced_namesr   visit_mypy_filecheck_undefined_namesr   r   r   r   r1    s   
z ASTStubGenerator.visit_mypy_filer1   c                 C  s|   d}|j D ]6}t|tsq| |jj|jjrq| | |s,| |j |jj	r+d}q|jj	r7| |j q| 
  qdS )zD@property with setters and getters, @overload chain and some others.FTN)r   r   r   is_private_namefuncr   r#  process_decoratorr
  is_overloadclear_decorators)r   r   overload_chainr   r   r   r   visit_overloaded_func_def  s    



z*ASTStubGenerator.visit_overloaded_func_deffunc_defr%   ctxrC   r=   c                 C  s&   |  ||}| ||}t|j||S r   )_get_func_args_get_func_returnr=   r   )r   r:  r;  r   retnamer   r   r   get_default_function_sig  s   z)ASTStubGenerator.get_default_function_siglist[ArgSig]c              	   C  s  g }t |jD ]\}}|j}|j}|j}t|jtr |jj| nd }	|dko)|dk}
|dko1|dk}d }|	rF|
sF|sFtt	|	t
sF| |	}| rZtdd |D sZ|td d}|jr||si| |jdd	}| |j\}}|r{t|d
kr{|}n|tkrd| }n	|tkrd| }|t||t|j|d q|jd urtdd |D rt|j|jjdd |D }|d ur|}| jo| jo|jj|j j}|jdkr
|r
ddd |D v r
d dd |D }|D ]}|jdkrd| d|_q|jdkr	d| d|_q|S )Nr   r   clsc                 s      | ]	}|j d V  qdS r   N)r   r   r   r   r   r   r   r         z2ASTStubGenerator._get_func_args.<locals>.<genexpr>r   r   TF   r   )defaultdefault_valuec                 s  s$    | ]}|j d u o|jdu V  qd S r'  )r  rG  rD  r   r   r   r   
  s    
c                 S     g | ]}|j qS r   r   rD  r   r   r   r         z3ASTStubGenerator._get_func_args.<locals>.<listcomp>r   c                 S  rI  r   rJ  r   ar   r   r   r     rK  r   c                 s  rB  rC  )r   striprL  r   r   r   r     rE  ___)!	enumerate	argumentsvariabler   r   r   unanalyzed_typerU   r   rZ   rT   print_annotationis_namedanyr   r<   initializerget_str_type_of_nodeget_str_default_of_noder   r   r   ro   
class_infoallrH   self_varr&  r-  infor   plugin_generatedr   )r   r   r;  r   iarg_varr   r   annotated_typeis_self_arg
is_cls_argtypenamerG  potential_defaultvalidnew_argsis_dataclass_generatednew_namer   r   r   r   r<    sf   


&
zASTStubGenerator._get_func_argsr   c           
      C  s,  |j dkrt|jtrtt|jjtrd S | |jjS |jt	ks'|j t
v r)d S t|j }|d ur4|S t|s<t|r| d}d}d}d}t|rS| d }}nt|D ]\}}	|jd urjt|jsj| d}|	rq| d}qWt|r{| d}| d| d| d| dS t|s|jtkrdS d S )Nr   zcollections.abc.Generatorr   _typeshed.Incompleter   r   r   )r   r   rT  rU   rZ   r!  rT   rU  abstract_statusr   rk   rI   rO   rP   add_namerM   r   r  rN   r   )
r   r   r;  r>  generator_name
yield_name	send_namereturn_namer   in_assignmentr   r   r   r=     s8   




z!ASTStubGenerator._get_func_returnr   c                 C  s:   |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   r   r   r   _get_func_docstringC  s   z$ASTStubGenerator._get_func_docstringc                 C  s  | j o| jo|jj|j j}|r|jdkrd S | |j|js.| |js.| 	|jr4|j
s4|   d S |  rD| jttfvrD| d |  sft|}|D ]\}}|| jv rXqN| ||}|re| | qN| jd urt|jrx|jd jj}nd}t| jj|}nd }t| j|j| ||jtk|d}	| |j | ||	}
|  |
| j!|	}| j"||j#| j$|	j%dD ]	}| |d  q|   t| _d S )Nr   
r   r   )r.  r   	docstringis_abstractr[  )is_coroutine
decoratorsrw  )&r&  r-  r^  r   r   r_  r3  r#  is_not_in_allis_recorded_namer6  r7  is_top_levelr*  r   r   r  find_self_initializersr,  get_initr+  r   rR  rS  rB   rC   r.  ru  rm  r   record_namer?  get_signaturessig_generatorsformat_func_defry  r(  rw  )r   r   rj  
self_initsinitr   	init_coder]  r[  r;  default_sigsigsoutputr   r   r   r
  K  s^   








zASTStubGenerator.visit_func_defr   c                 C  s2   |  |jj|jjrd S | | | |j d S r   )r3  r4  r   r#  r5  r
  r   r   r   r   visit_decorator  s   
z ASTStubGenerator.visit_decoratorc                 C  s0  d|j _|jD ]}t|ttfsqt|}| |}|dv r&| j|dd q|dv r6d|j _	| j|dd q|dkrF| j|dd t
|j _q|dv ry|dd	 }|sY| jd
 |tdd }| j|dd | j|pmd
 ddd t
|j _q|tv r| j|dd d|j _q|dr| j|dd q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.abstractmethod)z.setterz.deleter)r4  r6  original_decoratorsr   r/   r-   get_qualified_namer   add_decoratoris_awaitable_coroutiner   rm  
rpartitionr   
add_importr   rQ   r   )r   r   	decoratorqualnamer#  
abc_modulebuiltin_decorator_replacementr   r   r   r5    s:   





z"ASTStubGenerator.process_decoratorr   r!   rr   c                 C  sF   | j rt|ttfr|jrt|jtr|jjs|jS t|}| 	|S )z"Return the expression's full name.)
r&  r   r/   r-   r#  r   r:   is_suppressed_importr  resolve_name)r   r   r   r   r   r   r     s   

zASTStubGenerator.get_fullnamer   c                   s4  || _ t|jj| _d }|  r| jtkrt| j	}| 
d | |}|D ]}| 
| j d| d q&| |j | |}|rM|D ]}| j| qDt|jttfre|jt| }|d|  n| jr|jjr|jjs|d | jd | jd |rdd| dnd	}| 
| j d
|j | d |   | j r|j!rt"j#$|j!}	| 
| j |	 d t| j	}
| j%g  t& '| | (  | j%)  | j%d |j t| j	|
kr| jt*kr|d urd	| j	|< | j r|j!s| j	d d d d | j	d< t*| _nt+| _t, | _d| _-d | _ d S )Nrv  @z
metaclass=zmetaclass=abc.ABCMetar  r   r   r   r   class z:
r    ...
F).r+  find_method_namesdefsrt  r,  r}  r*  r   r   _outputr  get_class_decorators_indentr  r   get_base_typesr   r   r   	metaclassr/   r-   r   r   r   r&  r^  rx  is_protocolr  r   indent_include_docstringsrw  mypyutilquote_docstringr)  r   r  dedentpopr   r   r  r-  )r   r   seprz  d
base_typesr   metabasesrw  r   r   r   r   r    sV   








z ASTStubGenerator.visit_class_defcdefrt   c              	   C  sb  g }t | }|j|j D ]}t|ttfr$| |dkr#|t| qt|t	r2||
| qt|tr| |r|| |}t|jd tsKJ |jd j}|du r^|| d qddd |D }| d}|| d	|d
| d q| |r||
| q|| d q|j D ]\}	}
|	dkrq||	 d|

|  q|S )z%Get list of base classes for a class.zbuiltins.objectr   Nrl  r   c                 s  s&    | ]\}}d |d| dV  qdS )r   r   r   Nr   )r   fr  r   r   r   r     s   $ z2ASTStubGenerator.get_base_types.<locals>.<genexpr>typing.NamedTupler   z, [z])r  r   )r   base_type_exprsremoved_base_type_exprsr   r/   r-   r   r   r  r*   r   r   is_namedtuple_get_namedtuple_fieldsr   r5   r   rn  r   is_typed_namedtuplekeywordsr   )r   r  r  pr   	nt_fieldsrf  
fields_strnamedtuple_namer   r   r   r   r   r    s:   






zASTStubGenerator.get_base_typesc                 C  sL   g }t | }|jD ]}| |r#||| | jt| d| _q	|S )NT)	r   rz  is_dataclassr   r   r   r   r  r-  )r   r  rz  r  r  r   r   r   r    s   

z%ASTStubGenerator.get_class_decoratorsc                 C  s   t |tr|j}| |dkS )Nzdataclasses.dataclass)r   r   r   r   r   r   r   r   r   r  &  s   
zASTStubGenerator.is_dataclassr   c                   r  r   r  r   r   r   r   r  +  s   zASTStubGenerator.visit_blockr   c                 C  s  g }|j D ]}t|tr>t|jtr>| |js| |jr+| ||j |d q| 	|jr>| 
||j |d qt|trZ| |jsZ|jsZ| |jrZ| ||j qt|ttfrw|j}t|jtro|jj}nd gt| }n|g}|jg}d}d}t||D ]4\}}	t|tr| |j|j|	}
|
rd}|s|  r| jttfvrd|
 }
d}| |
 | |j q|| qt|rt| _d S d S )NFTrv  )lvaluesr   r/   rvaluer   r  r  process_namedtupler   is_typeddictprocess_typeddictr3  r   rT  is_alias_expressionprocess_typealiasr7   r,   r   rW   r   r   r  r}  r*  r   r   r  r  r\  )r   r   foundllvaluer   r   r  foundr   
annotationr  r   r   r   visit_assignment_stmt1  sZ   








z&ASTStubGenerator.visit_assignment_stmtr   c                 C  s   |  |jdkS )Nzcollections.namedtuple)r   r   r  r   r   r   r  a     zASTStubGenerator.is_namedtuplec                 C     |  |jtv S r   )r   r   rS   r  r   r   r   r  d  r  z$ASTStubGenerator.is_typed_namedtuplecalllist[tuple[str, str]] | Nonec           	        s*  |  |rK|jd }t|tr|jdd }n t|ttfr7g }|j	D ]}t|ts/ d S |
|j q%nd S |rI| d  fdd|D S g S | |r|jd }t|ttfs^d S g }t| }|j	D ])}t|trut|j	dksx d S |j	\}}t|ts d S |
|j||f qg|S d S )Nr   ,r   rl  c                   s   g | ]}| fqS r   r   )r   
field_name
incompleter   r   r   v  s    z;ASTStubGenerator._get_namedtuple_fields.<locals>.<listcomp>r   )r  r   r   r5   r   replacesplitr,   r7   r   r   rn  r  r   r   r   )	r   r  
fields_argfield_namesfieldfieldsr  r  
field_typer   r  r   r  g  s>   










z'ASTStubGenerator._get_namedtuple_fieldsr  r/   r  c              	   C  s   | j tkr
| d t|jd ts| | d S | |}|d u r)| | d S | d}| j	 d|j
 d| d}t|dkrN| | d t| _ d S | j ttfvrZ| d | | d |D ]\}}| | j	 d| d	| d qdt| _ d S )
Nrv  r   r  r  r   ):r      r   )r*  r   r  r   r   r5   annotate_as_incompleter  rn  r  r   r   r   r   )r   r  r  r  r  	class_deff_namef_typer   r   r   r    s(   







 
z#ASTStubGenerator.process_namedtuplec                 C  r  r   )r   r   rR   r  r   r   r   r    r  zASTStubGenerator.is_typeddictc              
   C  sn  | j tkr
| d t|jd ts| | d S g }d }t|jdkr||jd t	kr|t|jd t
s:| | d S |jd jD ]\}}t|tsQ| |  d S ||j|f q@t|jdkr{|jd tkso|jd dkrv| | d S |jd }n/t|jdd  |jdd  D ]\}}t|ts| |  d S |dkr|}q|||f qt| }	tdd |D r| | j |j d||	 d t| _ d S | d	}
|d ur|
d
||	 7 }
| 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 qt| _ d S )Nrv  r   r   r   totalc                 s  s(    | ]\}}|   pt|V  qd S r   )isidentifierkeyword	iskeyword)r   r   rO  r   r   r   r     s   & z5ASTStubGenerator.process_typeddict.<locals>.<genexpr> = 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   rr   r   rW  r  r   r   r   rn  r   r   )r   r  r  r   r  	attr_name	attr_typearg_namer   r  r  r  r   key_typer   r   r   r    s\   







&

$



(
z"ASTStubGenerator.process_typeddictc                 C  s2   |  d}| | j |j d| d t| _d S )Nrl  r   rv  )rn  r  r  r   r   r*  )r   r  r  r   r   r   r    s   

z'ASTStubGenerator.annotate_as_incompleteT	top_levelc                   sP  t |tr |jdv rdS t |tr| S t |tr2|jdv r#dS |jdkr+| S  |j S t |trS j	rS|rEt |j
tttfpJt |j
toR |j
j S t |trt |jtr |jjst |jtrp|jj}n|jg}|jjdkrt|dkr|\}}t |tr|g}nt |tr|j|g }ndS t fd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  s    | ]
} j |d dV  qdS )F)r  N)r  )r   r`  r   r   r   r     s    z7ASTStubGenerator.is_alias_expression.<locals>.<genexpr>)r   r   r   r   r    r/   r   r3  r-   r&  r   r%   r   r.   r8   is_private_memberr#  r*   r   r   r7   r   r   r,   r\  )r   r   r  indicesr   retr   r   r   r    sH   








z$ASTStubGenerator.is_alias_expressionc                 C  sN   t | }| | j |j d|| d | |j | jd |j d S )Nr  rv  r   )r   r  r  r   r   r  r)  r   )r   r  r  r  r   r   r   r    s   $z"ASTStubGenerator.process_typealiasr&   c                   sh   |j d }t|tr,t|jd tr,t|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   operandsr/   r5   r   r   r   visit_if_stmt)r   r   r   r   r   r   r    s   
zASTStubGenerator.visit_if_stmtr(   c                 C  s"   |  dd|j  |j d d S )Nzfrom r   z
 import *
)add_import_linerelativeidr   r   r   r   visit_import_all,  r   z!ASTStubGenerator.visit_import_allr)   c                   s.  t  }g }t|j|j\}} jr&tj j|| j	d\}}|s%|}n|}|dkr.d S |j
D ])\}}	|dkrB tdg q1 |||	d urS j| |}	|||	f q1 jd| | |  jd dd |D  |D ]\}}
 |
p~| qu jr fd	d
|j
D }|| d S d S )Nz.__init__.py
__future__six)r  Nr   r   c                 s  s    | ]	\}}|p	|V  qd S r   r   r   r   aliasr   r   r   r   G  rE  z5ASTStubGenerator.visit_import_from.<locals>.<genexpr>c                   s0   g | ]\}}| j v r|d u r| jvr|qS r   )r%  IGNORED_DUNDERSr  r   r   r   r   M  s
    z6ASTStubGenerator.visit_import_from.<locals>.<listcomp>)r  translate_module_namer  r  r.  r  r  correct_relative_importr   r   r   visit_importr'   should_reexportr   reexportr   add_import_fromr)  extendr  r%  update)r   r   exported_namesimport_namesr   r  full_moduleokr   as_namer  r   r   r   r   visit_import_from/  s>   
z"ASTStubGenerator.visit_import_fromr'   c                 C  sX   |j D ]&\}}| j|| |d u r|dd }n|}| jd | | | qd S )Nr   r   r   )idsr   r  r  r)  r   r  )r   r   r  as_idtarget_namer   r   r   r  T  s   zASTStubGenerator.visit_importr  Type | Nonec                 C  s   || j d v r	dS | |s| |rdS | j d | |durK| |}t|trJ|jsJ|jdkrJ| j	j
d| jv rJ| |}|d| d7 }n| jrV| 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   rv  )r)  r3  r{  r   rU  r   rY   r   r   r   
module_forgetTYPING_MODULE_NAMESrY  r-  r  get_assign_initializer)r   r  r  r  rf  	final_argrX  r   r   r   r  ^  s*   




zASTStubGenerator.get_initc                 C  sH   | 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+  r^  is_named_tupler   r6   r-  no_rhs)r   r  r   r   r   r    s   z'ASTStubGenerator.get_assign_initializerr   r   c                 C  s&   |r| j | | jd|  d S )Nr  )r   r   r(  r   )r   r   r   r   r   r   r    s   zASTStubGenerator.add_decoratorc                 C  s   | j   d S r   )r(  clearr   r   r   r   r7    r   z!ASTStubGenerator.clear_decoratorsr#  c                   s    | d}t fdd|D S )Nr   c                 3  s    | ]}  |V  qd S r   )r3  )r   partr   r   r   r     r   z5ASTStubGenerator.is_private_member.<locals>.<genexpr>)r  rW  )r   r#  partsr   r   r   r    s   
z"ASTStubGenerator.is_private_membercan_infer_optional
can_be_anyc                 C  s   |  |}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rF|jdv rFt|  |j	tsDt|  |j
trFdS t|trR|jdv rRdS |rft|trf|jd	krf| d
 dS |rm| d
S dS )Nintrr   bytesfloatcomplex)-+r  ro   r   rl  r   r   )maybe_unwrap_unary_exprr   r+   r5   r   r#   r   r0   r   r   r   r/   r   rn  )r   r  r  r  r   r   r   rY    s.   






z%ASTStubGenerator.get_str_type_of_nodec                 C  s   t |ts|S d}|j|v r/t |tr-|j|vs"t |jttttfs%	 |S |j}t |ts|S |jdkrbt |tr`|jdksFt |jttfsI	 |S t |jtrX|jjdvrX	 |S |j}t |ts9|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.
        )r  r  notr  )	r   r9   r   r   r+   r#   r   r/   r   )r   r   math_opsr   r   r   r     s2   






z(ASTStubGenerator.maybe_unwrap_unary_exprtuple[str, bool]c                 C  sX  t |tr|jdv r|jdfS dS t |ttfr|j dfS t |tr8t |jttfr6|j |jj dfS dS t |t	rDt
|jdfS t |trVdt
|jdd dfS t |trg }|jD ]}| |\}}|sn dS || q`t|dkr|dnd}d	d
| | }|dfS t |trg }|jD ]}| |\}}|s dS || qdd
| d }|dfS t |trg }|jD ]}| |\}}|s dS || q|rdd
| d }|dfS dS t |tr*g }|jD ],\}}	|du r dS | |\}
}| |	\}}|r|s dS ||
 d|  qdd
| d }|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   r/   r   r+   r#   r   r9   r   r   r5   r   r   r  r7   r   rZ  r   r   r   r,   r2   r   )r   r  items_defaultsr  	e_defaultrh  closingrG  kv	k_defaultk_valid	v_defaultv_validr   r   r   rZ    s|   


7
2



(



	z(ASTStubGenerator.get_str_default_of_noder  name_is_aliasc                   sX   |  ||d | }|s$|| jvr$| jr|| jv r$|s$|d| j vr$dS t |||S )Nr   )r  asyncioT)r3  r0  r%  r  r  r   r  )r   r   r  r/  
is_privater   r   r   r    s   

z ASTStubGenerator.should_reexport)NFFFF)r%  r   rx   ro   r&  ro   r~   ro   r   ro   r   r   )r   r.   r   r   )r   r1   r   r   )r:  r%   r;  rC   r   r=   )r   r%   r;  rC   r   r@  )r   r%   r;  rC   r   r   )r   r%   r   r   r  )r   r   r   r   )r   r!   r   rr   r  )r  r   r   rt   r   r!   r   ro   )r   r   r   r   r   r   r   r   )r   r   r   ro   )r  r   r   r  )r  r/   r  r   r   r   )r  r/   r   r   )T)r   r!   r  ro   r   ro   )r  r/   r  r!   r   r   )r   r&   r   r   )r   r(   r   r   )r   r)   r   r   )r   r'   r   r   r   )r  rr   r  r!   r  r  r   r   )r  r!   r   rr   )F)r   rr   r   ro   r   r   r  )r#  rr   r   ro   )FT)r  r!   r  ro   r  ro   r   rr   )r   r!   r   r!   )r  r!   r   r#  )r   rr   r  rr   r/  ro   r   ro   ),r   r   r   r   r   r1  r9  r?  r<  r=  ru  r
  r  r5  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r7  r  rY  r   rZ  r  r   r   r   r   r   r     s`    



@
#

8

.
.
+



0


$


7
5


%
!



"@r   r  list[Statement]c                 C  sl   t  }| D ].}t|tr||j qt|tr ||jj qt|tr3|jD ]
}|	t
|g q(q|S r   )r  r   r%   r  r   r   r4  r1   r   r  r  )r  resultdefnr   r   r   r   r  .  s   



r  c                   @  s    e Zd Zd
ddZdddZd	S )SelfTraverserr   r   c                 C  s
   g | _ d S r   )resultsr   r   r   r   r   =  r   zSelfTraverser.__init__r   r   c                 C  sP   |j d }t|tr"t|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   r/   r   r8  r   r  )r   r   r  r   r   r   r  @  s   

z#SelfTraverser.visit_assignment_stmtNr  r3  )r   r   r   r   r  r   r   r   r   r7  <  s    
r7  fdefr$   list[tuple[str, Expression]]c                 C  r   )znFind attribute initializers in a method.

    Return a list of pairs (attribute name, r.h.s. expression).
    )r7  r   r8  )r9  	traverserr   r   r   r~  J  s   
r~  r   rr   c                 C  s4   t | tr| jS t | trt| j d| j S tS )Nr   )r   r/   r   r-   r  r   r   )r   r   r   r   r  T  s
   

r  rz   list[StubSource]c                 C  s   dd | D S )Nc                 S  s$   g | ]}|j d u st|j s|qS r   )r   is_blacklisted_pathr   r   r   r   r   r   ^  s    z.remove_blacklisted_modules.<locals>.<listcomp>r   )rz   r   r   r   remove_blacklisted_modules]  s   r?  )tuple[list[StubSource], list[StubSource]]c                 C  s:   g }g }| D ]}t |jr|| q|| q||fS r   )r   r   r   )rz   
py_modulespyc_modulesmodr   r   r   split_pyc_from_pyc  s   
rD  r   c                   s   t  fddtD S )Nc                 3  s     | ]}|t  d  v V  qdS )rv  N)normalize_path_separators)r   substrr   r   r   r   o  s    z&is_blacklisted_path.<locals>.<genexpr>)rW  rb   rG  r   rG  r   r=  n  s   r=  c                 C  s   t jdkr| ddS | S )Nwin32r%  /)sysplatformr  rG  r   r   r   rE  r  s   
rE  options	mypy_optsMypyOptions;tuple[list[StubSource], list[StubSource], list[StubSource]]c              
   C  s   | j s| jr%| jrt| j| j | j| j}g }n3t| j| j | j| j\}}n%zt	| j
|}W n ty@ } ztt||d}~ww d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                 S     g | ]	}t |j|jqS r   r   r   r   r   mr   r   r   r         z)collect_build_targets.<locals>.<listcomp>)r\   rz   rn   find_module_paths_using_searchrs   rl   find_module_paths_using_importsr|   r}   r	   r{   r   
SystemExitrr   r?  rD  )rL  rM  rA  	c_modulessource_listr  pyc_modpy_modr   r   r   collect_build_targetsx  s(   

r\  rt   r\   r|   r}   c                 C  s   t  o}g }g }tt|||}| | } dd | D } | D ]I}zt|||}	W n' tyN }
 zt }|r;tj	| |sDt
||
j| W Y d}
~
qd}
~
ww |	sY|t| q|	\}}|t||| q||fW  d   S 1 suw   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                 S  s   g | ]}t |s|qS r   )is_non_library_module)r   rC  r   r   r   r     s
    z3find_module_paths_using_imports.<locals>.<listcomp>N)r   listrL   rF   rA   	traceback
format_excrJ  stdoutwriterK   messager   r   )rz   r\   r|   r}   rp   rA  rX  r  rC  r5  r  tbr   r   r   r   r   rV    s4   $rV  r   c                 C  sN   |  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   r   r   r   r]    s   r]  r  r  tuple[str, int]c                 C  s   t D ]@}dD ];}| d| }| d| s| |kr$|r$|df    S d| d | v rA|d | d| d d  df    S qq| |fS )N)z	six.movesr  r   r   r   )ra   r   	partition)r   r  pkgaltrF  r   r   r   r    s   *r  rs   rl   rm   c                 C  s   g }t tj |d}tdt| ddt|}t|ddd}| D ]}||}	t|	t	r5t
||	 d}
n|	}
|t||
 q!|D ]}||}|rQt
|t	j dd |D }|| qBdd |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   )fscacherL  c                 S  rP  r   rQ  rR  r   r   r   r     rT  z2find_module_paths_using_search.<locals>.<listcomp>c                 S  s   g | ]	}t |js|qS r   )r]  r   rR  r   r   r   r     rT  )r   r  r   default_data_dirr   tupler   find_moduler   r   rE   r   r   find_modules_recursive	NOT_FOUNDr  )rz   r\   rs   rl   r5  typeshed_pathsearch_pathscacher   m_resultmodule_pathpackagep_resultsourcesr   r   r   rU    s&   	



rU  stubgen_optionsc                 C  sn   t  }d|_d|_d|_d|_| j|_d|_t|_	d|_
| j|_tdd}| r-||_tj|j|_|S )z4Generate mypy options using the flag passed by user.skipFTMYPY_CACHE_DIRr   )rN  follow_importsincrementalrw   semantic_analysis_onlyrl   python_versionshow_tracebackrJ   transform_sourcepreserve_astsr   osgetenvrN  	cache_dirr   
expanduser)r~  rL  environ_cache_dirr   r   r   mypy_options  s   r  rC  r   c                 C  s   | j dus	J dt| j d}| }W d   n1 sw   Y  tj|}t|}tjj|| j | j||d| _	| j| j	_
| r[| D ]}tj| d qHt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   errorsrL  rv  r   )r   openreadr  r  decode_python_encodingr   parser   r   	_fullnameis_blockersnew_messagesrJ  stderrrb  exit)rC  r  r  datar   r  rS  r   r   r   parse_source_file  s   

r  rA  rv   c              
   C  s   | sdS |rt dt|  d |r| D ]}t|| qdS ztdd | D |}W n ty> } ztd| |d}~ww | D ]}|j|j j|_	|j
du rY|jjj|j |_
qAdS )z8Use mypy to parse (and optionally analyze) source files.NzProcessing z	 files...c                 S  rI  r   r   r>  r   r   r   r   =  rK  z-generate_asts_for_modules.<locals>.<listcomp>z)Critical error during semantic analysis: )printr   r  r   r   rW  graphr   treer   r   managersemantic_analyzer
export_map)rA  rv   r  r|   rC  resr  r   r   r   generate_asts_for_modules/  s(   
r  Fr   )rv   rp   rx   r~   r   rq   targetrp   rx   r~   r   rq   all_modulesc             	   C  s   |rt | j|| j||||d}	|	  |	 }
nt| j|| ||d}| jdus,J d| j| | }
tj	
|}|rItj	|sIt| t|ddd}||
 W d   dS 1 saw   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.
    )r.  known_modulesr%  rq   rx   r~   r   )rx   r&  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  rb  )rC  r  rv   rp   rx   r~   r   rq   r  ngenr  gensubdirr   r   r   r   generate_stub_for_py_moduleH  s8   	

"r  c           
        s<  t | }t| |\}}}|| | }tdd |D }t|| j|| j g }|| D ]b  jdus5J d jdd}t	j
 jdv rJ|d7 }n|d	7 }t	j| j|}|| t j|| j| j t || j| jpq |v | j| j| j| j|d
	 W d   n1 sw   Y  q*|D ]W t fdd|D r jddd }n	 jddd	 }t	j| j|}|| t j|| j| j t j||| j| j| j| jd W d   n1 sw   Y  qt|}	| js|	dkrtd|	  t|dkrtd|d   dS tdt| t	j  dS dS dS )z!Main entry point for the program.c                 s  s    | ]}|j V  qd S r   rk  rR  r   r   r   r     s    z!generate_stubs.<locals>.<genexpr>Nr  r   rI  )z__init__.pyz__init__.pycz/__init__.pyiz.pyi)rv   rp   rx   r~   r   rq   r  c                 3  s"    | ]}|j  j d  V  qdS )r   N)r   r   )r   r[  rC  r   r   r     s     )r  rq   rx   r~   r   r   zProcessed %d modulesr   z
Generated zGenerated files under )r  r\  sortedr  rv   r|   r   r   r  r  basenamer   ry   r   rG   rw   r  rp   rx   r~   r   rq   rW  r?   r   r}   r  rD   r  )
rL  rM  rA  rB  rX  r  all_module_namesr{   r  num_modulesr   r  r   generate_stubsz  sj   



r  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              	   C  s4  t jdttd}|jdddd |jdddd |jd	d
dddd |jddddd |jdddd |jdddd |jdddd |jddddd |jddddd |jdddd d! |jd"ddd#d! |jd$d%dd&d'd(d) |jd*d+d,d-d.g d/d0 |jd1d2d,d3d4g d5d0 |jd6d7d6d8d9 || }tjd d: }tj|_	|j
|j r|jr|d; |jr|jr|d< |jr|jr|d= tj|jd>d? tdLi d@|dA|jd|jdB|jdC|jdDdE|j	dF|jd|jdG|jd&|jd.|j
d4|jd6|jdH|jdI|jdJ|jdK|jS )MNr   )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-onlyrv   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-moderp   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))metavarrG  r  z--search-pathzaspecify module search directories, separated by ':' (currently only used if --no-import is given)z-oz--outputry   outz2change the output directory [default: %(default)s])r  r  rG  r  z-mz--moduler   MODULErz   z5generate stub for module; can repeat for more modules)r  r  r  rG  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-modeT)exist_okrl   rn   rq   rs   :ru   rw   rx   r|   r}   r~   r   r   )argparseArgumentParserHEADERDESCRIPTIONadd_argument
parse_argsrJ  version_info
executableru   rz   r\   r{   errorr}   r|   rp   rv   r  r  ry   r;   rn   rq   rs   r  rw   rx   r~   r   )r   parsernsrl   r   r   r   parse_options  s  			



	
r  r   c                 C  sX   t jd dtjv sdtjv stjdd t| d u r#tjdd  n| }t| d S )Nr   r   r   r   r   )	r  r  check_python_versionrJ  r   insertr  argvr  )r   rL  r   r   r   mainE  s
   r  r  )r   r.   r   r   r2  )r  r4  r   r   )r9  r$   r   r:  )r   r!   r   rr   )rz   r<  r   r<  )rz   r<  r   r@  )r   rr   r   ro   )r   rr   r   rr   )rL  r;   rM  rN  r   rO  )
rz   rt   r\   rt   r|   ro   r}   ro   r   r@  )r   rr   r   ro   )r   rr   r  r  r   rl  )
rz   rt   r\   rt   rs   rt   rl   rm   r   r<  )r~  r;   r   rN  )rC  r   r  rN  r   r   )
rA  r<  rv   ro   r  rN  r|   ro   r   r   )rC  r   r  rr   rv   ro   rp   ro   rx   ro   r~   ro   r   ro   rq   rr   r  rt   r   r   )rL  r;   r   r   )r   rt   r   r;   r   )r   r   r   r   )r   r  r   r  r  r  os.pathrJ  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.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   mypy.optionsr;   rN  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   rr   r   r   r;  TraverserVisitorr   r  r  mixedtraverserMixedTraverserVisitorr  r   r  r7  r~  r  r?  rD  r=  rE  r\  rV  r]  r  rU  r  r  r  r  r  r  r  r  r  r   r   r   r   r   <module>   s   (,<0	/
T

*       




	




 
!


!


2:
 

