o
    2gH                     @  sB  d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZ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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'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z> dd	l?m@Z@mAZA dd
lBmCZC ddlDmEZE ddlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZa ddlbmcZc ddldmeZe d?ddZfd@dd ZgG d!d" d"eCZh	#dAdBd+d,ZiG d-d. d.e\eej  ZkdCd2d3ZldDd7d8ZmdEd9d:ZndFd=d>Zod#S )Ga  Generate fine-grained dependencies for AST nodes, for use in the daemon mode.

Dependencies are stored in a map from *triggers* to *sets of affected locations*.

A trigger is a string that represents a program property that has changed, such
as the signature of a specific function. Triggers are written as '<...>' (angle
brackets). When a program property changes, we determine the relevant trigger(s)
and all affected locations. The latter are stale and will have to be reprocessed.

An affected location is a string than can refer to a *target* (a non-nested
function or method, or a module top level), a class, or a trigger (for
recursively triggering other triggers).

Here's an example representation of a simple dependency map (in format
"<trigger> -> locations"):

  <m.A.g> -> m.f
  <m.A> -> <m.f>, m.A, m.f

Assuming 'A' is a class, this means that

1) if a property of 'm.A.g', such as the signature, is changed, we need
   to process target (function) 'm.f'

2) if the MRO or other significant property of class 'm.A' changes, we
   need to process target 'm.f', the entire class 'm.A', and locations
   triggered by trigger '<m.f>' (this explanation is a bit simplified;
   see below for more details).

The triggers to fire are determined using mypy.server.astdiff.

Examples of triggers:

* '<mod.x>' represents a module attribute/function/class. If any externally
  visible property of 'x' changes, this gets fired. For changes within
  classes, only "big" changes cause the class to be triggered (such as a
  change in MRO). Smaller changes, such as changes to some attributes, don't
  trigger the entire class.
* '<mod.Cls.x>' represents the type and kind of attribute/method 'x' of
  class 'mod.Cls'. This can also refer to an attribute inherited from a
  base class (relevant if it's accessed through a value of type 'Cls'
  instead of the base class type).
* '<package.mod>' represents the existence of module 'package.mod'. This
  gets triggered if 'package.mod' is created or deleted, or if it gets
  changed into something other than a module.

Examples of locations:

* 'mod' is the top level of module 'mod' (doesn't include any function bodies,
  but includes class bodies not nested within a function).
* 'mod.f' is function 'f' in module 'mod' (module-level variables aren't separate
  locations but are included in the module top level). Functions also include
  any nested functions and classes -- such nested definitions aren't separate
  locations, for simplicity of implementation.
* 'mod.Cls.f' is method 'f' of 'mod.Cls'. Non-method attributes aren't locations.
* 'mod.Cls' represents each method in class 'mod.Cls' + the top-level of the
  module 'mod'. (To simplify the implementation, there is no location that only
  includes the body of a class without the entire surrounding module top level.)
* Trigger '<...>' as a location is an indirect way of referring to to all
  locations triggered by the trigger. These indirect locations keep the
  dependency map smaller and easier to manage.

Triggers can be triggered by program changes such as these:

* Addition or deletion of an attribute (or module).
* Change of the kind of thing a name represents (such as a change from a function
  to a class).
* Change of the static type of a name.

Changes in the body of a function that aren't reflected in the signature don't
cause the function to be triggered. More generally, we trigger only on changes
that may affect type checking results outside the module that contains the
change.

We don't generate dependencies from builtins and certain other stdlib modules,
since these change very rarely, and they would just increase the size of the
dependency map significantly without significant benefit.

Test cases for this module live in 'test-data/unit/deps*.test'.
    )annotations)defaultdict)List).GDEFLDEFMDEFAssertTypeExprAssignmentStmt	AwaitExprBlockCallExprCastExprClassDefComparisonExpr	DecoratorDelStmtDictionaryComprehensionEnumCallExpr
ExpressionForStmtFuncBaseFuncDefGeneratorExprImport	ImportAll
ImportFrom	IndexExpr
MemberExprMypyFileNamedTupleExprNameExprNewTypeExprNodeOperatorAssignmentStmtOpExprOverloadedFuncDefRefExprStarExpr	SuperExpr	TupleExprTypeAliasExprTypeApplicationTypedDictExprTypeInfoTypeVarExpr	UnaryExprVarWithStmtYieldFromExpr)
op_methodsops_with_inplace_methodreverse_op_methodsunary_op_methods)Options)Scope)make_triggermake_wildcard_trigger)TraverserVisitor)	bind_self)AnyTypeCallableTypeDeletedType
ErasedTypeFunctionLikeInstanceLiteralTypeNoneType
Overloaded
ParametersParamSpecTypePartialType
ProperType	TupleTypeTypeTypeAliasTypeTypedDictType	TypeOfAnyTypeTypeTypeVarTupleTypeTypeVarTypeTypeVisitorUnboundTypeUninhabitedType	UnionType
UnpackTypeget_proper_type)
type_state)correct_relative_importtargetr   type_mapdict[Expression, Type]python_versiontuple[int, int]optionsr7   returndict[str, set[str]]c                 C  s    t ||| j|}| | |jS )z,Get all dependencies of a node, recursively.)DependencyVisitor
alias_depsacceptmap)rZ   r[   r]   r_   visitor rg   H/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/server/deps.pyget_dependencies   s   
ri   	module_idstrmodule_treer"   c              	   C  s   t |||j}|j| ` t|tr(|jD ]}t|ttt	t
fs&|| qn3t|trM|jrM|j|j || W d   n1 sGw   Y  n|| W d   |jS W d   |jS W d   |jS 1 spw   Y  |jS )zDGet dependencies of a target -- don't recursive into nested targets.N)rb   rc   scopemodule_scope
isinstancer   defsr   r   r   r%   rd   r   infoclass_scopere   )rj   rl   rZ   r[   r]   rf   defnrg   rg   rh   get_dependencies_of_target   s0   	





rt   c                      st  e Zd Z	ddddZd fddZd fddZd fddZd fddZdddZdd d!Z	dd#d$Z
dd&d'Zdd)d*Zd fd,d-Zd fd/d0Zdd3d4Zdd8d9Zdd<d=Zd fd?d@Zd fdBdCZd fdEdFZd fdHdIZddJdKZddMdNZd fdPdQZddUdVZd fdXdYZd fd[d\Zd fd]d^Zd fd`daZd fdcddZd fdfdgZdÇ fdidjZ dć fdldmZ!dŇ fdodpZ"dƇ fdrdsZ#ddxdyZ$dd{d|Z%dd~dZ&dʇ fddZ'dˇ fddZ(ḋ fddZ)d͇ fddZ*d· fddZ+dddZ,ddddZ-ddddZ.dddZ/dddZ0dddZ1dddZ2dddZ3dddZ4  Z5S )rb   Nr[   r\   r]   r^   rc   defaultdict[str, set[str]]r_   Options | Noner`   Nonec                 C  s0   t  | _|| _|| _i | _d| _d| _|| _d S )NF)r8   rm   r[   rc   re   is_classis_package_init_filer_   )selfr[   r]   rc   r_   rg   rg   rh   __init__   s   

zDependencyVisitor.__init__or   c                   s   | j |j1 | | _| | j   |j D ]\}}| j	|t
 | qt | W d    d S 1 s;w   Y  d S N)rm   rn   fullnamery   add_type_alias_depscurrent_targetplugin_depsitemsre   
setdefaultsetupdatesupervisit_mypy_file)rz   r|   triggertargets	__class__rg   rh   r      s   
"z!DependencyVisitor.visit_mypy_filer   c                   s   | j | | j  }|jr7| jrt|jtrt|j}n|j}| |D ]}| 	| | j	|t
|d q&|jrXt|jD ]}|  rJ|jdvrW| 	t
|jd |j  q?| | j   t | t|j|h }|D ]}t|tr}t | qpW d    d S 1 sw   Y  d S )NrZ   r{   __new__.)rm   function_scoper   typerx   ro   rA   r<   get_type_triggersadd_dependencyr9   rq   non_trivial_basesuse_logical_depsnamer~   r   r   visit_func_defr   expandedr   )rz   r|   rZ   	signaturer   basevariantsexr   rg   rh   r      s.   


"z DependencyVisitor.visit_func_defr   c                   s   |   s|jjs| j d u r| t|jj n6|jD ]2}d }t	|t
r+|jr+|j}t	|tr>t	|jt
r>|jjr>|jj}|d urN| t|t|jj qt | d S r}   )r   funcis_overloadrm   current_function_namer   r9   r~   
decoratorsro   r&   r   calleer   visit_decorator)rz   r|   dtnamer   rg   rh   r     s   
z!DependencyVisitor.visit_decoratorr   c                   s   | j |j: | j  }| t|| | j}d| _|jD ]}| t|j| q| 	|j t
 | || _W d    d S 1 sDw   Y  d S )NT)rm   rr   rq   current_full_targetr   r9   rx   	type_varsr~   process_type_infor   visit_class_def)rz   r|   rZ   old_is_classtvr   rg   rh   r   ,  s   

"z!DependencyVisitor.visit_class_defr!   c                 C  sJ   |j r#| j|j  | |j  W d    d S 1 sw   Y  d S d S r}   )rq   rm   rr   r   rz   r|   rg   rg   rh   visit_newtype_expr9  s
   "z$DependencyVisitor.visit_newtype_exprrq   r-   c                 C  s&  | j  }|jD ]	}| j||d q|jr| j|jt|d |jr,| j|jt|d |jr9| j|jt|d |jrR|j	d d D ]}| j
t|jt|d qC| | j   |j D ]:\}}t|jtr|jjr}t|r}| 
t|jd |  t|D ]}| j
t|jd | t|jd | d qq_t|D ]r}|j D ](\}}|  r||jvrq|dv rq| j
t|jd | t|jd | d q|  s| j
t|jd t|jd d | j
t|jd t|jd d | j
t|jd t|jd d | 
t|jd  qd S )Nr   r   r   	.__init__.__new__z.(abstract))rm   r   basesadd_type_dependencies
tuple_typer9   typeddict_typedeclared_metaclassis_protocolmror   r:   r~   r   r   namesr   ro   noder0   is_initialized_in_classhas_user_basesr   r   )rz   rq   rZ   r   	base_infor   r   rg   rg   rh   r   >  sh   




z#DependencyVisitor.process_type_infor   c                 C  s*   |j D ]\}}| t|| j  qd S r}   )idsr   r9   rm   r   )rz   r|   idas_idrg   rg   rh   visit_import  s   zDependencyVisitor.visit_importr   c                 C  sb   |   rd S t| j |j|j| j\}}| t| |j	D ]\}}| t|d |  qd S Nr   )
r   rY   rm   current_module_idrelativer   ry   r   r9   r   )rz   r|   rj   _r   as_namerg   rg   rh   visit_import_from  s   z#DependencyVisitor.visit_import_fromr   c                 C  s0   t | j |j|j| j\}}| t| d S r}   )rY   rm   r   r   r   ry   r   r:   )rz   r|   rj   r   rg   rg   rh   visit_import_all  s   z"DependencyVisitor.visit_import_allr   c                   s   |j st | d S d S r}   )is_unreachabler   visit_blockr   r   rg   rh   r     s   zDependencyVisitor.visit_blockr	   c                   s  |j }t|tr4t|jtr4|j}| j|jt|jd |j	D ]}| j|t|jd qt
 | nOt|trt|jtr|jj}| j  d|j }|j D ]3\}}|dst|jtr|jj}	|	r| |	 | j|	t|d t| d| }
| j|	|
d qSnt|trt|jtr|jj}|jd usJ | j  d|j }| j|jt|d nt|trt|jtr|jjj D ]\}}t|jtr|jjr| |jj qn|jr?t|jdksJ |jd }t|tsJ t| j |}	t|	t!r |	" r |	# j}| $t|d  | $t|d  t|t%r6t|jt&r6| |jjj' nM|	r>| |	 nDt
 (| |jD ]}| )| qH|j|g }t*t|d D ]}|| }||d  }t|t+rw| ,|d q_|jr| |j | - r|j.d u rt|trt|j/t0r|j/jrd }t|j/jt1r|j/j d	}|rt|jt2r|jj}n|j/j}|sd S |jD ]/}t|t0r|jr|j3r|j4t5kr d S | $t|t|j qd S d S d S d S d S d S )
Nr   r   r      r   r   r   __iter__r{   )6rvaluero   r   analyzedr.   r   upper_boundr9   r~   valuesr   visit_call_exprr   rq   rm   r   r   r   r   
startswithr   r0   r   r,   r   r   is_alias_deflenlvaluesr    rW   r[   getrA   is_type_objtype_objectr   r   r*   rZ   visit_assignment_stmtprocess_lvalueranger)   !add_attribute_dependency_for_exprr   unanalyzed_typer   r&   r-   r   
is_new_defkindr   )rz   r|   r   r   valrq   prefixr   symnodetypattr_targetlvalue
class_namer   ifnameinitlvr   rg   rh   r     s   







z'DependencyVisitor.visit_assignment_stmtr   r   c           
      C  s  t |tr| |jd dS t |tr@|jttfv r<| |}| 	|}t
| j  d|j }|D ]
}| || q3dS dS t |tr| |rk|jrk|j}t |trk|j}|rkt|rk| t
|jd |j  |jdu r|j| jvrxdS | j|j }| |}| 	|}| ||jD ]}|D ]}| || qqdS dS t |tr|jD ]}	| |	 qdS t |tr| |j dS dS )z/Generate additional dependencies for an lvalue.__setitem__r   N)ro   r   add_operator_method_dependencyr   r    r   r   r   get_non_partial_lvalue_typer   r9   rm   r   r   r   r   is_self_member_refr   r   r0   rq   r   r~   exprr[   attribute_triggersr)   r   r   r'   )
rz   r   lvalue_typetype_triggersattr_triggertype_triggerr   rq   object_typeitemrg   rg   rh   r     sJ   











z DependencyVisitor.process_lvalue
memberexprr   boolc                 C  s(   t |jtsdS |jj}t |to|jS )z1Does memberexpr to refer to an attribute of self?F)ro   r   r    r   r0   is_self)rz   r   r   rg   rg   rh   r   +  s   z$DependencyVisitor.is_self_member_refr&   rK   c                 C  sj   || j vrt S t| j | }t|tr3t|jtr+|jjr&t|jj}|S t }|S |jr0J t S |S r}   )	r[   rT   rW   ro   rH   r   r0   r   r   )rz   r   r   rg   rg   rh   r   2  s   

	
z-DependencyVisitor.get_non_partial_lvalue_typer#   c                   s`   t  | | |j t|j }| |j| |jtv r.d|dd   }| |j| d S d S )N__i   )r   visit_operator_assignment_stmtr   r   r3   opr   r4   )rz   r|   methodinplace_methodr   rg   rh   r   G  s   

z0DependencyVisitor.visit_operator_assignment_stmtr   c                   s   t  | |js"| |jd | |jd |jr!| |jd n| |jd |jr3| |jd | |j t	|jt
rP|j}|rP| |d | |d |jr[| |j d S d S )Nr   __getitem____next__	__aiter__	__anext__)r   visit_for_stmtis_asyncr   r   inferred_iterator_typeadd_attribute_dependencyr   indexro   r)   inferred_item_type
index_typer   )rz   r|   	item_typer   rg   rh   r  P  s&   z DependencyVisitor.visit_for_stmtr1   c                   sj   t  | |jD ]}|js| |d | |d q	| |d | |d q	|jD ]}| | q+d S )N	__enter____exit__
__aenter__	__aexit__)r   visit_with_stmtr   r  r   analyzed_typesr   )rz   r|   er   r   rg   rh   r  i  s   

z!DependencyVisitor.visit_with_stmtr   c                   s0   t  | t|jtr| |jjd d S d S )N__delitem__)r   visit_del_stmtro   r   r   r   r   r   r   rg   rh   r  u  s   z DependencyVisitor.visit_del_stmtc                 C  sr   |j r| t|j  t| j|}t|tr5| r7|	 j }| t|d  | t|d  d S d S d S )Nr   r   )
r~   r   r9   rW   r[   r   ro   rA   r   r   )rz   r|   r   r   rg   rg   rh   process_global_ref_expr|  s   
z)DependencyVisitor.process_global_ref_exprr    c                 C  s*   |j tkrd S |j tkrd S | | d S r}   )r   r   r   r  r   rg   rg   rh   visit_name_expr  s
   

z!DependencyVisitor.visit_name_exprr  c                   s  t |jtrt |jjtr| t|jjj nt 	| |j
d ur*| | d S |j| jvr2d S t |jtrPt |jjtrP| t|jjjd |j  d S t| j|j }| ||j |  r{t |tr}| ||}|d ur| t| d S d S d S d S r   )ro   r   r&   r   r-   r   r9   r~   r   visit_member_exprr   r  r[   r   r   rW   r  r   r=   get_unimported_fullname)rz   r  r   r   r   rg   rh   r    s$   
z#DependencyVisitor.visit_member_exprr   r=   
str | Nonec                 C  s   d}|j tjkr=t|jtr=d|j | }|j}|j| jvr dS t| j|j }t|t	s/dS |}|j tjkr=t|jts|j tj
krP|jrP|jd |j | S dS )zIf e refers to an unimported definition, infer the fullname of this.

        Return None if e doesn't refer to an unimported definition or if we can't
        determine the name.
         r   N)type_of_anyrN   from_another_anyro   r   r   r   r[   rW   r=   from_unimported_typemissing_import_name)rz   r  r   suffixobj_typerg   rg   rh   r    s   

z)DependencyVisitor.get_unimported_fullnamer(   c                   sd   |   s
t | |jd ur.|j}t|jD ]}| t|jd |  ||j	v r- d S qd S d S r   )
r   r   visit_super_exprrq   r   r   r   r9   r~   r   )rz   r  r   r   r   rg   rh   r    s   

z"DependencyVisitor.visit_super_exprr   c                   sr   t |jtr|jjdkr| | d S t | | j|j}|d ur5t	|}t |t
s7| |d d S d S d S )Nzbuiltins.isinstance__call__)ro   r   r&   r~   process_isinstance_callr   r   r[   r   rW   rA   r  rz   r  r   r   rg   rh   r     s   
z!DependencyVisitor.visit_call_exprc                   sb   t |jdkr)|jd }t|tr)|jtkr)t|jtr)|jr)| 	t
|j dS t | dS )zDProcess "isinstance(...)" in a way to avoid some extra dependencies.r   r   N)r   argsro   r&   r   r   r   r-   r~   r   r9   r   r   )rz   r  argr   rg   rh   r!    s   


z)DependencyVisitor.process_isinstance_callr   c                      t  | | |j d S r}   )r   visit_cast_exprr   r   rz   r  r   rg   rh   r&       z!DependencyVisitor.visit_cast_exprr   c                   r%  r}   )r   visit_assert_type_exprr   r   r'  r   rg   rh   r)    r(  z(DependencyVisitor.visit_assert_type_exprr+   c                   &   t  | |jD ]}| | q	d S r}   )r   visit_type_applicationtypesr   r"  r   rg   rh   r+       
z(DependencyVisitor.visit_type_applicationr   c                      t  | | |jd d S )Nr   )r   visit_index_exprr   r   r'  r   rg   rh   r/       z"DependencyVisitor.visit_index_exprr/   c                   s6   t  | |jtvrd S t|j }| |j| d S r}   )r   visit_unary_exprr   r6   r   r   )rz   r  r   r   rg   rh   r1    s
   

z"DependencyVisitor.visit_unary_exprr$   c                   s$   t  | | |j|j|j d S r}   )r   visit_op_exprprocess_binary_opr   leftrightr'  r   rg   rh   r2    s   zDependencyVisitor.visit_op_exprr   c                   sJ   t  | t|jD ]\}}|j| }|j|d  }| ||| qd S )Nr   )r   visit_comparison_expr	enumerate	operatorsoperandsr3  )rz   r  r   r   r4  r5  r   rg   rh   r6    s   
z'DependencyVisitor.visit_comparison_exprr   rk   r4  r5  c                 C  sX   t |}|r(|dkr| || d S | || t|}|r*| || d S d S d S )Nin)r3   r   r   r5   )rz   r   r4  r5  r   
rev_methodrg   rg   rh   r3    s   

z#DependencyVisitor.process_binary_opr   c                 C  s,   t | j|}|d ur| || d S d S r}   )rW   r[   r   'add_operator_method_dependency_for_type)rz   r  r   r   rg   rg   rh   r   (  s   z0DependencyVisitor.add_operator_method_dependencyrI   c                 C  s   t |tr
t|j}t |tr|j}t |tr(t|jj	d | }| 
| d S t |tr=|jD ]
}| t|| q0d S t |trO| rO| |j| d S t |trlt |jtrn|jjjd urp| |jjj| d S d S d S d S r   )ro   rQ   rW   r   rJ   partial_fallbackrB   r9   r   r~   r   rU   r   r<  rA   r   fallbackrO   r   metaclass_type)rz   r   r   r   r   rg   rg   rh   r<  -  s$   






z9DependencyVisitor.add_operator_method_dependency_for_typer   c                   r*  r}   )r   visit_generator_expr	sequencesadd_iter_dependencyrz   r  seqr   rg   rh   r@  @  r-  z&DependencyVisitor.visit_generator_exprr   c                   r*  r}   )r   visit_dictionary_comprehensionrA  rB  rC  r   rg   rh   rE  E  r-  z0DependencyVisitor.visit_dictionary_comprehensionr'   c                   r%  r}   )r   visit_star_exprrB  r   r'  r   rg   rh   rF  J  r(  z!DependencyVisitor.visit_star_exprr2   c                   r%  r}   )r   visit_yield_from_exprrB  r   r'  r   rg   rh   rG  N  r(  z'DependencyVisitor.visit_yield_from_exprr
   c                   r.  )N	__await__)r   visit_await_exprr   r   r'  r   rg   rh   rI  R  r0  z"DependencyVisitor.visit_await_exprrZ   c                 C  s0   || j v r| j | D ]}| t| q
d S d S r}   )rc   r   r9   )rz   rZ   aliasrg   rg   rh   r   X  s
   
z%DependencyVisitor.add_type_alias_depsr   c                 C  s:   | drdS |du r| j }| j|t | dS )zyAdd dependency from trigger to a target.

        If the target is not given explicitly, use the current target.
        )z
<builtins.z<typing.z<mypy_extensions.z<typing_extensions.N)r   rm   r   re   r   r   add)rz   r   rZ   rg   rg   rh   r   _  s   
z DependencyVisitor.add_dependencyc                 C  s    |  |D ]}| || qdS )zAdd dependencies to all components of a type.

        Args:
            target: If not None, override the default (current) target of the
                generated dependency.
        N)r   r   )rz   r   rZ   r   rg   rg   rh   r   p  s   z'DependencyVisitor.add_type_dependenciesr   c                 C  s$   |  ||}|D ]}| | qdS )z;Add dependencies for accessing a named attribute of a type.N)r   r   )rz   r   r   r   rZ   rg   rg   rh   r  z  s   z*DependencyVisitor.add_attribute_dependency	list[str]c                 C  s&  t |}t|trt |j}t|tr|j}t|tr)|jj d| }t	|gS t|t
rM| rM| j d| }t	|g}|| |j| |S t|treg }|jD ]}|| || qW|S t|tr| |j|}t|jtr|jjjdur|t	|jjjjj d|  |S g S )z<Return all triggers associated with the attribute of a type.r   N)rW   ro   rQ   r   rJ   r=  rB   r   r~   r9   rA   r   r   extendr   r>  rU   r   rO   r   r?  append)rz   r   r   membertriggersr   r   rg   rg   rh   r     s4   








z$DependencyVisitor.attribute_triggersc                 C  s(   | j |}|d ur| || d S d S r}   r[   r   r  )rz   r  r   r   rg   rg   rh   r     s   z3DependencyVisitor.add_attribute_dependency_for_exprr   c                 C  s$   | j |}|r| |d d S d S )Nr   rQ  )rz   r   r   rg   rg   rh   rB    s   z%DependencyVisitor.add_iter_dependencyc                 C  s   | j d uo| j jS r}   )r_   logical_deps)rz   rg   rg   rh   r     s   z"DependencyVisitor.use_logical_depsc                 C  s   t ||  S r}   )r   r   rz   r   rg   rg   rh   r     s   z#DependencyVisitor.get_type_triggersr}   )
r[   r\   r]   r^   rc   ru   r_   rv   r`   rw   )r|   r   r`   rw   )r|   r   r`   rw   )r|   r   r`   rw   )r|   r   r`   rw   )r|   r!   r`   rw   )rq   r-   r`   rw   )r|   r   r`   rw   )r|   r   r`   rw   )r|   r   r`   rw   )r|   r   r`   rw   )r|   r	   r`   rw   )r   r   r`   rw   )r   r   r`   r   )r   r&   r`   rK   )r|   r#   r`   rw   )r|   r   r`   rw   )r|   r1   r`   rw   )r|   r   r`   rw   )r|   r&   r`   rw   )r|   r    r`   rw   )r  r   r`   rw   )r  r   r   r=   r`   r  )r  r(   r`   rw   )r  r   r`   rw   )r  r   r`   rw   )r  r   r`   rw   )r  r+   r`   rw   )r  r   r`   rw   )r  r/   r`   rw   )r  r$   r`   rw   )r  r   r`   rw   )r   rk   r4  r   r5  r   r`   rw   )r  r   r   rk   r`   rw   )r   rI   r   rk   r`   rw   )r  r   r`   rw   )r  r   r`   rw   )r  r'   r`   rw   )r  r2   r`   rw   )r  r
   r`   rw   )rZ   rk   r`   rw   )r   rk   rZ   r  r`   rw   )r   rK   rZ   r  r`   rw   )r   rK   r   rk   r`   rw   )r   rK   r   rk   r`   rL  )r  r   r   rk   r`   rw   )r   r   r`   rw   )r`   r   r   rK   r`   rL  )6__name__
__module____qualname__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/  r1  r2  r6  r3  r   r<  r@  rE  rF  rG  rI  r   r   r   r  r   r   rB  r   r   __classcell__rg   rg   r   rh   rb      sh    


V


V
&
	


!









rb   Nr   rK   r   r   seen_aliasesset[TypeAliasType] | NonerL  c                 C  s   |  t||S )z=Return all triggers that correspond to a type becoming stale.)rd   TypeTriggersVisitor)r   r   rY  rg   rg   rh   r     s   r   c                   @  s   e Zd Z	dOdPdd	ZdQddZdRddZdSddZdTddZdUddZdVddZ	dWdd Z
dXd#d$ZdYd&d'ZdZd)d*Zd[d,d-Zd\d/d0Zd]d2d3Zd^d5d6Zd_d8d9Zd`d;d<Zdad>d?ZdbdAdBZdcdDdEZdddGdHZdedJdKZdfdMdNZdS )gr[  Nr   r   rY  rZ  r`   rw   c                 C  s   g | _ |pt | _|| _d S r}   )depsr   rY  r   )rz   r   rY  rg   rg   rh   r{     s   
zTypeTriggersVisitor.__init__r   rK   rL  c                 C  s   t || j| jS r}   )r   r   rY  rS  rg   rg   rh   r     s   z%TypeTriggersVisitor.get_type_triggersrB   c                 C  sj   t |jj}|g}|jD ]
}|| | q|jr#|| |j |jr3|jjr3|	t
|jj |S r}   )r9   r   r~   r#  rM  r   last_known_valueextra_attrsmod_namerN  r:   rz   r   r   rP  r$  rg   rg   rh   visit_instance  s   
z"TypeTriggersVisitor.visit_instancerL   c                 C  sn   || j v rg S | j | |jd usJ t|jj}|g}|jD ]
}|| | q || |jj |S r}   )	rY  rK  rJ  r9   r~   r#  rM  r   rZ   r`  rg   rg   rh   visit_type_alias_type  s   

z)TypeTriggersVisitor.visit_type_alias_typer=   c                 C  s   |j d urt|j gS g S r}   )r  r9   rS  rg   rg   rh   	visit_any  s   
zTypeTriggersVisitor.visit_anyrD   c                 C     g S r}   rg   rS  rg   rg   rh   visit_none_type     z#TypeTriggersVisitor.visit_none_typer>   c                 C  6   g }|j D ]
}|| | q|| |j |S r}   )	arg_typesrM  r   ret_typerz   r   rP  r$  rg   rg   rh   visit_callable_type  s
   
z'TypeTriggersVisitor.visit_callable_typerE   c                 C  $   g }|j D ]
}|| | q|S r}   r   rM  r   rz   r   rP  r   rg   rg   rh   visit_overloaded     
z$TypeTriggersVisitor.visit_overloadedtr@   c                 C     J d)NFz"Should not see an erased type hererg   )rz   rq  rg   rg   rh   visit_erased_type  s   z%TypeTriggersVisitor.visit_erased_typer?   c                 C  rd  r}   rg   rS  rg   rg   rh   visit_deleted_type  rf  z&TypeTriggersVisitor.visit_deleted_typerH   c                 C  rr  )NFz"Should not see a partial type hererg   rS  rg   rg   rh   visit_partial_type  s   z&TypeTriggersVisitor.visit_partial_typerJ   c                 C  rg  r}   )r   rM  r   r=  rn  rg   rg   rh   visit_tuple_type  s
   
z$TypeTriggersVisitor.visit_tuple_typerO   c                 C  sP   |  |j}| js&| }|D ]}||dd  ||dd  q|S )N>z
.__init__>z	.__new__>)r   r   r   copyrN  rstrip)rz   r   rP  old_triggersr   rg   rg   rh   visit_type_type  s   z#TypeTriggersVisitor.visit_type_typerQ   c                 C  sj   g }|j r|t|j  |jr|| |j |jr%|| |j |jD ]
}|| | q(|S r}   )r~   rN  r9   r   rM  r   defaultr   )rz   r   rP  r   rg   rg   rh   visit_type_var  s   
z"TypeTriggersVisitor.visit_type_varrG   c                 C  `   g }|j r|t|j  |jr|| |j |jr%|| |j || |j |S r}   r~   rN  r9   r   rM  r   r|  rz   r   rP  rg   rg   rh   visit_param_spec     z$TypeTriggersVisitor.visit_param_specrP   c                 C  r~  r}   r  r  rg   rg   rh   visit_type_var_tuple#  r  z(TypeTriggersVisitor.visit_type_var_tuplerV   c                 C  s   |j | S r}   )r   rd   rS  rg   rg   rh   visit_unpack_type.     z%TypeTriggersVisitor.visit_unpack_typerF   c                 C  rl  r}   )rh  rM  r   rj  rg   rg   rh   visit_parameters1  rp  z$TypeTriggersVisitor.visit_parametersrM   c                 C  s:   g }|j  D ]
}|| | q|| |j |S r}   )r   r   rM  r   r>  rn  rg   rg   rh   visit_typeddict_type7  s
   z(TypeTriggersVisitor.visit_typeddict_typerC   c                 C  s   |  |jS r}   )r   r>  rS  rg   rg   rh   visit_literal_type>  r  z&TypeTriggersVisitor.visit_literal_typerS   c                 C  rd  r}   rg   rS  rg   rg   rh   visit_unbound_typeA  rf  z&TypeTriggersVisitor.visit_unbound_typerT   c                 C  rd  r}   rg   rS  rg   rg   rh   visit_uninhabited_typeD  rf  z*TypeTriggersVisitor.visit_uninhabited_typerU   c                 C  rl  r}   rm  rn  rg   rg   rh   visit_union_typeG  rp  z$TypeTriggersVisitor.visit_union_typer}   )r   r   rY  rZ  r`   rw   rT  )r   rB   r`   rL  )r   rL   r`   rL  )r   r=   r`   rL  )r   rD   r`   rL  )r   r>   r`   rL  )r   rE   r`   rL  )rq  r@   r`   rL  )r   r?   r`   rL  )r   rH   r`   rL  )r   rJ   r`   rL  )r   rO   r`   rL  )r   rQ   r`   rL  )r   rG   r`   rL  )r   rP   r`   rL  )r   rV   r`   rL  )r   rF   r`   rL  )r   rM   r`   rL  )r   rC   r`   rL  )r   rS   r`   rL  )r   rT   r`   rL  )r   rU   r`   rL  )rU  rV  rW  r{   r   ra  rb  rc  re  rk  ro  rs  rt  ru  rv  r{  r}  r  r  r  r  r  r  r  r  r  rg   rg   rg   rh   r[    s2    






	





	







r[  new_depsr\  rw   c                 C  s*   |   D ]\}}||t | qd S r}   )r   r   r   r   )r  r\  r   r   rg   rg   rh   merge_dependenciesN  s   r  rq   r-   list[TypeInfo]c                 C  s   dd | j dd  D S )Nc                 S  s   g | ]	}|j d kr|qS )zbuiltins.object)r~   .0r   rg   rg   rh   
<listcomp>T  s    z%non_trivial_bases.<locals>.<listcomp>r   )r   rq   rg   rg   rh   r   S  s   r   c                 C  s   t dd | jdd  D S )Nc                 s  s    | ]}|j d vV  qdS ))builtinstypingenumN)module_namer  rg   rg   rh   	<genexpr>X  s    z!has_user_bases.<locals>.<genexpr>r   )anyr   r  rg   rg   rh   r   W  s   r   modulesdict[str, MypyFile]c                 C  s   i }|   D ]/\}}|dv sd|jv rq||jksJ t||||}|  D ]\}}	||t |	 q&qt| t	|  dd dD ]\}}	t
| t	|	D ]	}
t
d|
  qQqEdS )zKGenerate dependencies for all interesting modules and print them to stdout.)r  r  z
/typeshed/c                 S  s   | d S )Nr   rg   )xrg   rg   rh   <lambda>n  s    z'dump_all_dependencies.<locals>.<lambda>)keyz    N)r   pathr~   ri   r   r   r   rX   add_all_protocol_depssortedprint)r  r[   r]   r_   all_depsr   r   r\  r   r   rZ   rg   rg   rh   dump_all_dependencies[  s    
r  )
rZ   r   r[   r\   r]   r^   r_   r7   r`   ra   )rj   rk   rl   r   rZ   r"   r[   r\   r]   r^   r`   ra   r}   )r   rK   r   r   rY  rZ  r`   rL  )r  ra   r\  ra   r`   rw   )rq   r-   r`   r  )rq   r-   r`   r   )
r  r  r[   r\   r]   r^   r_   r7   r`   rw   )p__doc__
__future__r   collectionsr   r  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#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   mypy.operatorsr3   r4   r5   r6   mypy.optionsr7   
mypy.scoper8   mypy.server.triggerr9   r:   mypy.traverserr;   mypy.typeopsr<   
mypy.typesr=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   mypy.typestaterX   	mypy.utilrY   ri   rt   rb   r   rk   r[  r  r   r   r  rg   rg   rg   rh   <module>   s<    Q0t

     Z 


