
    X-Ph7                   x   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlm Z! ddl"Z#ddl$m%Z% ddl&m'Z'm(Z( dd	l)m*Z*m+Z+m,Z,m-Z- dd
l.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO erddlPmQZQ ddl#mRZS ddlTmUZU ddlVmWZW ddlXmYZY ddlZm[Z[ ddl\m]Z]m^Z^m_Z_ ddl`maZambZbmcZcmdZdmeZemfZfmgZg ddl6mhZh ddlimjZj ddlkmlZl ddlmmnZnmoZompZp ddlqmrZr ddlsmtZtmuZu dd lvmwZw dd!lxmyZymzZz dd"l{m|Z| dd#l}m~Z~mZ dd$lDmZmZ dd%lmZ d&Zd'ed(<   h d)Zd'ed*<   eed+f         Zd,ed-<    G d. d/          Z	 	 	 	 	 	 ddd@ZddDZddFZddHZ G dI dJe          Z G dK dLe          ZddPZdQZd'edR<   dSZd'edT<   dUZd'edV<   dWZd'edX<   dYZd'edZ<   d[Zd'ed\<   ddaZddeZddgZddjZddmZ G dn do          ZddsZdtZd'edu<   dvZd'edw<   dxZd'edy<   ddZddZddZdZd'ed<   ddZddZddZddZddZddZddZddZd dZddZddZddZddZddZddZ	  G d de          Z G d d+          Z	 	 	 	 	 d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 G dǄ dȦ          ZddɄZÐddʄZĐddd˄Z	 	 dddЄZƐddфZefddՄZȐddׄZɐddلZdefdd݄ZːddބZ̐ddZ͐ddZΐddZϐd dZdS (!  a  Facilities to analyze entire programs, including imported modules.

Parse and analyze the source files of a program in the correct order
(based on file dependencies), and collect the results.

This module only directs a build, which is performed in multiple passes per
file.  The individual passes are implemented in separate modules.

The function build() is the main interface to this module.
    )annotationsN)IteratorMappingSequenceSet)	TYPE_CHECKINGAnyCallableClassVarFinal
NamedTupleNoReturnTextIO	TypedDict)	TypeAlias)TypeChecker)OUTPUT_CHOICESErrorFormatter)CompileError	ErrorInfoErrorsreport_internal_error)prepare_sccsstrongly_connected_componentstopsort)TypeIndirectionVisitor)MessageBuilder)Import	ImportAll
ImportBase
ImportFromMypyFileSymbolTableTypeInfo) PossiblyUndefinedVariableVisitor)SemanticAnalyzer)SemanticAnalyzerPreAnalysis)DecodeErrordecode_python_encodingget_mypy_commentshash_digestis_stub_package_fileis_sub_path_normabsis_typeshed_filemodule_prefixread_py_filetime_reftime_spent_usReports)
errorcodes)parse_mypy_comments)fixup_module)	free_tree)FileSystemCache)FilesystemMetadataStoreMetadataStoreSqliteMetadataStore)BuildSourceBuildSourceSetFindModuleCacheModuleNotFoundReasonModuleSearchResultSearchPathscompute_search_paths)
Expression)Options)parse)ChainedPluginPluginReportConfigContext)DefaultPlugin)LimitedVariableRenameVisitorVariableRenameVisitor)dump_type_stats)%is_module_from_legacy_bundled_packagestub_distribution_name)Type)reset_global_state
type_state)
json_dumps
json_loads)__version__Fr   DEBUG_FINE_GRAINED>   collections.abcabcsystypestypingbuiltins	_typeshedcollectionsmypy_extensions_collections_abctyping_extensionsCORE_BUILTIN_MODULESState
_TypeAliasGraphc                      e Zd ZdZd
dZd	S )BuildResultaP  The result of a successful build.

    Attributes:
      manager: The build manager.
      files:   Dictionary from module name to related AST node.
      types:   Dictionary from parse tree node to its inferred type.
      used_cache: Whether the build took advantage of a pre-existing cache
      errors:  List of error messages.
    managerBuildManagergraphre   returnNonec                x    || _         || _        |j        | _        |j        | _        |j        | _        g | _        d S N)	rh   rj   modulesfiles	all_typesrZ   cache_enabled
used_cacheerrors)selfrh   rj   s      J/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/build.py__init__zBuildResult.__init__   s8    
_
&
!/!#    N)rh   ri   rj   re   rk   rl   )__name__
__module____qualname____doc__rw    rx   rv   rg   rg   |   s2         $ $ $ $ $ $rx   rg   sourceslist[BuildSource]optionsrE   alt_lib_path
str | Noneflush_errors4Callable[[str | None, list[str], bool], None] | NonefscacheFileSystemCache | NonestdoutTextIO | Nonestderrextra_pluginsSequence[Plugin] | Nonerk   c           
        g dfd	}|p|}|pt           j        }|pt           j        }|pg }	 t          | |||||||          }	|	_        |	S # t
          $ r'}
|
j         } |d
|
j        |           |
_         d
}
~
ww xY w)ag  Analyze a program.

    A single call to build performs parsing, semantic analysis and optionally
    type checking for the program *and* all imported modules, recursively.

    Return BuildResult if successful or only non-blocking errors were found;
    otherwise raise CompileError.

    If a flush_errors callback is provided, all error messages will be
    passed to it and the errors and messages fields of BuildResult and
    CompileError (respectively) will be empty. Otherwise those fields will
    report any error messages.

    Args:
      sources: list of sources to build
      options: build options
      alt_lib_path: an additional directory for looking up library modules
        (takes precedence over other directories)
      flush_errors: optional function to flush errors after a file is processed
      fscache: optionally a file-system cacher

    filenamer   new_messages	list[str]
is_seriousboolrk   rl   c                2                         |           d S rn   )extend)r   r   r   messagess      rv   default_flush_errorsz#build.<locals>.default_flush_errors   s     	%%%%%rx   N)r   r   r   r   r   r   rk   rl   )rY   r   r   _buildrt   r   
use_stdoutr   )r~   r   r   r   r   r   r   r   r   resulteseriousr   s               @rv   buildr      s    D H& & & & & &
  7#7L!szF!szF!'RMWlL'66S`
 
 !   
 l"T1:w///
s   A 
A?"A::A?-Callable[[str | None, list[str], bool], None]r   Sequence[Plugin]c                	   t          j                    dk    rt          j        ddd           t	                      }|pt                      }t          | |||          }	d }
|j        rddlm	}  |||j                  }
t          |           }|j        t          |fd          }t          ||||          \  }}t          j                            |j                  }t%          ||	t          j                    ||
|t(          ||||j        d nt-          j        |j                  ||||          }|                                d	k    r"|                    t5          |                     t7                       	 t9          | ||          }|j        st=          j                     |j         tC          |j         |           |j"        tG          |j"        |           tI          ||          tK          j%                    }|j&        '                                 |(                    tK          j%                    |z
  
           |)                    dtK          j%                    |j*        z
  tW          |j,                  |j-        .                                fz             |/                                 |
|
0                                 |sLt          j                            |j                  r(tc          |j                   te          |j                   t          j                            |j                  rtg          |j        |j4                   S S # tK          j%                    }|j&        '                                 |(                    tK          j%                    |z
  
           |)                    dtK          j%                    |j*        z
  tW          |j,                  |j-        .                                fz             |/                                 |
|
0                                 |sLt          j                            |j                  r(tc          |j                   te          |j                   t          j                            |j                  rtg          |j        |j4                   w w xY w)NCPythoni@    r   r3   c                $    t          |           S rn   )r0   )pathcached_reads    rv   <lambda>z_build.<locals>.<lambda>   s    l46U6U rx   )read_source)ignore_prefix
source_setreportsr   
version_idpluginplugins_snapshotrt   error_formatterr   r   r   r      )cache_commit_timez=Build finished in %.3f seconds with %d modules, and %d errors)5platformpython_implementationgcset_thresholddefault_data_dirr9   rC   report_dirsmypy.reportr4   r>   readr   load_pluginsosr   isdir	cache_dirri   getcwdrU   outputr   get	verbositytracereprrQ   dispatchfine_grained_incrementalrR   reset_all_subtype_cachestiming_statsdump_timing_statsline_checking_statsdump_line_checking_statsrg   time	metastorecommit	add_statslog
start_timelenro   rt   num_messages
dump_statsfinishadd_catch_all_gitignoreexclude_from_backupsrecord_missing_stub_packagesmissing_stub_packages)r~   r   r   r   r   r   r   r   data_dirsearch_pathsr   r4   r   rt   r   snapshotcache_dir_existedrh   rj   t0r   s                       @rv   r   r      s    %''944 	R,,,!!H***G'(LQQLG 9'''''''(G$788((J,KG)U)U)U)UVVVF#GVV]KKFH g&788
 ikk! ' 6N<Nw~<^<^!  G" ad7mm$$$['622/ 	2/111+g2E:::&2$W%@%HHH7E**Y[[  """DIKK",<===K	g00GO$$++--	
 	
 	
 	NN  	4RW]]73D%E%E 	4#G$5666 !23337==*++ 	[():G<YZZZZ	[% Y[[  """DIKK",<===K	g00GO$$++--	
 	
 	
 	NN  	4RW]]73D%E%E 	4#G$5666 !23337==*++ 	[():G<YZZZZ	[s   ?A2M E,Sstrc                 J    t           j                            t                    S )z0Returns directory containing typeshed directory.)r   r   dirname__file__r}   rx   rv   r   r   *  s    7??8$$$rx   r   c                    |j         rt          j                            |           S t          j                            |           S )zConvert path to absolute; but to relative in bazel mode.

    (Bazel's distributed cache doesn't like filesystem metadata to
    end up in output files.)
    )bazelr   r   relpathabspath)r   r   s     rv   normpathr   /  s6     } %wt$$$wt$$$rx   c                      e Zd ZU ded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   dS )	CacheMetar   idr   intmtimesizehashr   dependencies
data_mtime	data_json
suppressedzdict[str, object] | Noner   	list[int]	dep_prios	dep_linesinterface_hashr   r   
ignore_allr	   plugin_dataNry   rz   r{   __annotations__r}   rx   rv   r   r   >  s         GGGIIIJJJIIIIIIOOONNN%%%%OOOrx   r   c                  $    e Zd ZU ded<   ded<   dS )	FgDepMetar   r   r   r   Nr   r}   rx   rv   r   r   X  s"         IIIJJJJJrx   r   metadict[str, Any]r   c                   d}t          |                     d|          |                     d|          d| v rt          | d                   n||                     d|          |                     d|          |                     dg           d| v rt          | d                   n|||                     d	g           |                     d
          |                     dg           |                     dg           |                     dd          |                     d|          |                     dd          |                     dd                    S )zBuild a CacheMeta object from a json metadata dictionary

    Args:
      meta: JSON metadata read from the metadata cache file
      data_json: Path to the .data.json file containing the AST trees
    Nr   r   r   r   r   r   r   r   r   r   r   r    r   r   Tr   )r   r   r   )r   r   sentinels      rv   cache_meta_from_dictr   ]  s5    Hx  ""%ooDM8""""$$#/4#7#7DXr""b!!b!!!2&&x((t$$%%!  rx      PRI_HIGH
   PRI_MED   PRI_LOW   PRI_MYPYr   PRI_INDIRECTc   PRI_ALLimpr    toplevel_priorityr   c                Z    | j         st          S | j        rt          t          |          S |S )z,Compute import priority from an import node.)is_top_levelr  is_mypy_onlymaxr  )r
  r  s     rv   import_priorityr    s4     
 08.///rx   rt   r   #tuple[list[Plugin], dict[str, str]]c                z   ddl }i }| j        sg |fS t          | j        dd          dk    rddfd}g }                    | j        d|            | j        D ]Y}d}d}	dt
          j                            |          v r|                    dd          \  }}|	                    d          rt
          j        
                    t
          j                            | j                  |          }t
          j                            |          s |d| d           t
          j                            t
          j                            |                    }	t
          j                            |          }
|
dd         }t          j                            d|	           nFt!          j        d|          r/t
          j                            |          }
 |d|
 d           n|}	 |                    |          }n(# t&          $ r} |d| d|            Y d}~nd}~ww xY w|	%t          j        d         |	k    sJ t          j        d= n,# |	%t          j        d         |	k    sJ t          j        d= w xY wt)          ||          s |d                    ||                     	  t-          ||          t.                    }n$# t&          $ r t1          d| d|            w xY wt3          |t4                    s |d                    ||                     t7          |t8                    s |d                    |                     	 |                     ||                      t=          |          ||<   2# t&          $ r t1          d|j         d|            w xY w||fS )zLoad all configured plugins.

    Return a list of all the loaded plugins from the config file.
    The second return value is a snapshot of versions/hashes of loaded user
    plugins (for cache validation).
    r   Nmypyplugins   messager   rk   r   c                b                         d|                                d           d S )Nr   F)r   )reportraise_error)r  rt   lines    rv   plugin_errorz.load_plugins_from_config.<locals>.plugin_error  s6    dAw'''e,,,,,rx   r   :.pyzCan't find plugin ""z[\\/]zPlugin "z" does not have a .py extensionzError importing plugin "z": z5Plugin "{}" does not define entry point function "{}"z1Error calling the plugin(version) entry point of 
filezFType object expected as the return value of "plugin"; got {!r} (in {})zKReturn value of "plugin" must be a subclass of "mypy.plugin.Plugin" (in {})z&Error constructing plugin instance of )r  r   rk   r   ) 	importlibconfig_filefind_config_file_line_numberset_filer  r   r   basenamersplitendswithjoinr   isfiler   rY   insertresearchimport_module	ExceptionhasattrformatgetattrrU   print
isinstancetype
issubclassrH   appendtake_module_snapshotry   )r   rt   r   r$  r   r  custom_pluginsplugin_path	func_name
plugin_dirfnammodule_namemoduleexcplugin_typer  s    `             @rv   load_plugins_from_configrD    s^    !H 8|'(;VYOODrzz- - - - - - - $&N
OOG'w777 = =	!%
"'"";////%0%7%7Q%?%?"K&& 	&',,rww7J'K'K[YYK7>>+.. DBKBBBCCC )E)EFFJ7##K00Dss)KHOOAz****Yx-- 	&7##K00DLIDIIIJJJJ%K	 ,,[99FF 	K 	K 	KLIKIICIIJJJJJJJJ	K %x{j0000HQK %x{j0000HQKvy)) 	LGNN   	4'&)44[AAKK 	 	 	UkUUU\bcccc	 +t,, 	LX__   
 +v.. 	L &--  	!!++g"6"6777$8$@$@H[!! 	 	 	S;;OSSSZ`aaaa	 8##sH   1HI
H,H'"I'H,,I)J 3K!K30N&N6tuple[Plugin, dict[str, str]]c                    t          | ||          \  }}||z  }t          |           }|s||fS t          | ||gz             |fS )a  Load all configured plugins.

    Return a plugin that encapsulates all plugins chained together. Always
    at least include the default plugin (it's last in the chain).
    The second return value is a snapshot of versions/hashes of loaded user
    plugins (for cache validation).
    )rD  rJ   rG   )r   rt   r   r   r;  r   default_plugins          rv   r   r     sc      8PPNHm#N*733N (x'' .N3C"CDDhNNrx   rA  types.ModuleTypec                   t          | d          rX| j        J t          | j        d          5 }t          |                                          }ddd           n# 1 swxY w Y   nd}t          | dd          }| d| S )zTake plugin module snapshot by recording its version and hash.

    We record _both_ hash and the version to detect more possible changes
    (e.g. if there is a change in modules imported by a plugin).
    r   NrbunknownrU   noner  )r2  r   openr+   r   r4  )rA  fdigestvers       rv   r:  r:    s     vz"" ***&/4(( 	+A **F	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 
&-
0
0CFs   "AA!$A!sectionsetting_namec                   d}	 g }t          | d          5 }t          |          D ]\  }}|                                }|                    d          r8|                    d          r#|dd                                         }||k    }f|r0t          j        | d|          r|                    |dz              	 d	d	d	           n# 1 swxY w Y   t          |          dk    r|d
         S n# t          $ r Y nw xY wdS )zReturn the approximate location of setting_name within mypy config file.

    Return -1 if can't determine the line unambiguously.
    FzUTF-8)encoding[]r  r  z\s*=Nr   )
rM  	enumeratestrip
startswithr*  r.  matchr9  r   OSError)	r   rQ  rR  in_desired_sectionresultsrN  ir  current_sections	            rv   r&  r&    st   
 $))) 	*Q$Q<< * *4zz||??3'' *DMM#,>,> *&*1R4j&6&6&8&8O)8G)C&&' *BH5K5K5KT,R,R *NN1q5)))*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* w<<11:    2s5   C4 B)CC4 CC4 CC4 4
D Dc                      e Zd ZdZ	 dBdCd ZdDd!ZdEd#ZdFd%ZdGd'ZdHd)Z	dId-Z
dJd/ZdKd2ZdLd4ZdMd7ZdNd8ZdOd:ZdOd;ZdOd<ZdPd?ZdQdAZdS )Rri   aK	  This class holds shared state for building a mypy program.

    It is used to coordinate parsing, import processing, semantic
    analysis and type checking.  The actual build steps are carried
    out by dispatch().

    Attributes:
      data_dir:        Mypy data directory (contains stubs)
      search_paths:    SearchPaths instance indicating where to look for modules
      modules:         Mapping of module ID to MypyFile (shared by the passes)
      semantic_analyzer:
                       Semantic analyzer, pass 2
      all_types:       Map {Expression: Type} from all modules (enabled by export_types)
      options:         Build options
      missing_modules: Set of modules that could not be imported encountered so far
      stale_modules:   Set of modules that needed to be rechecked (only used by tests)
      fg_deps_meta:    Metadata for fine-grained dependencies caches associated with modules
      fg_deps:         A fine-grained dependency map
      version_id:      The current mypy version (based on commit id when possible)
      plugin:          Active mypy plugin(s)
      plugins_snapshot:
                       Snapshot of currently active user plugins (versions and hashes)
      old_plugins_snapshot:
                       Plugins snapshot from previous incremental run (or None in
                       non-incremental mode and if cache was not found)
      errors:          Used for reporting all errors
      flush_errors:    A function for processing errors after each SCC
      cache_enabled:   Whether cache is being read. This is set based on options,
                       but is disabled if fine-grained cache loading fails
                       and after an initial fine-grained load. This doesn't
                       determine whether we write cache files or not.
      quickstart_state:
                       A cache of filename -> mtime/size/hash info used to avoid
                       needing to hash source files when using a cache with mismatching mtimes
      stats:           Dict with various instrumentation numbers, it is used
                       not only for debugging, but also required for correctness,
                       in particular to check consistency of the fine-grained dependency cache.
      fscache:         A file system cacher
      ast_cache:       AST cache to speed up mypy daemon
    Nr   r   r   rB   r   r   r>   r   Reports | Noner   rE   r   r   rH   r   dict[str, str]rt   r   r   r   r   r9   r   r   r   r   ErrorFormatter | Nonerk   rl   c                6   i | _         || _        || _        t          j                    | _        || _        |
| _        | j                            |           || _        || _	        || _
        || _        || _        || _        i | _        t                      | _        i | _        i | _        t'          |t(                    st)          ||g          }|| _        t                      | _        t/          | j        | j        | j        | j        | j                  | _        i | _        t5                      | _        t                      | _        t                      | _        || _        |d uo|j        }|j         o|j!         p|j"        o| | _#        || _$        tK          | j	        | j$        | j        | j
                  | _&        tN          D ]}|j(        r
| j&        )                    |d          }t'          |tT                    stW          d| dg          tY          |j-        |          st]          |          rttW          dt^          j0        1                    |           d| dd	| d
g          te          |          | _3        i | _4        | j        j5        tm          | j        j5                  | _4        i | _7        || _        |	| _8        ts          |           | _:        tw          || j                  | _<        g | _=        t                      | _>        i | _?        d S )N)r   T	fast_pathzFailed to find builtin module z, perhaps typeshed is broken?zmypy: "z" shadows library module "r  z1note: A user-defined top-level module with name "z" is not supported)@statsr   r   r   r   r   rt   set_ignore_prefixr   r   r   r   r   r   ro   setmissing_modulesfg_deps_metafg_depsr6  rG   r   incomplete_namespacesr&   semantic_analyzerrq   r   indirection_detectorstale_modulesrechecked_modulesr   	reportersincrementalr   use_fine_grained_cacherr   r   r?   find_module_cacherb   use_builtins_fixturesfind_moduler   r   r.   abs_custom_typeshed_dirr,   r   r   r   create_metastorer   
shadow_mapshadow_filedictshadow_equivalence_mapr   read_plugins_snapshotold_plugins_snapshotread_quickstart_filequickstart_stateprocessed_targetsr   	ast_cache)ru   r   r   r   r   r   r   r   r   r   rt   r   r   r   r   r   has_reportersrA  r   s                      rv   rw   zBuildManager.__init__S  s-   $ &(
)++ %%m444.($$,.),24
 -/&-00 	6"7VH55F 03uu"!1L &KK"
 "
 24$:$<$<!'*uu+.55(t+A0A "55W9W"!! 	
 !0t|T\do"
 "
 "
 + 	 	F, )55f5MMDdC(( "[f[[[\     ?FF J^K K  Xbgood33XXvXXXbbbb   *'22 +-<#/"4<#;<<DO=?# 0$9$$?$?! 4Wdk J J 9;/2uu" GIrx   c                    | j         j        r_t          d           t          |                                                                           D ]\  }}t          |dz   d|            d S d S )NzStats:r  24)r   dump_build_statsr5  sortedstats_summaryitems)ru   keyvalues      rv   r   zBuildManager.dump_stats  s    <( 	0(OOO$T%7%7%9%9%?%?%A%ABB 0 0
Us..u..////	0 	00 0rx   r   c                (    | j         o| j        j        S rn   )rr   r   rt  ru   s    rv   rt  z#BuildManager.use_fine_grained_cache  s    !Idl&IIrx   r   c                4   | j         s|S t          || j                  }|| j        v }|sP| j                                         D ]6\  }}| j                            ||          r|| j        |<    nd | j        |<   7| j                            |          }|r|n|S rn   )rz  r   r   r}  r  r   samefiler   )ru   r   previously_checkedsourceshadowr{  s         rv   maybe_swap_for_shadow_pathz'BuildManager.maybe_swap_for_shadow_path  s     	Kdl++!T%@@! 	="&/"7"7"9"9 = =<((v66 =8>D/5E8<D/55155d;;)3{{t3rx   os.stat_result | Nonec                \    | j                             |                     |                    S rn   )r   stat_or_noner  ru   r   s     rv   get_statzBuildManager.get_stat  s&    |(()H)H)N)NOOOrx   r   c                l    | j         j        rdS t          | j                            |                    S )zReturn a file's mtime; but 0 in bazel mode.

        (Bazel's distributed cache doesn't like filesystem metadata to
        end up in output files.)
        r   )r   r   r   r   getmtimer  s     rv   r  zBuildManager.getmtime  s4     < 	61t~..t44555rx   r#  r"   list[tuple[int, str, int]]c           	     4    d fd}g }j         D ]}|j        st          |t                    rt	          |t
                    }t	          |t                    }|j        D ]\  }}|                    |||j	        f           |
                    d          dd         }	g }
|	D ]G}|
                    |           |                    |d                    |
          |j	        f           Ht          |t                    r ||          }d	}t	          |t
                    }|j        D ]B\  }}|dz   |z   }                     |          r|                    |||j	        f           @d
}Ct	          ||st          nt                    }|                    |||j	        f           t          |t                     r;t	          |t                    }|                    | ||          |j	        f           |                    d            |S )a  Find all reachable import statements in a file.

        Return list of tuples (priority, module id, import line number)
        for all modules imported in file; lower numbers == higher priority.

        Can generate blocking errors on bogus relative imports.
        r
  ImportFrom | ImportAllrk   r   c                   j         }| j        }|dk    r| j        S t          j                            j                                      d          r|dz  }|dk    r1d                    |                    d          d|                    }| j        r|dz   | j        z   n|}|sNj	        
                    j        j        j                   j	                            | j        ddd           |S )	z)Function to correct for relative imports.r   z	__init__.r  .Nz2No parent module -- cannot perform relative importTblocker)fullnamerelativer   r   r   r(  rY  r+  splitrt   r'  namer   r  r  )r
  file_idrelnew_idr#  ru   s       rv   correct_rel_impzBBuildManager.all_imported_modules_in_file.<locals>.correct_rel_imp  s    mG,Caxxvw	**55kBB qaxx((7==#5#5ete#<==/2vBWs]SV++7F $$TY	4<HHH""Ha!U_c #    Mrx   r  Nr  TFc                :    | d                              d           S )Nr  r  )countxs    rv   r   z;BuildManager.all_imported_modules_in_file.<locals>.<lambda>7  s    !

3/ rx   r  )r
  r  rk   r   )importsis_unreachabler6  r   r  r  r  idsr9  r  r  r+  r!   names	is_moduler   r   sort)ru   r#  r  resr
  priancestor_prir   _ancestor_parts	ancestorspartcur_idall_are_submodulesr  __sub_ids   ``               rv   all_imported_modules_in_filez)BuildManager.all_imported_modules_in_file  s`   	 	 	 	 	 	 	( +-< !	F !	FC%  Fc6** F)#w77C#23#@#@L!$ V VA

CSX#6777)+#ss);$&	$2 V VD%,,T222JJchhy6I6I38'TUUUUV	V  Z00 F,_S11F)-&)#w77C$'I 7 7b!'#!4>>&11 7JJVSX'>????16.. *#?Q/^xxW^__CJJVSX67777Y// F)#x88CJJ__S%9%938DEEE 	//000
rx   r   c                &    t          ||           duS )z>Is there a file in the file system corresponding to module id?Nfind_module_simple)ru   r   s     rv   r  zBuildManager.is_module:  s    !"d++477rx   r  ignore_errorsc                "   t          j                     }|r| j        j                            |           t	          |||| j        |          }||_        |                     dt          |j                   t          |j                  t          j                     |z
             | j        	                                r.| 
                    d           | j                                         | j                            ||j        |           |S )zoParse the source of a file with the given name.

        Raise CompileError if there is a parse error.
        r   r  )files_parsedmodules_parsedstubs_parsed
parse_timezBailing due to parse errors)r   rt   ignored_filesaddrF   	_fullnamer   r   is_stubis_blockersr   r  set_file_ignored_linesignored_lines)ru   r   r   r  r  r   r   trees           rv   
parse_filezBuildManager.parse_file>  s     Y[[ 	0K%))$///VT2t{GDDD4</00T\**y{{R'	 	 	
 	
 	
 ;""$$ 	&HH2333K##%%%**41C]SSSrx   dict[str, set[str]]c                D   t          j                     }|| j        v r9t          | j                            | j        |         d                             }ni }d |                                D             }|                     t          j                     |z
             |S )Nr   c                4    i | ]\  }}|t          |          S r}   )ri  .0kvs      rv   
<dictcomp>z7BuildManager.load_fine_grained_deps.<locals>.<dictcomp>_  s$    222TQq#a&&222rx   load_fg_deps_time)r   rk  rT   r   r   r  r   )ru   r   r   depsvals        rv   load_fine_grained_depsz#BuildManager.load_fine_grained_depsX  s    Y[["""dn11$2CB2G2OPPQQDDD22TZZ\\222r)9:::
rx   type_mapdict[Expression, Type]c                    | j         >| j                            |          r&| j                             || j        ||           d S d S d S rn   )r   r   	is_sourcer#  ro   )ru   r#  r  r   s       rv   report_filezBuildManager.report_filec  sS     <#(A(A$(G(G#LdDL(GDDDDD $###rx   c                    | j         j        S rn   )r   r   r  s    rv   r   zBuildManager.verbosityi  s    |%%rx   r  c                    |                                  dk    rH|rt          dg|R d| j        i nt          | j                   | j                                         d S d S )Nr  zLOG: r#  r"  r   r5  r   flushru   r  s     rv   r   zBuildManager.logl  sw    >>q   (g::::dk::::4;''''K ! rx   c                    dd l }|                                 dk    r | j        dg|R   d S |j        j        rD|rt          |d| j        i nt          | j                   | j                                         d S d S )Nr   r  zfine-grained:r#  r"  )
mypy.buildr   r   r   rV   r5  r   r  )ru   r  r  s      rv   log_fine_grainedzBuildManager.log_fine_grainedt  s    >>q  DH_/w//////Z* 	  (w1T[11114;''''K	  	 rx   c                    |                                  dk    r0t          dg|R d| j        i | j                                         d S d S )Nr   zTRACE:r#  r  r  s     rv   r   zBuildManager.trace  sY    >>q  (7W7774;777K ! rx   kwdsr	   c                    |                                 D ].\  }}|| j        v r| j        |xx         |z  cc<   $|| j        |<   /d S rn   )r  rg  )ru   r  r  r  s       rv   r   zBuildManager.add_stats  s[    **,, 	( 	(JCdj  
35("'
3		( 	(rx   Mapping[str, object]c                    | j         S rn   )rg  r  s    rv   r  zBuildManager.stats_summary  s
    zrx   rn   ) r   r   r   rB   r   r   r   r>   r   ra  r   rE   r   r   r   rH   r   rb  rt   r   r   r   r   r9   r   r   r   r   r   rc  rk   rl   rk   rl   rk   r   )r   r   rk   r   )r   r   rk   r  )r   r   rk   r   )r#  r"   rk   r  )r   r   rk   r   )r   r   r   r   r  r   r  r   r   rE   rk   r"   )r   r   rk   r  )r#  r"   r  r  r   rE   rk   rl   )rk   r   )r  r   rk   rl   )r  r	   rk   rl   )rk   r  )ry   rz   r{   r|   rw   r   rt  r  r  r  r  r  r  r  r  r   r   r  r   r   r  r}   rx   rv   ri   ri   )  s       ' 'r 26!rI rI rI rI rIh0 0 0 0J J J J4 4 4 4$P P P P	6 	6 	6 	6H H H HT8 8 8 8   4	 	 	 	E E E E& & & &                     
( ( ( (     rx   ri   r  r  bytesc                X    t          d |                                 D                       S )Nc                4    i | ]\  }}|t          |          S r}   )listr  s      rv   r  z deps_to_json.<locals>.<dictcomp>  s$    888daq$q''888rx   )rS   r  r  s    rv   deps_to_jsonr    s'    88aggii888999rx   z@deps.meta.jsonDEPS_META_FILEz@root.deps.jsonDEPS_ROOT_FILEz@rootFAKE_ROOT_MODULErdepsdict[str, dict[str, set[str]]]rh   rj   rl   c                   |j         }d}|j                                        }| D ]}|t          k    r&t	          |||         j        |j                  \  }}}nt          }|sJ |                    d|           |j         	                    |t          | |                             s|                    d|            d}||                    |          d||<   i }	|                                D ]/\  }}
|
j        r|
j        }n|
j        r|
j        j        }nd}||	|<   0|	|d}|	                    t           t#          |                    s|                    dt                       d}|rS|j                            t)          |j                  d	|j                   |j                            d
d
dd           d	S d	S )a  Write cache files for fine-grained dependencies.

    Serialize fine-grained dependencies map for fine grained mode.

    Dependencies on some module 'm' is stored in the dependency cache
    file m.deps.json.  This entails some spooky action at a distance:
    if module 'n' depends on 'm', that produces entries in m.deps.json.
    When there is a dependency on a module that does not exist in the
    build, it is stored with its first existing parent module. If no
    such module exists, it is stored with the fake module FAKE_ROOT_MODULE.

    This means that the validity of the fine-grained dependency caches
    are a global property, so we store validity checking information for
    fine-grained dependencies in a global cache file:
     * We take a snapshot of current sources to later check consistency
       between the fine-grained dependency cache and module cache metadata
     * We store the mtime of all of the dependency files to verify they
       haven't changed
    FzWriting deps cachez*Error writing fine-grained deps JSON file T)r   r   r   )r   	deps_metaz/Error writing fine-grained deps meta JSON file Nr   z-Error writing fine-grained dependencies cacher  )r   rk  copyr  get_cache_namesxpathr   r  r   writer  r  r  source_hashr   r   r  rS   rt   r'  _cache_dir_prefixr  )r  rh   rj   r   errorrk  r   r  	deps_jsonmeta_snapshotstr   r   s                rv   write_deps_cacher    s    , !IE',,..L Y Y!!!-b%)/7?SSOAq))&I()444 &&y,uRy2I2IJJ 	YKKPYPPQQQEE(1G<L<LY<W<WXXL$&M++-- ! !B > 	>DDw w| b%LAAD??>:d+;+;<< VnVVWWW c 1'/ B BD'/ZZZa$S]abbbbbc crx   r  c                v   ddl m} d |                                D             }|                                 D ]\  }}t          | ||                    }|r||         j        st
          }|                    |i           }|                    |t                                                    |           |S )aS  Splits fine-grained dependencies based on the module of the trigger.

    Returns a dictionary from module ids to all dependencies on that
    module. Dependencies not associated with a module in the build will be
    associated with the nearest parent module that is in the build, or the
    fake module FAKE_ROOT_MODULE if none are.
    r   )trigger_to_targetc                (    i | ]\  }}|j         |i S r}   )r  r  r   r  s      rv   r  zinvert_deps.<locals>.<dictcomp>  s'    ,[,[,[BSUSZ,[R,[,[,[rx   )	mypy.server.targetr  r  r/   r  r  
setdefaultri  update)r  rj   r  r  triggertargetsrA  	mod_rdepss           rv   invert_depsr    s     544444
 -\,[%++--,[,[,[E JJLL = =u&7&7&@&@AA 	&U6]/ 	&%F$$VR00	Wcee,,33G<<<<Lrx   c                    ddl m} t          | j        |          }|                                D ]&\  }}|                     |          } |||           '|S )a&  Generate fine-grained dependencies into a form suitable for serializing.

    This does a couple things:
    1. Splits fine-grained deps based on the module of the trigger
    2. For each module we generated fine-grained deps for, load any previous
       deps and merge them in.

    Returns a dictionary from module ids to all dependencies on that
    module. Dependencies not associated with a module in the build will be
    associated with the nearest parent module that is in the build, or the
    fake module FAKE_ROOT_MODULE if none are.
    r   merge_dependencies)mypy.server.depsr  r  rl  r  r  )rh   rj   r  r  rA  mdepsold_depss          rv   generate_deps_for_cacher    st     433333 //E
  , ,11&998U++++Lrx   z@plugins_snapshot.jsonPLUGIN_SNAPSHOT_FILEc                L   t          | j                  }| j                            t          |          sm| j        j        t          j        k    rU| j	        
                    t          | j                  d| j                   | j	                            dddd           dS dS dS )zBWrite snapshot of versions and hashes of currently active plugins.Nr   zError writing plugins snapshotTr  )rS   r   r   r  r  r   r   r   devnullrt   r'  r  r  rh   r   s     rv   write_plugins_snapshotr#    s    '233H##$8(CCTO%33 1'/ B BD'/ZZZa$DdSSSSST T33rx   dict[str, str] | Nonec                    t          t          | dd          }|dS t          |t                    s'|                     dt          |                      dS |S )zIRead cached snapshot of versions and hashes of plugins from previous run.zPlugins snapshot z!Could not load plugins snapshot: log_success	log_errorNz6Could not load plugins snapshot: cache is not a dict: )_load_json_filer  r6  r|  r   r7  r"  s     rv   r~  r~  %  sm    '5	  H th%% ]TRZ^^]]^^^tOrx   (dict[str, tuple[float, int, str]] | Nonec                ~   d }| j         ri }	 t          | j         d          5 }t          |                                          }d d d            n# 1 swxY w Y   i }|                                D ]\  }\  }}}|||f||<   n9# t
          $ r,}	t          dt          |	           d|           Y d }	~	nd }	~	ww xY w|S )NrJ  z)Warning: Failed to load quickstart file: r!  r"  )quickstart_filerM  rT   r   r  r1  r5  r   )
r   r   
quickstartraw_quickstartrN  r#  r  yzr   s
             rv   r  r  5  s>    <@J W *,	Wg-t44 6!+AFFHH!5!56 6 6 6 6 6 6 6 6 6 6 6 6 6 6 J#1#7#7#9#9 - -iq!Q$%q!9
4  - 	W 	W 	WHc!ffHHHvVVVVVVVVV	Ws:   B "AB AB A+B 
B:"B55B:dict[str, FgDepMeta] | Nonec                   t          t          | dd          }|dS |d         d |                                D             t                                                    t                                                    z  }t          fd|D                       r|                     d           dS |d	         }t          |t                    sJ | j	        j
        ss|                                D ]^}	 |                     |d
                   |d         k    }n# t          $ r d}Y nw xY w|s!|                     d|d
                      dS _|S )zRead and validate the fine-grained dependencies cache.

    See the write_deps_cache documentation for more information on
    the details of the cache.

    Returns None if the cache was invalid in some way.
    z
Deps meta z1Could not load fine-grained dependency metadata: r&  Nr   c                2    i | ]\  }}|j         ||j         S rn   )meta_source_hashr  s      rv   r  z#read_deps_cache.<locals>.<dictcomp>]  s0       $*Br?R?^B?^?^?^rx   c              3  <   K   | ]}|         |         k    V  d S rn   r}   )r  r   current_meta_snapshotr
  s     rv   	<genexpr>z"read_deps_cache.<locals>.<genexpr>b  s3      
K
Kb= 5b 99
K
K
K
K
K
Krx   z6Fine-grained dependencies cache inconsistent, ignoringr  r   r   Fz,Invalid or missing fine-grained deps cache: )r)  r  r  ri  keysanyr   r6  r|  r   skip_cache_mtime_checksvaluesr  FileNotFoundError)	rh   rj   r  commonmodule_deps_metasr   matchedr6  r
  s	          @@rv   read_deps_cacher@  I  s      E	  I tj)M .3kkmm   ##%%&&-B-G-G-I-I)J)JJF

K
K
K
K
KF
K
K
KKK LMMMt!+.'.....?2 %,,.. 	 	D !**4<88DMI$        Y4PV<YYZZZtt s   =%D##D21D2r#  r'  r(  dict[str, Any] | Nonec                `   t          j                     }	 |j                            |           }n)# t          $ r |                    || z              Y dS w xY w|                    t          j                     |z
             |                                dk    r<|                    ||                                	                                z              	 t          j                     }t          |          }|                    t          j                     |z
             t          |t                    sJ |S # t          j        $ ra |j                            | d|j                   |j                            ddd                    |j        j                  d	           Y dS w xY w)
z1A simple helper to read a JSON file with logging.N)metastore_read_timer   )data_json_load_timer  zpError reading JSON file; you likely have a bad cache.
Try removing the {cache_dir} directory and run mypy again.r   Tr  )r   r   r   r[  r   r   r   r   rstripdecoderT   r6  r|  jsonJSONDecodeErrorrt   r'  r   r  r3  r   )r#  rh   r'  r(  r   datat1r   s           rv   r)  r)  v  s    
B %%d++   I$%%%tt $)++*:;;;akDKKMM$8$8$:$::;;;Y[[D!!dikkB.>??? &$'''''    dGO<<<# $*6GO4M6#N#N 	 	
 	
 	
 tts#   0 "AAAD= =A,F-,F-c                    | j         rt          j        S | j        }| j        }t          j                            |d|z            }|S )z5Get current cache directory (or file if id is given).z%d.%d)r   r   curdirr   python_versionr   r+  )r   r   	pyversionbases       rv   r  r    sC    } y!I&I7<<	7Y#677DKrx   
target_dirc                    t           j                            | d          }	 t          |d          5 }t	          d|           t	          d|           ddd           dS # 1 swxY w Y   dS # t
          $ r Y dS w xY w)zdAdd catch-all .gitignore to an existing directory.

    No-op if the .gitignore already exists.
    z
.gitignorer  z# Automatically created by mypyr"  *N)r   r   r+  rM  r5  FileExistsError)rQ  	gitignorerN  s      rv   r   r     s    
 Z66I)S!! 	Q3!<<<<#A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    s4   A/ #A"A/ "A&&A/ )A&*A/ /
A=<A=c                    t           j                            | d          }	 t          |d          5 }|                    d           ddd           dS # 1 swxY w Y   dS # t
          $ r Y dS w xY w)zExclude the directory from various archives and backups supporting CACHEDIR.TAG.

    If the CACHEDIR.TAG file exists the function is a no-op.
    zCACHEDIR.TAGr  zSignature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag automatically created by mypy.
# For information about cache directory tags see https://bford.info/cachedir/
N)r   r   r+  rM  r  rT  )rQ  cachedir_tagrN  s      rv   r   r     s    
 7<<
N;;L	,$$ 	GG  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    s4   A" AA" AA" AA" "
A0/A0r;   c                    | j         rt          t          |                     }nt          t          |                     }|S )z&Create the appropriate metadata store.)sqlite_cacher<   r  r:   )r   mdss     rv   ry  ry    sA     B01B71K1KLL%&7&@&@AAJrx   r   tuple[str, str, str | None]c                H   |j         r)|j                             t          ||                    }nd}|\t          |          }t          j                            |d         |          t          j                            |d         |          dfS t	          j        j        |                     d           }t          j        	                    |          
                    d          }|r t          j                            |d          }d}|j        r|dz   }|dz   |d	z   |fS )
aG  Return the file names for the cache files.

    Args:
      id: module ID
      path: module path
      cache_dir: cache directory
      pyversion: Python version (major, minor)

    Returns:
      A tuple with the file names to be used for the meta JSON, the
      data JSON, and the fine-grained deps JSON, respectively.
    Nr   r  r  __init__.pyrw   z
.deps.jsonz
.meta.jsonz
.data.json)	cache_mapr   r   r  r   r   r   r+  r  r(  rY  cache_fine_grained)r   r   r   pairrootprefix
is_packager	  s           rv   r  r    s
      $$XdG%<%<== !))Q..Q0N0NPTUUW\288C==)F!!$''22=AAJ 2fj11I! *\)	\!6L#8)DDrx   CacheMeta | Nonec                   t          | ||j                  \  }}}|                    d|  d|            t          j                    }t	          ||d|  dd|  d          }t          j                    }|dS t          |t                    s*|                    d|  d	t          |                      dS t          ||          }	t          j                    }
|
                    |
|z
  ||z
  |
|z
  
           |	j        | k    s|	j        |	j        |	j        |	j        |                    d|  d           dS |	j        |j        k    r|j        j        r|	j        ~t%          |	j                  t%          |	j                  z   t%          |	j                  k    s?t%          |	j                  t%          |	j                  z   t%          |	j                  k    r|                    d|  d           dS |	j        }|j                            |                                           }|j        j        r|d         |d<   d|v r|d= ||k    r|                    d|  d           |j        j        dk    rt3          t5          |          t5          |          z            D ]~}|                    |          |                    |          k    rP|                    d                    ||                    |          |                    |                               dS |j        r2|j        r+|j        |j        k    r|                    d|  d           dS t?          tA          |j!        "                    tG          | |d                                        }|	j$        |k    r|                    d|  d           dS |
                    d           |	S )a  Find cache data for a module.

    Args:
      id: module ID
      path: module path
      manager: the build manager (for pyversion, log/trace, and build options)

    Returns:
      A CacheMeta instance if the cache data was found and appears
      valid; otherwise None.
    zLooking for z at zMeta  zCould not load cache for : r&  Nz: meta cache is not a dict: )load_meta_timeload_meta_load_timeload_meta_from_dict_timeMetadata abandoned for z: attributes are missingz: new attributes are missingr   debug_cachez: options differr   z    {}: {} != {}z: plugins differTis_checkz: plugin configuration differsr  )fresh_metas)%r  r   r   r   r)  r6  r|  r   r   r   r   r   r   r   r   r   r   skip_version_checkr   r   r   r   clone_for_moduleselect_options_affecting_cacher   r  ri  r   r3  r  r   rT   rS   r   report_config_datarI   r   )r   r   rh   	meta_jsonr   r  r   r   rK  mt2cached_optionscurrent_optionsr  r   s                  rv   find_cache_metary    s%    .b$HHIy!MM44444555	B7Ac]_AcAcAc  D 
B|tdD!! \\\PTUYPZPZ\\]]]tT9--A	BBwBGVX[]V]     	


7?6>>!<JbJJJKKKt 
+	+	+GO4V	+9q~Q\!2!22c!+6F6FFFq~Q\!2!22c!+6F6FFFNbNNNOOOt YNo66r::YY[[O) A%4Z%@z"&&=)((BbBBBCCC?$))c.11C4H4HHII  !%%c**o.A.A#.F.FFFMM*11!3!3C!8!8/:M:Mc:R:R   
 t# (@ #w'CCCKKF"FFFGGG4 7>445HT\`5a5a5abbcc K 	}##PbPPPQQQt!$$$Hrx   r   r   c                	   | |                     d|            dS | j        r|s|                     d| d           dS t          j                    }|j        j        }|
J d            |j        j        sl	 |                    | j                  }n*# t          $ r |                     d| d           Y dS w xY w|| j	        k    r|                     d| d           dS |rt          ||j                  }|                    |          }|dS t          j        |j                  s7t          j        |j                  s|                     d| d| d	           dS |                    t          j                    |z
  
           |                                }	|j        }
|
| j        k    r"|s |	s|                     d| d| d           dS |rdnt)          |j                  }|s|| j        k    s|| j        k    r|j        rr||j        v ri|j        |         \  }}}t)          |          |k    rE||
k    r?|| j        k    r4|                     d| d|            |                     ||          } | S t          j                    }	 t          j        |j                  rd}n|j                            |          }n# t          t:          t<          f$ r Y dS w xY w|                    t          j                    |z
             || j        k    r=|	r|                     d| d|            | S |                     d| d| d           dS t          j                    }|                     ||          } ||||
|| j	        | j        | j         |j        !                    |          "                                | j#        | j$        | j%        |j&        | j        | j'        d}tQ          ||j        j)                  }tU          |||j                  \  }}}|                     d+                    |||| j                             t          j                    }|j,        -                    ||           |                    t          j                    |z
  ||z
             | S |                     d| d|            | S )a  Checks whether the cached AST of this module can be used.

    Returns:
      None, if the cached AST is unusable.
      Original meta, if mtime/size matched.
      Meta with mtime updated to match source file, if hash/size matched but mtime/path didn't.
    NzMetadata not found for rk  z : errors were previously ignoredz0Internal error: meta was provided without a pathz: failed to stat data_jsonz: data cache is modifiedz: file or directory z does not exist)validate_stat_timez: file z has different sizer   z#Metadata fresh (by quickstart) for )r   r   r   )validate_hash_timezUsing stale metadata for z has different hashr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z1Updating mtime for {}: file {}, meta {}, mtime {})validate_update_timevalidate_munging_timezMetadata fresh for ).r   r   r   r   r   r:  r  r   r[  r   r   r  statS_ISDIRst_modeS_ISREGr   rt  st_sizer   r   st_mtimer   r   r  r   _replacer   r+   UnicodeDecodeErrorr(   r   r   rq  rr  r   r   r   r   r   rS   rl  r  r3  r   r  )r   r   r   r   rh   r   r   r   r  fine_grained_cacher   r   qmtimeqsizeqhashr  	meta_dict
meta_bytesrt  r  rK  s                        rv   validate_metar  Q  sZ    |2b22333t z RbRRRSSSt	BO!EO?2 		 ))$.99JJ 	 	 	KKP"PPPQQQ44	 ((KKN"NNNOOO4 /go..			$		B	zt<
## DL,D,D [b[[d[[[\\\tr)9::: !7799:Dty/ARbRRRRRSSSt ,AAC,,E =etz))TTY->-># 		0H(H(H
 $+#;D#A FE56{{e##%49:L:LS"SSTSSTTT}}5t}<<Y[[	|BJ'' @ %o99$??+[9 	 	 	44	TY[[2-=>>>$)##! III4IIJJJZbZZZZZ[[[tB==u4=88D #"o $ 1"o#O<<R@@__aa!^!^"&"5%0"o#/ I" $Iw/JKKJ-b$HHOIq!KKCJJi   
 B##Iz:::49;;3C[]`b[bcccK KK7b7777888Ks$   9B #B;:B;6K K'&K'textc                F    t          |                     d                    S )Nzutf-8)r+   encode)r  s    rv   compute_hashr    s     t{{7++,,,rx   r  r"   r   r   r   r   r   r   old_interface_hashr  tuple[str, CacheMeta | None]c                   |
j         }|
j        j        }t          | ||
j                  \  }}}|
                    d|  d| d| d|            |r||_        |                                }t          ||
j        j                  }t          |          }|
j
                            t          | |d                    }|
                    |          }|H|
                    d|            ||fD ]'}	 t          j        |           # t           $ r Y $w xY w|dfS ||k    r|
                    d|  d           nK|
                    d|  d	           |                    ||          s|
                    d
|            |dfS 	 |
                    |          }n-# t           $ r  |
                    d|d           |dfcY S w xY w|rdnt)          |j                  }|j        }|
j                            |           }|J | ||||||||                                ||||
j        |	|d}t          ||
j        j                  }|                    ||          s|
                    d|            |t5          ||          fS )a  Write cache files for a module.

    Note that this mypy's behavior is still correct when any given
    write_cache() call is replaced with a no-op, so error handling
    code that bails without writing anything is okay.

    Args:
      id: module ID
      path: module path
      tree: the fully checked module data
      dependencies: module IDs on which this module depends
      suppressed: module IDs which were suppressed as dependencies
      dep_prios: priorities (parallel array to dependencies)
      dep_lines: import line locations (parallel array to dependencies)
      old_interface_hash: the hash from the previous version of the data cache file
      source_hash: the hash of the source code
      ignore_all: the ignore_all flag for this module
      manager: the build manager (for pyversion, log/trace)

    Returns:
      A tuple containing the interface hash and CacheMeta
      corresponding to the metadata that was written (the latter may
      be None if the cache could not be written).
    zWriting rf  Frm  NzCannot get stat for zInterface for z is unchangedz has changedzError writing data JSON file zError in os.stat(z), skipping cache writer   r}  zError writing meta JSON file )r   r   r   r  r   r   	serializerS   rl  r+   r   rs  rI   r  r   remover[  r   r  r  r   r  r  rq  rr  r   r   )r   r   r  r   r   r   r   r  r  r   rh   r   r   rt  r   r  rJ  
data_bytesr   r   r  r   r   r   r   r   r   meta_strs                               rv   write_cacher    s;   J !IO!E .b$HHIy!KK>2>>>>y>>9>>???  	 >>DD'/"=>>J ,,N.334GD[`4a4a4abbK 
		$		B	z1411222 #I. 	 	H	(####    t## ^++8r88899997r777888y*55 	( KKC	CCDDD "4''$%%i00

 $ $ $L	LLLMMMt####$ ,AAC,,E:D o..r22G""" $ 99;;(( " D& $ ;<<H??9h// A 	?I??@@@/i@@@@s$   5D


DD
F   'G
	G
c                   t          | ||j                  \  }}}||g}|                    d|  d| dd                    d |D                                   |D ]i}	 |j                            |           # t          $ r?}|j        t          j        k    r |                    d| d|j	                    Y d}~bd}~ww xY wdS )zDelete cache files for a module.

    The cache files for a module are deleted when mypy finds errors there.
    This avoids inconsistent states with cache files from different mypy runs,
    see #4043 for an example.
    z	Deleting rf  c              3     K   | ]}||V  	d S rn   r}   )r  r  s     rv   r7  zdelete_cache.<locals>.<genexpr>z  s'      0M0Mq10M0M0M0M0M0M0Mrx   zError deleting cache file rg  N)
r  r   r   r+  r   r  r[  errnoENOENTstrerror)	r   r   rh   	meta_path	data_pathr  cache_pathsr   r   s	            rv   delete_cacher  n  s    .b$HHIy!i(KKKOBOOOO0M0MK0M0M0M(M(MOOPPP S S	S$$X.... 	S 	S 	Sw%,&&QQQQZQQRRR	SS Ss   A::
C5B>>Cc                      e Zd ZdZdS )ModuleNotFoundz=Control flow exception to signal that a module was not found.N)ry   rz   r{   r|   r}   rx   rv   r  r    s        GGGGrx   r  c                     e Zd ZU dZded<   dZded<   ded<   d	ed
<   dZded<   dZded<   d	ed<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZded<   ded<   ded<   ded<   ded<   ded<   ded <   dZd!ed"<   d#ed$<   dZd%ed&<   dZd'Zd(Zd	ed)<   d*ed+<   d,Zd,Zd-ed.<   dZd/ed0<   d,ZdZded1<   d2ed3<   	 	 	 	 	 dndod;Zedpd=            Zdqd>Zdrd?Zdrd@ZdqdAZd,dBdsdDZdqdEZ e!j"        dtdudH            Z#dvdJZ$dwdxdKZ%dqdLZ&d,dMdxdNZ'dydOZ(dqdPZ)dzdRZ*dzdSZ+dqdTZ,dqdUZ-d{dWZ.d|dYZ/drdZZ0dqd[Z1dqd\Z2dqd]Z3d}daZ4dvdbZ5d~ddZ6ddeZ7dqdfZ8dwddhZ9ddjZ:ddkZ;dqdlZ<dqdmZ=dS )rc   zThe state for a module.

    The source is only used for the -c command line option; in that
    case path is None.  Otherwise source is None and path isn't.
    ri   rh   r   zClassVar[int]order_counterr   orderr   r   Nr   r   r   r  r  r  r4  rd  r   rJ  zMypyFile | Noner  r   r   set[str]dependencies_setr   suppressed_setzdict[str, int]
prioritiesdep_line_mapzlist[str] | Noner  zlist[tuple[str, int]]import_contextState | Nonecaller_stateTr   r   rE   r   Fzlist[ErrorInfo]early_errorszTypeChecker | None_type_checkerr2   zdict[int, int]per_line_checking_time_nscaller_lineancestor_forroot_sourcer   	temporaryrk   rl   c
           
     X	   |	s|s|s|
J d            || _         t          xj        dz  c_        t          j        | _        || _        || _        |r@|j                                        | _        | j                            |j	        |f           ng | _        |pd| _
        |j                            | j
                  | _        g | _        d | _        |s`|^|J 	 t          ||| j        |||||	          \  }}
n+# t           $ r |	s|j                            |            w xY w|
dk    rd| _        n|rt)          ||          r	|sd| _        || _        |r$t,          j                            |          | _        |pd| _	        |rR|P| j         j        rDt3          | j
        ||          | _        | j        "| j        j        | _        | j        j        | _        |r#|!| j         j                            |          rd}|| _         | !                                 tE          j#        tH                    | _%        tM          j&                    }tO          | j        | j
        | j        | j        |          | _        | j         (                    tM          j&                    |z
  	           | j        rtS          | j        j*                  | _*        tW          | j*                  | _,        tS          | j        j-                  | _-        tW          | j-                  | _.        | j*        | j-        z   }t_          |          t_          | j        j0                  k    sJ d
 tc          || j        j0                  D             | _2        t_          |          t_          | j        j3                  k    sJ d tc          || j        j3                  D             | _4        |	r| 5                    d           |6                                sEto          | j-        || j                  r,| 8                                 | 9                                 d S d S d S |6                                r#|:                    d| d| d           t           | 8                    |	           | 9                                 d S )Nz!Neither id, path nor source givenr  __main__)skip_diagnosesilentTz<string>r   )validate_meta_timec                    i | ]\  }}||	S r}   r}   )r  r   r  s      rv   r  z"State.__init__.<locals>.<dictcomp>  s    YYY72sr3YYYrx   c                    i | ]\  }}||	S r}   r}   )r  r   r  s      rv   r  z"State.__init__.<locals>.<dictcomp>  s     ] ] ]hb$T ] ] ]rx   r  z(Deferring module to fine-grained update  ());rh   rc   r  r  r  r  r  r  r9  r  r   r   rq  r  r  find_module_and_diagnoser  rj  r  r   is_silent_import_moduler   r   r   rr   ry  r   r   r   r4  r   r   r  add_ancestorsr^   defaultdictr   r  r   r  r   r  r   ri  r  r   r  r   r   zipr  r   r  	load_treert  exist_added_packagesr  compute_dependenciesr   )ru   r   r   r  rh   r  r  r  r  r  follow_importsr   all_depss                rv   rw   zState.__init__^  s      	YXX!3!35X!3!3!3q (
(& 	%"."="B"B"D"DD&&(:K'HIIII"$D"
77@@! 	#>>>'?L  "+	( 	( 	($nn "     4+//333 ))"& 	#-gt<< 	#[ 	#"DO	 	17??400DL'Z
 	7FNt|'AN'w??DIy$&*i&>#(,	% 	FNt|';'A'A$'G'GNF)4)@)E)E&Y[[!$)TWdiRYZZ	$)++2BCCC9 %	( !%TY%; < <D$'(9$:$:D!"49#788DO"%do"6"6D(4?:Hx==C	(;$<$<<<<<YYc(DIDW6X6XYYYDOx==C	(;$<$<<<<< ] ]#h	H[:\:\ ] ] ]D /...1133 0 ($,OO 0OO%%%--/////0 00 0 --// %TtTTrTTTUUU$$ OOiO000%%'''''s   C; ;(D#r   c                2    | j         s
J d            | j         S )Nz&missing meta on allegedly fresh moduler   r  s    rv   xmetazState.xmeta  s!    yBBBBBByrx   c                L   | j         Vt          j                             | j                   \  }}t          j                             |          \  }}d|v r	g | _        d S g }| j        }d|v r2|                    dd          \  }}|                    |           d|v 2|| _        d S )Nr  r  )r   r   r  splitextr  r   r)  r9  )ru   r  r  rP  r  parents         rv   r  zState.add_ancestors  s    9 gmmDI..GAtg&&t,,GD!d{{!#	Vmmc1--IFAV$$$ Vmm #rx   c                f    | j         duo(|                                 o| j        | j         j        k    S )z5Return whether the cache data for this file is fresh.N)r   is_interface_freshr   r  s    rv   is_freshzState.is_fresh  s<     IT! <''))<!TY%;;	
rx   c                    | j         S rn   )externally_samer  s    rv   r  zState.is_interface_fresh  s    ##rx   c                N    | j         j                            | j                   dS )zGMarks this module as having been fully re-analyzed by the type-checker.N)rh   rq  r  r   r  s    rv   mark_as_recheckedzState.mark_as_rechecked  s#    &**4733333rx   	on_errorsr  c               d    d| _         |s&| j        j                            | j                   dS dS )zRMarks this module as having a stale public interface, and discards the cache data.FN)r  rh   rp  r  r   )ru   r  s     rv   mark_interface_stalezState.mark_interface_stale  s=    $ 	4L&**4733333	4 	4rx   c                    | j         j                                        r:| j                             d           | j         j                                         dS dS )z3Raise CompileError if a blocking error is detected.zBailing due to blocking errorsN)rh   rt   r  r   r  r  s    rv   check_blockerszState.check_blockers  sY    <**,, 	.L=>>>L++-----	. 	.rx   r  Iterator[None]c           
   #    K   | j         j                                        }| j         j                            | j                   	 dV  n^# t          $ r  t
          $ rG}t          || j        d| j         j        | j        | j         j	        | j         j
                   Y d}~nd}~ww xY w| j         j                            |           |r|                                  dS dS )a  Temporarily change the error import context to match this state.

        Also report an internal error if an unexpected exception was raised
        and raise an exception on a blocking error, unless
        check_blockers is False. Skipping blocking error reporting is used
        in the semantic analyzer so that we can report all blocking errors
        for a file (across multiple targets) to maintain backward
        compatibility.
        Nr   )rh   rt   r  set_import_contextr   r1  r   r   r   r   r   r  )ru   r  save_import_contexterrs       rv   wrap_contextzState.wrap_context   s      #l1@@BB..t/BCCC	EEEE 	 	 	 		 		 		!	###       		 	../BCCC 	"!!!!!	" 	"s   A B&=B!!B&r  c                @    | j                             | j                  S rn   )rh   r  r   r  s    rv   r  zState.load_fine_grained_deps   s    |2247;;;rx   c                   | j         
J d            t          | j         j        | j        dd          }|d S t	          j                    }t          j        |          | _        t	          j                    }| j                            ||z
             |s6| j        | j        j	        | j
        <   | j                            d           d S d S )NzBInternal error: this method must be called only for cached modulesz
Load tree zCould not load tree: )deserialize_timer  )fresh_trees)r   r)  r   rh   r   r"   deserializer  r   ro   r   )ru   r  rJ  r   rK  s        rv   r  zState.load_tree#  s    I!!O "!! I|=T
 
 <FY[[(..	Y[[R888 	2,0IDL )L""q"11111	2 	2rx   c                |    | j         
J d            t          | j         | j        j        | j        j                   d S )N9Internal error: method must be called on parsed file only)r  r7   rh   ro   r   rt  r  s    rv   fix_cross_refszState.fix_cross_refs7  s?    y$$&a$$$ 	TY 4dl6YZZZZZrx   r  c          
        | j         dS | j        }| j        |j        v }|j        }|s'|                    d| j         d| j         d           n&|                    d| j         d| j         d           t                      }|                                 5  | j	        }d| _	        | j
        rg|d	 |                    | j
                  }t          |j                            |                    }|j                            |          | _        nN# t"          $ r}|j        J t'          d                    | j
                            t-          j                    t,          j        z   d          t-          j        |j                            g| j                  |d}~wt4          t6          f$ r]}	| j
                            d	          rd
| j
         d}
nd| j
         dt;          |	           }
t'          |
g| j                  |	d}	~	ww xY w| j
        r.| j        j                            | j
                  r
d}d| _        n|J t?          |          | _        |                      |           |s@|!                    | j        | j        || j"        p| j#        j$        | j#                  | _         nY|j        | j                 d         | _         |j%        &                    | j        | j         j'        | j"        p| j#        j$                   ddd           n# 1 swxY w Y   | xj(        tQ          |          z  c_(        |s8tS          |j%        j*        +                    | j        g                     | _,        n|j        | j                 d         | _,        |s| j         || j        <   |s| -                                 |s| .                                 | j         | j,        f|j        | j        <   dS )zParse file and run first pass of semantic analysis.

        Everything done here is local to the file. Don't depend on imported
        modules in any way. Also record module dependencies based on imports.
        NzParsing r  r  zUsing cached AST for zmypy: can't read file '{}': {}r   )module_with_blockerz.pydz,mypy: stubgen does not support .pyd files: ''zmypy: can't decode file 'z': )r  r   r   r  )/r  rh   r   r  ro   r   r  r1   r  r  r   r  r)   r   r   r+   r  r[  r  r   r3  replacer   r   sepr  r  r(   r*  r   r   r  parse_inline_configurationr  r   r   r  rt   r  r  r2   r  error_info_mapr   r  semantic_analysis_pass1r  )ru   r  rh   cachedro   r   r  r   ioerr	decodeerrr  s              rv   r  zState.parse_file?  sa    9 F, G--/ 	JKK;4:;;;;;<<<<KKH
HHdgHHHIIIZZ   5	 5	[FDKy 8V^Z"==diHHD3GO4H4H4N4NOOF'.'B'B4'H'HD$$ ! ! !
 !;222&<CC $	 1 1")++2F K K "EK 8 8  -1G   !! +K8 Z Z Zy))&11 YYTYYYYX$)XXIXX&u$'JJJPYYZ  8t|399$)DD 8#%  )))#/#7#7 ++F333 #..GJ"&/"OT\5O L /  		 $-dg6q9	55JI+OAt|'A  c5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	n 	mB/// 	> !%W^%B%F%FtzSU%V%V W WD ' 1$' :1 =D 	)#yGDG 	+((*** 	"!!!&*i1B%C$'"""sF   L2A DL
HBF!!H5AHHD LL"%L"c                L   t          |          }|rt          || j                  \  }}| j                            |          | _        | j        j                            | j        | j        | j                   |D ](\  }}| j        j        	                    |d|           'dS dS )z8Check for inline mypy: options directive and parse them.r   N)
r*   r6   r   apply_changesrh   rt   r'  r  r   r  )ru   r  flagschangesconfig_errorslinenor  s          rv   r  z State.parse_inline_configuration  s    !&)) 	=%8%M%M"G]<55g>>DLL((TWdlKKK!. = =#**61e<<<<	= 	== =rx   c                   | j         }| j        J t                      }t                      }|                                 5  |                    | j        | j        | j        |           ddd           n# 1 swxY w Y   | j        j	        
                    | j        | j        j                   t                      | j        _        | j        j        s_| j         j        s&| j                            t#                                 |j        r&| j                            t'                                 | xj        t)          |          z  c_        dS )zPerform pass 1 of semantic analysis, which happens immediately after parsing.

        This pass can't assume that any other modules have been processed yet.
        N)r   r  r1   r'   r  
visit_filer  r   rh   rt   set_skipped_linesskipped_linesr#   r  r  allow_redefinition_newacceptrK   allow_redefinitionrL   r2   )ru   r   r   analyzers       rv   r  zState.semantic_analysis_pass1  sz   
 ,y$$$ZZ /00   	I 	I	4:twHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I--dj$):QRRR%--	y  	:<6 A 	  !=!?!?@@@) :	  !6!8!8999mB///s   (A55A9<A9depc                    || j         vr4| j                            |           | j                             |           || j        v r6| j                            |           | j                            |           d S d S rn   )r  r   r9  r  r  r   r  ru   r  s     rv   add_dependencyzState.add_dependency  s    d+++$$S)))!%%c***$%%%O""3'''&&s+++++ &%rx   c                    || j         v r4| j                            |           | j                             |           || j        vr6| j                            |           | j                            |           d S d S rn   )r  r   r  r  r   r9  r  r  s     rv   suppress_dependencyzState.suppress_dependency  s    $'''$$S)))!((---d)))O""3'''##C((((( *)rx   c                v   | j         }| j        J g | _        t                      | _        g | _        t                      | _        i | _        i | _        |	                    | j                  | j         j
                            | j                  z   }|D ]p\  }}}t          || j                            |t                              | j        |<   || j        k    rH|                     |           || j        vr
|| j        |<   q| j        dk    r|                     d           |                                  dS )zCompute a module's dependencies after parsing it.

        This is used when we parse a file that we didn't have
        up-to-date cache information for. When we have an up-to-date
        cache, we just use the cached info.
        Nr\   )rh   r  r   ri  r  r   r  r  r  r  r   get_additional_depsminr   r	  r   r	  r  )ru   rh   dep_entriesr  r   r  s         rv   r  zState.compute_dependencies  s>    ,y$$$  #!ee::I
 
L33DI>>? ) 	- 	-MCT"%c4?+>+>r7+K+K"L"LDOBTW}}###***(,!"%7j  
+++rx   c                   | j         j        rd S t                      }|                                 5  |                                                                  d d d            n# 1 swxY w Y   | xj        t          |          z  c_        d S rn   )r   semantic_analysis_onlyr1   r  type_checkercheck_first_passr2   )ru   r   s     rv   type_check_first_passzState.type_check_first_pass	  s    <. 	FZZ   	3 	300222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3mB///   'A$$A(+A(r   c           	         | j         sU| j        
J d            | j        }t          |j        |j        | j        | j        | j        |j        | j	                  | _         | j         S )Nz2Internal error: must be called on parsed file only)
r  r  rh   r   rt   ro   r   r  r   r  ru   rh   s     rv   r  zState.type_checker
	  sl    ! 	9((*^(((lG!,	
." "D !!rx   r  c                    t          |                                 j                  dk    sJ |                                 j        d         S )Nr  r   )r   r  
_type_mapsr  s    rv   r  zState.type_map	  sF     4$$&&122a7777  ""-a00rx   c                   | j         j        rdS t                      }|                                 5  |                                                                 }d d d            n# 1 swxY w Y   | xj        t          |          z  c_        |S )NF)r   r  r1   r  r  check_second_passr2   )ru   r   r   s      rv   type_check_second_passzState.type_check_second_pass	  s    <. 	5ZZ   	= 	=&&((::<<F	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=mB///r  c                   | j         
J d            | j         j        rd S | j        }|j                            | j        | j         j        | j                   |j                            t          j
                  s$|j                            t          j                  re| j                             t          t          |j        |j                  |                                 | j        | j         j                             d S d S )Nr  r  )r  r  rh   rt   r'  r  r  r   is_error_code_enabledcodesPOSSIBLY_UNDEFINEDUSED_BEFORE_DEFr  r%   r   ro   r  r  r  s     rv   detect_possibly_undefined_varsz$State.detect_possibly_undefined_vars(	  s    y$$&a$$$9 	F,
DI,>UUU>//$
 
 
	^11%2GHH
	 I0"7>7?CCMMOOLIO	     
	 
	rx   c           	     N   | j         
J d            | j        }| j        j        rd S t	                      }|                                 5  |j        }|j        r,|j                            | 	                                           t          | 	                                                                          }| j                                         D ]\  }}}|j        |                    |j                   t          |j        t"                    r|                    |j        j                   |j        j        r|                    |j        j                   |j        j        r|                    |j        j                   |j        j        r|                    |j        j                   |                     |                                 j        |           | j        j        r:t7          | j         | j        | j        j        d| 	                                           |                    | j         | 	                                | j                   |                     | j        j                    |j        j!        r.tE          | |j#        |j        | 	                                           | $                                 |j        j%        s |j        j&        stO          | j                    d d d            n# 1 swxY w Y   | xj(        tQ          |          z  c_(        d S )Nr  T)ro   inferredtypemap))r  rh   r   r  r1   r  export_typesrq   r  r  r  r;  local_definitionsr7  r9  r6  noder$   r   basesmetaclass_typetypeddict_type
tuple_type_patch_indirect_dependenciesr  module_refsdump_inference_statsrM   r  ro   r  update_fine_grained_depsrl  export_ref_infowrite_undocumented_ref_infor   
free_stater   preserve_astsr8   r2   )ru   rh   r   r   rq   r  syms          rv   finish_passeszState.finish_passes;	  s   y$$&a$$$,<. 	FZZ   +	% +	%oG# :!((999
 T]]__335566I!Y88:: > >	38'$$SX...ch11 >$$SX^444x. B!(()@AAAx. B!(()@AAAx* >!(()<===--d.?.?.A.A.MyYYY|0 IJ L0! MMOO    	4==??DLIII))$,*>???. +'+W_dmmoo   OO?; %GODa %$)$$$W+	% +	% +	% +	% +	% +	% +	% +	% +	% +	% +	% +	% +	% +	% +	%X 	mB///s   	J(K==LLc                X    | j         r"| j                                          d | _         d S d S rn   )r  resetr  s    rv   r3  zState.free_stateo	  s:     	&$$&&&!%D	& 	&rx   r.  rZ   
list[Type]c                   d |vsJ |                                  }| j        j                            |          |z  }||z
  }t	          |          D ]y}|| j        j        vr|| j        vr3|| j        j        vr%|                     |           t          | j
        |<   M|| j        vr#|| j        j        v r|                     |           zd S rn   )valid_referencesrh   ro  find_modulesr  ro   r  rj  r	  r  r  r  )ru   r.  rZ   validencounteredextrar  s          rv   r-  z"State._patch_indirect_dependenciest	  s    5    %%''l7DDUKKkYe#%== 	. 	.C$,...$---#T\=Y2Y2Y##C((('3$$D///C4<;W4W4W((---	. 	.rx   c                    | j         J | j        dv ri S ddlm}  || j         |                                 | j        j        | j        j                  S )N)r\   r[   rZ   rY   r]   r   )get_dependencies)targetr  rN  r   )r  r   r  rA  r  r   rN  rh   )ru   rA  s     rv   compute_fine_grained_depszState.compute_fine_grained_deps	  sq    y$$$7III I5555559]]__<6L(	
 
 
 	
rx   r  c                    | j         j        }|j        s|j        r:ddlm}  ||                                 |           t          j        |           d S d S )Nr   r  )	rh   r   r_  r   r  r  rC  rR   update_protocol_deps)ru   r  r   r  s       rv   r0  zState.update_fine_grained_deps	  ss    ,&% 	2)I 	2;;;;;;t==??FFF+D11111		2 	2rx   c                    | j         J t          | j        | j        z   | j         z             }|                    | j                   d|v r|                    d           |S )Nr   zos.path)r  ri  r   r   r  r   )ru   
valid_refss     rv   r;  zState.valid_references	  se    ~)))*T_<t~MNN
tw:NN9%%%rx   c                z   | j         
J d            | j        r&| j        j        t          j        k    s| j        j        r[| j        j        rM	 | j                                          n2# t          $ r% t          d| j         | j        j                    w xY wd S | j        }|r?t          | j        | j        | j                   d | _        |                     d           d S |                                 }|                                 }| j        J t+          t-          | j                            t+          | j                  k    sJ d| j         d| j         d            t1          | j        | j        | j         t3          | j                  t3          | j                  ||| j        | j        | j        | j                  \  }| _        || j        k    r%| j                            d	| j         d
           d S | j                            d	| j         d           |                                  || _        d S )Nr  zError serializing r"  Tr  z$Duplicates in dependencies list for r  r  zCached module z has same interfacez has changed interface)r  r   r   r   r   r!  r   debug_serializer  r1  r5  r   rh   r   transitive_errorr  r   r  dependency_prioritiesdependency_linesr  r   ri  r   r  r  r   r   r   r   )ru   	is_errorsr   r   new_interface_hashs        rv   r  zState.write_cache	  sq   y$$&a$$$ 		|%33|4 4 |+ I''))))    8tw88t|?RSSSS F)	 	$)T\:::DI%%%555F..00	))++	+++3t())**c/
 /
 
 
 
Q$'QQT=NQQQ
 
 
 )4GII"##!!OL)
 )
%DI !444LJdgJJJKKKKKLMdgMMMNNN%%'''"4Ds   A& &/Bsuppressed_onlyc           	          j         } j        J |r j        }n% fd j        D             }| j        z    j        z   }|D ]}||j        v r|j                            |          }|j        r. j        	                    |d          }	 | j        v rd} }	n d}	}t          ||||||	           r# t          t          f$ r Y w xY wdS )zReport errors for import targets in modules that don't exist.

        If suppressed_only is set, only check suppressed dependencies.
        Nc                Z    g | ]'}j                             |          t          k    %|(S r}   r  r   r  r  r  ru   s     rv   
<listcomp>z-State.verify_dependencies.<locals>.<listcomp>	  s;       DO4G4G4L4LP\4\4\4\4\4\rx   r  )r  r  r  )rh   r  r   r   ro   r   rq  ignore_missing_importsr  r   r  r  r   )
ru   rO  rh   r  r   r  r   r  stateancestors
   `         rv   verify_dependencieszState.verify_dependencies	  sN   
 ,~))) 	GHH   #0  L $do5FH 	 	Cgo%%o66s;;G- $((a00D$.((*.E-1HH&*D8E(!& $!)     #L1    -	 	s   'B55C	C	r   c                :      fd j          j        z   D             S )Nc                P    g | ]"}j                             |t                    #S r}   r  r   r   rS  s     rv   rT  z/State.dependency_priorities.<locals>.<listcomp>
  s+    bbbs##C22bbbrx   r   r   r  s   `rv   rK  zState.dependency_priorities
  s)    bbbbd>ORVRa>abbbbrx   c                :      fd j          j        z   D             S )Nc                F    g | ]}j                             |d           S )r  )r  r   rS  s     rv   rT  z*State.dependency_lines.<locals>.<listcomp>

  s,    ]]]#!%%c1--]]]rx   r\  r  s   `rv   rL  zState.dependency_lines	
  s'    ]]]]9JT_9\]]]]rx   c                   | j         j        st          j        | j         j        v r]t          j        | j         j        vrC| j        r|                     d           | j        j	        
                    | j                   d S d S d S )NT)rO  )r   warn_unused_ignoresr  UNUSED_IGNOREenabled_error_codesdisabled_error_codesr   rX  rh   rt   generate_unused_ignore_errorsr  r  s    rv   generate_unused_ignore_notesz"State.generate_unused_ignore_notes
  s    L,		J"dl&FFF!)JJJ y ?(((>>>L==djIIIII KJ GFrx   c                    | j         j                            t          j                  r1| j         j                            | j        | j        j                   d S d S rn   )	rh   rt   r  r  IGNORE_WITHOUT_CODE#generate_ignore_without_code_errorsr  r   r`  r  s    rv   "generate_ignore_without_code_notesz(State.generate_ignore_without_code_notes
  s]    <44U5NOO 	LCC
DL<    	 	rx   Nr   NFF)r   r   r   r   r  r   rh   ri   r  r  r  r   r  r  r  r   r  r   rk   rl   )rk   r   r  r  )r  r   rk   rl   )T)r  r   rk   r  )rk   r  )F)r  r   rk   rl   )r  r   rk   rl   )r  r   rk   rl   )rk   r   )rk   r  )r.  r  rZ   r9  rk   rl   )r  r  rk   rl   )rk   r  )rO  r   rk   rl   )rk   r   )>ry   rz   r{   r|   r   r  r   r   r  r  r4  r   rJ  r  r  r  r  r  r   r   rJ  r  fine_grained_deps_loadedr2   rw   propertyr  r  r  r  r  r  r  
contextlibcontextmanagerr  r  r  r  r  r  r  r	  r  r  r  r  r  r  r"  r6  r3  r-  rC  r0  r;  r  rX  rK  rL  re  ri  r}   rx   rv   rc   rc     s.          #$M$$$$JJJGGGDGJJJF"K""""#'''''!D!!!!D D    
  !    #'I&&&& *))) "&L%%%% K O N  J  "!!! )-M,,,,$ M .--- &*%)!
  l( l( l( l( l(\    X# # # # 

 

 

 

$ $ $ $4 4 4 4 9> 4 4 4 4 4 4. . . . " " " " ">< < < <2 2 2 2 2([ [ [ [ /4 `D `D `D `D `D `DD= = = =0 0 0 0B, , , ,) ) ) )$ $ $ $L0 0 0 0" " " "1 1 1 1      &20 20 20 20h& & & &
. . . . 
 
 
 
(2 2 2 2   -5 -5 -5 -5^+ + + + +Zc c c c^ ^ ^ ^
J 
J 
J 
J     rx   r  r  r  r  r  r  tuple[str, str]c                   t          ||           }t          |t                    r|j        }	|s%|                    d          r|j        r	|t          v rd}	|rn|	dk    r|                     d| d| d           nf|	dk    s|	dk    rZ|| j        vr|                     d	| d| d           |	dk    r(|rt          | |||           nt          | ||||           t          t          | |          r|sd}	||	fS |j        }
| j        j        }t          |          r|r|j        s|t"          j        u rd
}
|rt          |r,|
s#t'          ||           st)          | ||||           t          |rt+          d| dg          t          )a  Find a module by name, respecting follow_imports and producing diagnostics.

    If the module is not found, then the ModuleNotFound exception is raised.

    Args:
      id: module to find
      options: the options for the module being loaded
      caller_state: the state of the importing module, if applicable
      caller_line: the line number of the import
      ancestor_for: the child module this is an ancestor of, if applicable
      root_source: whether this source was specified on the command line
      skip_diagnose: skip any error diagnosis and reporting (but ModuleNotFound is
          still raised if the module is missing)

    The specified value of follow_imports for a module can be overridden
    if the module is specified on the command line or if it is a stub,
    so we compute and return the "effective" follow_imports of the module.

    Returns a tuple containing (file path, target's effective follow_imports setting)
    .pyinormalr  z
Silencing r  r  skipr  z	Skipping Fzmypy: can't find module 'r  )find_module_with_reasonr6  r   r  r*  follow_imports_for_stubsrb   r   rj  skipping_ancestorskipping_moduler  r  rU  r   rN   !ignore_missing_imports_per_moduler@   APPROVED_STUBS_NOT_INSTALLEDin_partial_packagemodule_not_foundr   )rh   r   r   r  r  r  r  r  r   r  rU  global_ignore_missing_importss               rv   r  r  "
  s5   < %R11F&# A!
 !/	& ''	&  8		& )))%N 	!x''KK4V44r4445555v%%7)B)B000777"777888(( T%gr6<HHHH#G[,FSSS  "7F33 	&K 	&%N'' ")!? )0(N%1"55	+-	+ =	+ .KKK%*" 	!   
	!* Q.@W.M.M Q +|RPPP   	!  AB A A ABCCC  rx   c                    | D ]S}||j         j        v rt          ||          }|s$|j        dk    r|                    d          r|j        rLd|v r dS TdS )zFind if there are any newly added packages that were previously suppressed.

    Exclude everything not in build for follow-imports=skip.
    rs  rq  r]  TF)r   source_modulesr  r  r*  ru  )r   rh   r   r  r   s        rv   r  r  
  s    
   '$333 !#w// 	!V++f%% ,)0)I , D   44 ! 5rx   c                    t          j                     }|j                            | d          }|                    t          j                     |z
  d           t	          |t
                    rdS |S )z>Find a filesystem path for module `id` or `None` if not found.Tre  r  find_module_timefind_module_callsN)r   ru  rw  r   r6  r@   r   rh   r   r  s       rv   r  r  
  si    	B!--bD-AAAty{{R'71MMM!)** tHrx   rA   c                    t          j                     }|j                            | d          }|                    t          j                     |z
  d           |S )zGFind a filesystem path for module `id` or the reason it can't be found.Fre  r  r  )r   ru  rw  r   r  s       rv   rt  rt  
  sQ    	B!--bE-BBAty{{R'71MMMHrx   c                    d| v ru|                      dd          \  }}||j        v r|j        |         }n6	 t          |dd|d          }|j        }n# t          t
          f$ r d}Y nw xY w||j        S |} d| v udS )zCheck if a missing module can potentially be a part of a package.

    This checks if there is any existing parent __init__.pyi stub that
    defines a module-level __getattr__ (a.k.a. partial stub package).
    r  r  NT)r   r   r  rh   r  F)r)  ro   rc   r  r  r   is_partial_stub_package)r   rh   r  r  
parent_mod	parent_sts         rv   rz  rz  
  s     ))IIc1%%	W_$$*1/&*AJJ,!DwRV  	 '^

 #L1 " " "!


" !55# ))$ 5s   A A('A(r  rB  reasonr@   c           	        | j         }|                                }|                    |j                   |                    |j        |j        |j                   |dk    r/|                    |ddd           |                                 n | j        j	        }|
                    |          \  }}	|t          j        k    rt          j        }
n9|t          j        k    s|t          j        k    rt          j        }
nt          j        }
|                    |d|                    |          |
           t)          |          }|	D ];}d|v r|J |                    |	          }|                    |d|d
d|
           <|t          j        u r|J | j                            |           |                    |           d S )Nr\   r   z7Cannot find 'builtins' module. Typeshed appears broken!Tr  )rA  )codez{stub_dist})	stub_distnote)severity	only_oncer  )rt   r  r  r'  r  r   r   r  r  r   error_message_templatesr@   	NOT_FOUNDr  IMPORT_NOT_FOUNDFOUND_WITHOUT_TYPE_HINTSry  IMPORT_UNTYPEDIMPORTr3  rO   r   r  )rh   r  r  rB  r  rt   r  daemonmsgnotesr  distr  s                rv   r{  r{  
  s    ^F //11
l9:::
OOL&9MNNN!NX\ 	 	
 	
 	
 	933F;;
U)333)DD*CCC-JJJ'DD<DdAszzz88tDDD%f-- 	U 	UD$$'''{{T{22MM$4&DtMTTTT)FFF###)--d333
122222rx   c                   |sJ ||f            | j                                         }| j                             |j                   | j                             |j        |j        | j                   | j                             |dd| dd           | j                             |dddd	           | j                             |           d
S )zDProduce an error for an import ignored due to --follow_imports=errorr   zImport of "	" ignoredr  r  zA(Using --follow-imports=error, module not passed on command line)r  Tr  r  N)rt   r  r  r'  r  r   r   r  )rh   r  r  r   r   r  s         rv   rw  rw  
  s     ##"d###!.7799N%%l&ABBBNL.QQQN$#>#>#>#>QQQN	K     N%%&9:::::rx   c                   | j                             g            | j                             |j        |j        | j                   | j                             ddd| ddd           | j                             ddddd           d	S )
zFProduce an error for an ancestor ignored due to --follow_imports=errorr  zAncestor package "r  r  Tr  z@(Using --follow-imports=error, submodule passed on command line)r  N)rt   r  r'  r  r   r   r  )rh   r   r   r  s       rv   rv  rv    s     N%%b)))NL.QQQN
B2R222WPT     N

J      rx   c                   | j         j        }|rt          j                            |          }|                                  dt          fd|pdfd| j         j        pdfdt          j	        fd| j         j
        fdt          t                              d	                     fd
| j         j        fg}|D ]"\  }}|                     |dz   d|            #|D ]}|                     dd|            | j                                                                        D ]U\  }}|s|                     d|             |                     | d           |D ]}	|                     d|	            VdS )z8Output useful configuration information to LOG and TRACEzMypy VersionzConfig FileDefaultzConfigured Executablerl   zCurrent Executablez	Cache DirCompiledr  Excluder  r  zFound source:zNo z    N)r   r%  r   r   r   r   rU   python_executablerY   
executabler   r   r   r*  excluder   asdictr  r   )
rh   r~   r%  configuration_vars	conf_name
conf_valuer  	path_typepathspths
             rv   log_configurationr    s    /-K 3gook22KKMMM	%	1	3	 '/"C"MvN	s~.	go/0	SX..u555667	GO+, "4 9 9	:y377:778888 5 5336334444 $07799??AA ( (	5 	MM+	++,,,ooo&&& 	( 	(CMM,,,''''	(( (rx   c                x   t          ||            t          j                    }t          | |          }|                                rOt	          |          dt	          |           z  k     r,|                    d           d|_        t          | |          }t          j                    }|                    t	          |          t          d |	                                D                       ||z
  t	          |j
        j                             |st          d|           |S |                    dt	          |           d	||z
  d
d           |j        j        rt          ||           |S |j        j        s|                                rt          j                    }t!          ||          }|                    t          j                    |z
             |||_        nz|j                            dd          dk    r[|j                                         |                    d           d|_        |                    d           t+          | ||          S |                                st-          ||           t/          |           |j        |_        |j        j        s|j        j        rFt7          j        |j                   |j        j        s!t=          ||          }t?          |||           |j        j         r-ddl!m"}	  |	|j#        |j$        |j        j%        |j                   |S )Ng      ?z=Redoing load_graph without cache because too much was missingFc              3  \   K   | ]'}|j         d uo|j                             d          V  (d S )Nrq  )r   r*  )r  gs     rv   r7  zdispatch.<locals>.<genexpr>V  s<      __1d*Fqvv/F/F______rx   )
graph_sizestubs_foundgraph_load_timefm_cache_sizezNothing to do?!r"  zLoaded graph with z nodes (z.3fz sec)r  ro  r   zDError reading fine-grained dependencies cache -- aborting cache loadz.Falling back to full run -- reloading graph...)dump_all_dependencies)&r  r   
load_graphrt  r   r   rr   r   sumr;  ru  r]  r5  r   
dump_graphr_  r@  rk  rg  r   clearr   process_graphr#  r   r  r   rR   add_all_protocol_depsrl  r  r  	dump_depsr  r  ro   rq   rN  )
r~   rh   r   r   rj   rK  rv  rk  r  r  s
             rv   r   r   B  s<   gw'''	Bw((E %%'' -CJJG9L,L,LSTTT %7G,,	Bu::__PUP\P\P^P^_____b'3;<<	      f----KKKSZZKKbKKKKLLL! 5&!!! ) 6W-K-K-M-M 6Y[[&w66DIKK",<===##/G  ]}a00144M!!!KK^___$)G!KKHIIIGWf555
 ))++ 8eW%%%w''''.'?$?- 	81Y 	8
 ,W_===?; 8/?? 777  
::::::OW.0NPWP_	
 	
 	
 Lrx   c                  "    e Zd ZdZddZdd
ZdS )NodeInfoz,Some info about a node in the graph of SCCs.indexr   sccr   rk   rl   c                D    d|z  | _         || _        i | _        i | _        d S )Nzn%d)node_idr  sizesr  )ru   r  r  s      rv   rw   zNodeInfo.__init__  s&    u}%'
$&			rx   r   c           	     \   t          | j                                                  }d                    t	          j        | j                  t	          j        |          t	          j        | j                  t	          j        | j                  t	          j        | j                            S )zConvert to JSON string.z[{}, {}, {},
     {},
     {}])	r  r  r;  r3  rH  dumpsr  r  r  )ru   
total_sizes     rv   r  zNodeInfo.dumps  s~    **,,--
188Jt|$$Jz""Jtx  Jtz""Jty!!
 
 	
rx   N)r  r   r  r   rk   rl   rk   r   )ry   rz   r{   r|   rw   r  r}   rx   rv   r  r    sB        66' ' ' '	
 	
 	
 	
 	
 	
rx   r  c                    t          | d          5 }t          |          D ](}|                    | d||         j         d           )	 ddd           dS # 1 swxY w Y   dS )z3Dump timing stats for each file in the given graph.wrf  r!  N)rM  r  r  r2   )r   rj   rN  r   s       rv   r   r     s    	dC 9A-- 	9 	9BGGr77E"I37778888	99 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s   9AAAc           	     j   t          | d          5 }t          |          D ]x}||         j        s|                    | d           t          ||         j                  D ]5}||         j        |         }|                    |dd|dz  dd           6y	 ddd           dS # 1 swxY w Y   dS )	z-Dump per-line expression type checking stats.r  z:
z>5rf  i  z8.1fr!  N)rM  r  r  r  )r   rj   rN  r   r  	line_times         rv   r   r     s   	dC >A-- 	> 	>B96 GGrJJJuRyBCC > >!"I?E	4<<<Yt^<<<<====>		>> > > > > > > > > > > > > > > > > >s   B	B((B,/B,c                   |pt           j        }g }t          |           }t          |          D ]:\  }}t	          | |          }t          ||          }|                    |           ;i }|D ]}|j        D ]}	|j        ||	<   |D ]}|j        D ]}	| |	         }
d}|
j	        r6	 t          j	                            |
j	                  }n# t          $ r Y nw xY w||j        |	<   |
j        D ]S}||
j        v rH|
j        |         }||v r7||         }||j        k    r$||j        vs||j        |         k     r
||j        |<   Tt#          dd                    d |D                       z   dz   |           dS )zDump the graph as a JSON string to stdout.

    This copies some of the work by process_graph()
    (sorted_components() and order_ascc()).
    r   rU  z,
 c              3  >   K   | ]}|                                 V  d S rn   )r  )r  r(  s     rv   r7  zdump_graph.<locals>.<genexpr>  s*      ;;TDJJLL;;;;;;rx   z
]r"  N)rY   r   sorted_componentsrW  
order_asccr  r9  r  r  r   r   getsizer[  r  r   r  r  r5  r+  )rj   r   nodessccsr^  asccr  r(  	inv_nodesmodrV  r   r  r  dep_ids                  rv   r  r    s    !szFEU##DT??  4%%3TI * *8 	* 	*C!\IcNN	* 4 48 	4 	4C#JEDz 7??5:66DD   D"DJsO) 4 4%****3/Ci''!*3!T\11"$)33sTYv=N7N7N03DIf-4	4$ 
#;;U;;;;;
;e
C&QQQQQQs   $$C		
CC	old_graphGraph | Nonenew_moduleslist[State] | Nonec                   ||ni }||ng }t                      }| D ]:}	 t          |j        |j        |j        |j                   n# t          $ r Y :w xY wj        |v rj        	                    j
        j        j                   j                            dddj         d|j                 j
         dd           j                            ddd	d
           j                            dddd
           j                                         |j        <   |                               |                    |j                   <d |                                D             }|D ]4j        J fdj        D             }	                                sfdj        D             }
ng }
j        |	z   j        z   D ]}|j        v o||v}|r ||
vrj                            |           n||vr~	 |j        v rt          |dd          }n.t          |ddj                            |d                    }|j        rt2          j                            |j                  }||v rj                            ddd                    ||         j        |j                  d           j                            ddd	d
           j                            dddd
           j                                         |||<   |j        |vsJ |j                    |||j        <   |                    |           n.# t          $ r! |j        v r                    |           Y nw xY w||v r|j        v r                    |           ِ6j                             j!                   |S )a  Given some source files, load the full dependency graph.

    If an old_graph is passed in, it is used as the starting point and
    modified during graph loading.

    If a new_modules is passed in, any modules that are loaded are
    added to the list. This is an argument and not a return value
    so that the caller can access it even if load_graph fails.

    As this may need to parse files, this can raise CompileError in case
    there are syntax errors.
    N)r   r   r  rh   r  r  zDuplicate module named "z" (also at "z")Tr  zgSee https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more infor  r  zCommon resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATHc                ,    i | ]}|j         	|j        |S r}   )r   r   )r  r  s     rv   r  zload_graph.<locals>.<dictcomp>(  s#    EEERRWE"*bEEErx   c                Z    g | ]'}j                             |          t          k    %|(S r}   rR  )r  r  r  s     rv   rT  zload_graph.<locals>.<listcomp>9  s4    aaa"-:K:KC:P:PT`:`:`:`:`:`rx   c                4    g | ]}t          |          |S r}   r  )r  r  rh   s     rv   rT  zload_graph.<locals>.<listcomp>?  s)    VVVS5GW5U5UVSVVVrx   )r   r   r  rh   r  r  )r   r   r  rh   r  r  r   zCSource file found twice under different module names: "{}" and "{}"zxCommon resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH)"ri  rc   rA  r   r  followedr  r   rt   r'  r  r   r  r  r9  r  r;  r  r   rt  r   r  rj  r  r   r   r   r3  r  r  r	  r   set_modulesro   )r~   rh   r  r  rj   newentry_pointsbs
seen_filesr   addedr  ignorednewst
newst_pathr  s    `             @rv   r  r    s   & !* 5992E
 %0++bC UUL &$ &$		9Ww "O  BB  	 	 	H	5E>>N##BHbeW_EEEN!!T25TTeBEl>PTTT	 "    N!!  "    N!!%   "    N&&(((be

2#### FE5<<>>EEEJ  T' T'|''' baaaraaa--// 
	
 WVVVBMVVVEE
 E<,.> ;	' ;	'CR..J3l3JG 6&3e++'++C0000E!!3&bl** !&"dGZ\! ! ! !&"!%#'$+)+(*(;(;C(C(C! ! ! z 7%'W__UZ%@%@
%33#N11 " !!006z*7M7PRWRZ0[0[(, 2    $N11 " !!0)/ 2    $N11 " !!\)/ 2    $N6688816
:. 85000%(000&+E%(OJJu%%%%G & 4 4 4b111..s3334H e||r'8 8 8!!#&&&w;	'x Nw///Ls$   )A
AAAM(NNc           
     
    t                     }|                    dt          |          t          d |D                       fz             g }|D ]t	                     }dv r;t          |d          }|                    d           |                    d           |j        j	        dk    rK|D ]H|
                    d dd	                     fd
          j        D                                  I fd|D             }| }t                      }|D ]"|                              j                   #|z  } fd|D             }|o| }t                      }	|r@|D ]"|	                              j                   #|	                                 z  }	|	rd}|rt#           fd|D                       }
 fd|D             }|sdnt           fd|D                       }|j        j	        dk    rt          |z   fd          }|D ]h|v r          j        j        |k     rd}nd}n          j        j        |
k    rd}nd}|
                    d|          j        j        fz             i|
|k     rd}d||
z
  dd}nd}n|	r'dd	                    t          |	                     d}n|r]d }|k    r)|d!d	                    t          |                     dz  }|r)|d"d	                    t          |                     dz  }n&d#d	                    t          |                     d}t)           fd$|D                       r|D ]d          _        d	                    |          }|r3|
                    d%| d&| d           |                    |           p|r>|                    d't          |           d(           |D ]}t-           ||           g }t          |          }|d)k    r|                    d*| d+|            n|                    d,|||fz             t/           ||           t          |          }t1          d- |D                       }|                    ||.           |rM|                    d/                    ||                     |
                    t7          |                     d1S |                    d0           d1S )2z'Process everything in dependency order.z#Found %d SCCs; largest has %d nodesc              3  4   K   | ]}t          |          V  d S rn   r   r  r  s     rv   r7  z process_graph.<locals>.<genexpr>  s)      GaGaUXCGaGaGaGaGaGarx   r\   T)reverser   zPriorities for r  rf  c              3  n   K   | ]/}|v |         j         v d |         j         |         fz  V  0dS )z%s:%dN)r  )r  r  r  rj   r   s     rv   r7  z process_graph.<locals>.<genexpr>  s_        99eBi.B)B)B  1eBi&:1&=">>)B)B)B)B rx   c                H    h | ]}|                                          |S r}   )r  r  r   rj   s     rv   	<setcomp>z process_graph.<locals>.<setcomp>  s.    BBBBU2Y-?-?-A-ABRBBBrx   c                P    h | ]"}|v |                                           |#S r}   )r  r  s     rv   r  z process_graph.<locals>.<setcomp>  s2    ^^^R2;;uRy?[?[?]?];b;;;rx   Fc              3  <   K   | ]}|         j         j        V  d S rn   r  r   r  s     rv   r7  z process_graph.<locals>.<genexpr>  s,      IIrb	 :IIIIIIrx   c                .    h | ]}|         j         |S rn   r  r  s     rv   r  z process_graph.<locals>.<setcomp>  s$    LLLRr1Kb1K1K1Krx   r   c              3  <   K   | ]}|         j         j        V  d S rn   r  r  r  rj   s     rv   r7  z process_graph.<locals>.<genexpr>  s-      (W(Ws)9)D(W(W(W(W(W(Wrx      c                (    |          j         j        S rn   r  r   rj   s    rv   r   zprocess_graph.<locals>.<lambda>  s    uRy?Y rx   r  z*id:zid:z+dep:zdep:z %5s %.0f %szout of date by z.0fz secondsfreshz"stale due to changed suppression (r  zinherently staler  z with stale deps (zstale due to deps (c              3  :   K   | ]}|v |         j         V  d S rn   )rJ  r  s     rv   r7  z process_graph.<locals>.<genexpr>  s.      KKscUlluSz*llllKKrx   zQueuing z SCC (zProcessing z queued fresh SCCsr  zProcessing SCC singleton (z) as z$Processing SCC of size %d (%s) as %sc              3  4   K   | ]}t          |          V  d S rn   r  r  s     rv   r7  z process_graph.<locals>.<genexpr>  s(      99#SXX999999rx   )	sccs_left
nodes_leftzD{} fresh SCCs ({} nodes) left in queue (and will remain unprocessed)zNo fresh SCCs left in queueN)r  r   r   r  r  r  r  r9  r   r   r   r+  r   ri  r  r   r8  r  r  r   r9  rJ  process_fresh_modulesprocess_stale_sccr  r   r3  r   )rj   rh   r  fresh_scc_queuer  	stale_sccr  r  
stale_depsundepsoldest_in_sccviablenewest_in_depsall_idsr  	fresh_msgscc_strprev_sccr   r  r  r  r   s   `                    @@rv   r  r    sl   U##DKK5TCGaGa\`GaGaGaDaDa8bbccc')O
  z3 z3 %% d+++C JJz"""JJz"""?$))  +b+++HH      !&r!7        CBBB#BBB	uu 	0 	0BKKb	.////^^^^4^^^
(j. 	  4 4eBi23333ejjll"F  &	N  IIIISIIIIIMLLLL:LLLFWS(W(W(W(WPV(W(W(W%W%W  (A-- 4Y4Y4Y4YZZZ! Z ZBSyy 9?5FF"(CC"'CC 9?5EE")CC"(CMM.Cr9SUW3X"XYYYY ~--Zn}.LZZZZ		#		 		NXSXXfVnn=U=UXXXII 	N*ID  @#((6)+<+<"="=@@@@	 RQ#((6*;M;M2N2NQQQQ	Mchhvj7I7I.J.JMMMI KKKKdKKKKK 	2 2 2-1b	**((3-- 	3MM@Y@@g@@@AAA""3'''' %R#o*>*>RRRSSS !0 D DH)%7CCCC"$s88DqyyRRRyRRSSSSBdGU^E__```eS'2222O$$I9999999J	jAAA 3RYY: 	
 	
 	

 	c/**+++++122222rx   r  AbstractSet[str]pri_maxc                    t          |          dk    rt          |          S t                      }|D ]S} |         }|j        D ]A}||v r;|j                            |t                    }|k     r|                    |           BTt          |          dk    rt          | fd          S t          |          t           |          } fd|D             S )a$  Come up with the ideal processing order within an SCC.

    Using the priorities assigned by all_imported_modules_in_file(),
    try to reduce the cycle to a DAG, by omitting arcs representing
    dependencies of lower priority.

    In the simplest case, if we have A <--> B where A has a top-level
    "import B" (medium priority) but B only has the reverse "import A"
    inside a function (low priority), we turn the cycle into a DAG by
    dropping the B --> A arc, which leaves only A --> B.

    If all arcs have the same priority, we fall back to sorting by
    reverse global order (the order in which modules were first
    encountered).

    The algorithm is recursive, as follows: when as arcs of different
    priorities are present, drop all arcs of the lowest priority,
    identify SCCs in the resulting graph, and apply the algorithm to
    each SCC thus found.  The recursion is bounded because at each
    recursion the spread in priorities is (at least) one less.

    In practice there are only a few priority levels (less than a
    dozen) and in the worst case we just carry out the same algorithm
    for finding SCCs N times.  Thus the complexity is no worse than
    the complexity of the original SCC-finding algorithm -- see
    strongly_connected_components() below for a reference.
    r  c                     |          j          S rn   r  r  s    rv   r   zorder_ascc.<locals>.<lambda>A  s    E"IO+; rx   r  c                <    g | ]}t          |          D ]}|S r}   )r  )r  sssrj   r  s      rv   rT  zorder_ascc.<locals>.<listcomp>E  s2    EEE"jG&D&DEEAEEEErx   )r   r  ri  r   r  r   r   r  r  r  r  )	rj   r  r  
pri_spreadr   rV  r  r  r  s	   ` `      rv   r  r    s    8 4yyA~~DzzJ ( (b	% 	( 	(Cd{{&**399==NN3'''		(
 :!d ; ; ; ;<<<<*ooGUD'22DEEEEEEEEErx   ro   c                .   t          j                     }|D ]}| |                                          t          j                     }|D ]}| |                                          t          j                     }|                    ||z
  ||z
             dS )zProcess the modules in one group of modules from their cached data.

    This can be used to process an SCC of modules
    This involves loading the tree from JSON and then doing various cleanups.
    )process_fresh_timeload_tree_timeN)r   r  r  r   )rj   ro   rh   r   r   rK  rv  s          rv   r   r   H  s     
B  b		B # #b	  """"	BbbIIIIIrx   r  c                    |}|D ]} |                                           d|v r d         j        }|s
J d            t          j                             |j                   t          |          }|D ]} |                                           |                                         j	        sI|
                    |            |                                           |                                          |ro|D ]j}||vr |                                         sI|
                    |            |                                           |                                          k|o|D ]6} |                                           |                                          7t!           fd|D                       r|D ]}d |         _        |D ]} |         j        j        j        vrfj                             |         j        j                  }                    j                             |         j                  |d            |                                           |                                          dS )zProcess the modules in one SCC from source code.

    Exception: If quick_and_dirty is set, use the cache for fresh modules.
    r[   z The typing module was not parsedc              3  b   K   | ])}j                             |         j                  V  *d S rn   )rt   is_errors_for_filer  )r  r   rj   rh   s     rv   r7  z$process_stale_scc.<locals>.<genexpr>  s9      
N
N"7>,,U2Y_==
N
N
N
N
N
Nrx   T)	formatterFN)r  r  r  semanal_mainsemantic_analysis_for_sccrt   ri  r  r  deferred_nodesdiscardr"  r6  r  re  ri  r9  rJ  r  r  file_messagesr   r   simplify_pathr  r  )rj   r  rh   staler   
typing_modunfinished_modulesrt   s   ` `     rv   r  r  X  s   
 E   	b	3 8_)
======//sGNKKK U & &b	'')))Ry%%''6 	&&&r***"I44666"I##%%%
 * 	* 	*B+++93355 *"**2...b	88:::b	'')))  *  7 7b	..000b	446666

N
N
N
N
N
N
N
NNN . 	. 	.B)-E"I&& & &9?'.">>>^11b	7+B 2  F   !=!=eBio!N!NPVX]^^^b	b	##%%%%& &rx   verticesAbstractSet[str] | Nonelist[AbstractSet[str]]c                    t                      fdD             }t          t          |                    }g }t          t	          ||                    D ])}|                    t          | fd                     *|S )a9  Return the graph's SCCs, topologically sorted by dependencies.

    The sort order is from leaves (nodes without dependencies) to
    roots (nodes on which no other nodes depend).

    This works for a subset of the full dependency graph too;
    dependencies that aren't present in graph.keys() are ignored.
    Nc           	     6    i | ]}|t          |          S r}   )deps_filtered)r  r   rj   r  r&  s     rv   r  z%sorted_components.<locals>.<dictcomp>  s)    PPPRuhG<<PPPrx   c                <    t          fd| D                        S )Nc              3  2   K   | ]}|         j         V  d S rn   r  r  s     rv   r7  z6sorted_components.<locals>.<lambda>.<locals>.<genexpr>  s)      5T5T"eBio5T5T5T5T5T5Trx   )r  )r  rj   s    rv   r   z#sorted_components.<locals>.<lambda>  s(    #5T5T5T5TPS5T5T5T2T2T1T rx   r  )ri  r  r   r   r   r   r  )rj   r&  r  edgesr  r  readys   ```    rv   r  r    s     u::PPPPPPxPPPE-h>>??D
CdE2233 	W 	W 	

6%%T%T%T%TUUUVVVVJrx   c                N    |vrg S | |         fdj         D             S )z.Filter dependencies for id with pri < pri_max.c                d    g | ],}|v j                             |t                    k     *|-S r}   r[  )r  r  r  rV  r&  s     rv   rT  z!deps_filtered.<locals>.<listcomp>  sI       (??u/33CBBWLL 	LLLrx   )r   )rj   r&  r   r  rV  s    ` `@rv   r+  r+    sV    		"IE     %   rx   r   c                B    t           j                            | d          S )Nmissing_stubs)r   r   r+  rE  s    rv   missing_stubs_filer4    s    7<<	?333rx   r   r  c                >   t          |           }|rVt          |d          5 }t          |          D ]}|                    | d           	 ddd           dS # 1 swxY w Y   dS t          j                            |          rt	          j        |           dS dS )zWrite a file containing missing stub packages.

    This allows a subsequent "mypy --install-types" run (without other arguments)
    to install missing stub packages.
    r  r!  N)r4  rM  r  r  r   r   r,  r  )r   r   r?  rN  pkgs        rv   r   r     s     i((D $__ 	$344 $ $3


####$	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 7>>$ 	IdOOOOO	 	s   +AA"Ac                    | j         j        rdS t          fd| j        j        D                       rdS t          fd| j        j        D                       S )NFc              3  8   K   | ]}t          |          V  d S rn   r-   r  dirr   s     rv   r7  z*is_silent_import_module.<locals>.<genexpr>  s.      
W
WctS))
W
W
W
W
W
Wrx   Tc              3  8   K   | ]}t          |          V  d S rn   r9  r:  s     rv   r7  z*is_silent_import_module.<locals>.<genexpr>  s.      \\#"4--\\\\\\rx   )r   no_silence_site_packagesr9  r   package_pathtypeshed_path)rh   r   s    `rv   r  r    sn    / u

W
W
W
WW5I5V
W
W
WWW t\\\\9M9[\\\\\\rx   rV  r   r  r  c                ^   ddl m} | j        sd S t          | j        | j        |          \  }}}d                    |                    d          d d                   dz   }|                    d          rJ  || j        |          }|	                    |t          |                     d S )Nr   )get_undocumented_ref_info_jsonr  z
.refs.json)mypy.refinforA  r  r  r   r  r+  r  rY  r  rS   )	rV  r   r   r  rA  r  	data_fileref_info_filer	  s	            rv   r2  r2    s     <;;;;;: %ehWEEOAy!HHY__S11#2#677,FM'',,,,,..uz8DDIOOM:i#8#899999rx   )NNNNNN)r~   r   r   rE   r   r   r   r   r   r   r   r   r   r   r   r   rk   rg   )r~   r   r   rE   r   r   r   r   r   r   r   r   r   r   r   r   rk   rg   r  )r   r   r   rE   rk   r   )r   r   r   r   rk   r   )r
  r    r  r   rk   r   )r   rE   rt   r   r   r   rk   r  )
r   rE   rt   r   r   r   r   r   rk   rE  )rA  rH  rk   r   )r   r   rQ  r   rR  r   rk   r   )r  r  rk   r  )r  r  rh   ri   rj   re   rk   rl   )r  r  rj   re   rk   r  )rh   ri   rj   re   rk   r  )rh   ri   rk   rl   )rh   ri   rk   r$  )r   rE   r   r   rk   r*  )rh   ri   rj   re   rk   r1  )
r#  r   rh   ri   r'  r   r(  r   rk   rA  )r   rE   rk   r   )rQ  r   rk   rl   )r   rE   rk   r;   )r   r   r   r   r   rE   rk   r[  )r   r   r   r   rh   ri   rk   rd  )r   rd  r   r   r   r   r   r   rh   ri   rk   rd  )r  r   rk   r   )r   r   r   r   r  r"   r   r   r   r   r   r   r   r   r  r   r  r   r   r   rh   ri   rk   r  )r   r   r   r   rh   ri   rk   rl   rj  )rh   ri   r   r   r   rE   r  r  r  r   r  r  r  r   r  r   rk   ro  )r   r   rh   ri   r   rE   rk   r   )r   r   rh   ri   rk   r   )r   r   rh   ri   rk   rA   )r   r   rh   ri   rk   r   )rh   ri   r  r   r  rc   rB  r   r  r@   rk   rl   )rh   ri   r  r   r  r  r   r   r   r   rk   rl   )
rh   ri   r   r   r   r   r  rc   rk   rl   )rh   ri   r~   r   rk   rl   )r~   r   rh   ri   r   r   rk   re   )r   r   rj   re   rk   rl   rn   )rj   re   r   r   rk   rl   )NN)
r~   r   rh   ri   r  r  r  r  rk   re   )rj   re   rh   ri   rk   rl   )rj   re   r  r  r  r   rk   r   )rj   re   ro   r   rh   ri   rk   rl   )rj   re   r  r   rh   ri   rk   rl   )rj   re   r&  r'  r  r   rk   r(  )
rj   re   r&  r  r   r   r  r   rk   r   )r   r   rk   r   )r   r   r   r  rk   rl   )rh   ri   r   r   rk   r   )
rV  rc   r   r;   r   rE   r  r  rk   rl   )r|   
__future__r   r^   rm  r  r   rH  r   r   r.  r  rY   r   rZ   collections.abcr   r   r   r   AbstractSetr[   r   r	   r
   r   r   r   r   r   r   ra   r   rd   mypy.semanal_mainr  mypy.checkerr   mypy.error_formatterr   r   mypy.errorsr   r   r   r   mypy.graph_utilsr   r   r   mypy.indirectionr   mypy.messagesr   
mypy.nodesr   r   r    r!   r"   r#   r$   mypy.partially_definedr%   mypy.semanalr&   mypy.semanal_pass1r'   	mypy.utilr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r4   r5   r  mypy.config_parserr6   
mypy.fixupr7   mypy.freetreer8   mypy.fscacher9   mypy.metastorer:   r;   r<   mypy.modulefinderr=   r>   r?   r@   rA   rB   rC   rD   mypy.optionsrE   
mypy.parserF   mypy.pluginrG   rH   rI   mypy.plugins.defaultrJ   mypy.renamingrK   rL   
mypy.statsrM   mypy.stubinforN   rO   
mypy.typesrP   mypy.typestaterQ   rR   rS   rT   mypy.versionrU   rV   r   rb   r|  r   re   rg   r   r   r   r   r   r   r   r   r  r  r  r  r	  r  rD  r   r:  r&  ri   r  r  r  r  r  r  r  r  r#  r~  r  r@  r)  r  r   r   ry  r  ry  r  r  r  r  r1  r  rc   r  r  r  rt  rz  r{  rw  rv  r  r   r  r   r   r  r  r  r  r   r  r  r+  r4  r   r  r2  r}   rx   rv   <module>re     s  	 	 	 # " " " " "          				  				  				  



   K K K K K K K K K K K K
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 6 5 5 5 5 5     $ $ $ $ $ $ ? ? ? ? ? ? ? ? N N N N N N N N N N N N Q Q Q Q Q Q Q Q Q Q 3 3 3 3 3 3 ( ( ( ( ( ( a a a a a a a a a a a a a a a a a a C C C C C C ) ) ) ) ) ) : : : : : :                           $###### $ $ $ $ $ $ 2 2 2 2 2 2 # # # # # # # # # # # # ( ( ( ( ( ( V V V V V V V V V V                  " ! ! ! ! !                   B B B B B B B B B B . . . . . . M M M M M M M M & & & & & & W W W W W W W W       9 9 9 9 9 9 9 9 , , , , , , , , $ $ $ $ $ $ "  ! ! ! !        g& & & & &$ $ $ $ $ $ $ $.  $IM&*  -1< < < < <~X[ X[ X[ X[v% % % %
% % % %    
   4    	   
   >                         	 	 	 	Y$ Y$ Y$ Y$xO O O O,       .e e e e e e e eP: : : :
 * ) ) ) )) ) ) ) ) "  ! ! ! !?c ?c ?c ?cD   4   8 7  6 6 6 6T T T T       (* * * *Z       F         $   !E !E !E !EH] ] ] ]@J J J JZ- - - -DA DA DA DANS S S S,FRH H H H HY H H HK K K K K K K Kj "&!%`! `! `! `! `!F   0         6'3 '3 '3 '3T; ; ; ;&   (!( !( !( !(NO O O Od
 
 
 
 
 
 
 
*9 9 9 9	> 	> 	> 	>$R $R $R $R $RT #&*	_ _ _ _ _DQ3 Q3 Q3 Q3h EL ,F ,F ,F ,F ,F^J J J J 1& 1& 1& 1&j 7;7    >	 	 	 	4 4 4 4    ] ] ] ]: : : : : :rx   