
    X-Ph9                       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mZmZ ddlmZmZ ddlmZmZmZ ddlmZ ddlZddlZddlZddlm Z m!Z!m"Z" dd	l#m$Z$m%Z% dd
l&m'Z' ddl(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@ ddlAmBZB dZCdeDd<   e
jE        dk    rddl	mFZF 	 dPdQd$ZGndRdSd'ZH	 dPdQd(ZGd)ZIdeDd*<   dTd/ZJdUd1ZKeLeMeMf         ZNd2eDd3<   eOeN         ZPd2eDd4<   eLePePf         ZQd2eDd5<    G d6 d7          ZRd8ZSdeDd9<   dVd;ZT	 dWdXdBZUdYdGZVdZdHZWd[dOZXdS )\zServer for mypy daemon mode.

This implements a daemon process which keeps useful state in memory
to enable fine-grained incremental reprocessing of changes.
    )annotationsN)SequenceSet)redirect_stderrredirect_stdout)AnyCallableFinal)	TypeAlias)WriteToConnreceivesend)InvalidSourceListcreate_source_list)FileSystemCache)FileDataFileSystemWatcher)InspectionEngine)	IPCServer)BuildSourceFindModuleCacheSearchPathscompute_search_paths)Options)FineGrainedBuildManagerrefresh_suppressed_submodules)SuggestionEngineSuggestionFailure)reset_global_state)FancyFormattercount_stats)__version__Fr
   MEM_PROFILEwin32)STARTUPINFOoptionsr   status_filestrtimeout
int | Nonelog_file
str | Nonereturnintc                   t           j        ddd|dg}t          j        |                                           }|                    dt          j        |                                           d           |r|                    d|            |r|                    d|            t                      }d	|_
        d
|_        	 t          j        |d|           d
S # t          j        $ r}|j        cY d}~S d}~ww xY w)a  Create the daemon process via "dmypy daemon" and pass options via command line

        When creating the daemon grandchild, we create it in a new console, which is
        started hidden. We cannot use DETACHED_PROCESS since it will cause console windows
        to pop up when starting. See
        https://github.com/python/cpython/pull/4150#issuecomment-340215696
        for more on why we can't have nice things.

        It also pickles the options to be unpickled by mypy.
        z-mz
mypy.dmypyz--status-filedaemonz--options-data=""z
--timeout=z--log-file=   r      )creationflagsstartupinfoN)sys
executablepickledumpssnapshotappendbase64	b64encodedecoder%   dwFlagswShowWindow
subprocessPopenCalledProcessError
returncode)r&   r'   r)   r+   commandpickled_optionsinfoes           Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/dmypy_server.py	daemonizerJ   .   s"    >4U]^ ,w'7'7'9'9::W&*:?*K*K*R*R*T*TWWWXXX 	3NN111222 	5NN333444}}	 WDdKKKK1, 	  	  	 <	 s   C   D /C;5D ;D funcCallable[[], None]c                   t           j                                         t           j                                         t	          j                    }|rKt	          j        |d          \  }}|dz  }|rt          d|           | S |dz	  }|rt          d|           |S 	 t	          j                     t	          j	        d           t	          j
        dt          j                  }t	          j        |d           t	          j        |d           t	          j        |d	           t	          j        |           t	          j                    }|rt	          j        d           |rpt          |d
d          xt           _        t           _        t           j                                        }t	          j        |d	           t	          j        |d            |              t	          j        d           dS # t	          j        d           w xY w)zArrange to call func() in a grandchild of the current process.

        Return 0 for success, exit status for failure, negative if
        subprocess killed by signal.
        r      zChild killed by signal   zChild exit status   z	/dev/nullr2      a)	bufferingN)r6   stdoutflushstderrosforkwaitpidprintsetsidumaskopenO_RDWRdup2close_exitfileno)rK   r+   pidnpidstssigdevnullfds           rI   _daemonize_cbri   M   s    	

gii 
	
3**ID#*C .444t(C 0)3///J	IKKKHTNNNgk2955GGGQGGQGGQHW'))C  *.x*J*J*JJ
SZZ&&((AADFFF HQKKKKKBHQKKKKs   D>G2 2Hc                J    t          t          | ||          j        |          S )zRun the mypy daemon in a grandchild of the current process

        Return 0 for success, exit status for failure, negative if
        subprocess killed by signal.
        )ri   Serverserve)r&   r'   r)   r+   s       rI   rJ   rJ   z   s#     VG['BBH(SSS    dmypyCONNECTION_NAMEflags	list[str]allow_sourcesboolc                .   t           j                            dg| z   dd          \  }}|j        rt	          d           |j        rt	          d           d |_        |j        st          j        d           |j	        dvrt          j        d	           |S )
N-iFT)require_targetsserver_optionszRdmypy: Ignoring report generation settings. Start/restart cannot generate reports.zxdmypy: Ignoring report generation settings. Start/restart does not support --junit-xml. Pass it to check/recheck insteadz8dmypy: start/restart should not disable incremental mode)skiperrornormalz*dmypy: follow-imports=silent not supported)
mypymainprocess_optionsreport_dirsrZ   	junit_xmlincrementalr6   exitfollow_imports)rp   rr   _r&   s       rI   process_start_optionsr      s    **	d +  JAw  dbccc ![	
 	
 	
 ! MKLLL%@@@=>>>Nrm   modulec                ,    |                      d          S )z=Can we skip looking for newly unsuppressed imports to module?z
encodings.)
startswithr   s    rI   ignore_suppressed_importsr      s    
 \***rm   
_TypeAliasModulePathPairModulePathPairsChangesAndRemovalsc                  "   e Zd Zd_d`d
ZdadZdbdZdcdZd_dddZdedZdfdZ	dgd Z
	 	 dhdid$Zdjd(Zdbd)Zdkd+Zdld,Zdmd-Z	 	 	 dndod1Z	 dpdqd2Zdrd;Zdsd>ZdtdBZdudDZ	 	 dvdwdFZdxdGZdydIZdzdJZd{dKZd|dMZ	 	 	 	 	 	 	 d}d~dXZdd]Zded^ZdS )rk   Nr&   r   r'   r(   r)   r*   r-   Nonec                   || _         |                                | _        || _        d| _        t
          j                            |          rt          j        |           t                      | _
        d|_        d|_        d|_        d|_        |j        rd|_        nt
          j        |_        d|_        || _        t+          t,          j        t,          j        |j                  | _        dS )z2Initialize the server with the desired mypy flags.NT)r&   r:   options_snapshotr)   fine_grained_managerrW   pathisfileunlinkr   fscacheraise_exceptionsr   fine_grained_incrementalshow_tracebackuse_fine_grained_cachecache_fine_grainedrg   	cache_dirlocal_partial_typesr'   r    r6   rT   rV   hide_error_codes	formatter)selfr&   r'   r)   s       rI   __init__zServer.__init__   s     ' 0 0 2 2DH!7>>+&& 	#Ik"""&((#' "+/(!%) 	+ *.G&& "
G '+#& (
CJ@XYYrm   dict[str, str]c                n    | j         j        d          d| j         j        d          }| j         j        |dS )Nr   r   r2   )platformpython_version)r&   r   r   )r   
py_versions     rI   _response_metadatazServer._response_metadata   s=    3A6YY9TUV9WYY
 L1ZPPPrm   c                `   d}t          t          | j                  }t          j        }t          j        }	 t          | j        d          5 }t          j	        t          j                    |j        d|           |                    d           ddd           n# 1 swxY w Y   	 |5  t          |          }t          |dt          j                                                  t          _        t          |dt          j                                                  t          _        i }d|vrd	d
i}n|d         }t#          |t$                    sd	di}n|                    d          }	 |                     ||          }n# t*          $ rw t-          j        t          j                     }d	dd                    |          z   i}|                    |                                            d|d<   t9          ||            w xY wd|d<   	 |                    |                                            t9          ||           n# t:          $ r Y nw xY w|dk    r"t=                       t          j        d           ddd           n# 1 swxY w Y   # |t          _        |t          _        |dk    rt          j         | j                   	 |!                                 n# t:          $ r Y nw xY wt          j                    }	|	d         r|	d         tD          urt-          j#        |	  w w w xY w)z2Serve requests, synchronously (no thread or fork).Nw)rc   connection_name
TrT   rV   rE   ry   zNo command found in requestzCommand is not a stringzDaemon crashed!
 finalstopr   )$r   ro   r)   r6   rT   rV   r]   r'   jsondumprW   getpidr   writer   r   isatty
isinstancer(   poprun_command	Exception	tracebackformat_exceptionexc_infojoinupdater   r   OSErrorr   r   r   cleanup
SystemExitprint_exception)
r   rE   serverorig_stdoutorig_stderrfdataresptbr   s
             rI   rl   zServer.serve   s    ?DL99jj7	5d&,, 	")++&BXYY[\]]]               $ $ $"6??D!,VXsz?P?P?R?R!S!SCJ!,VXsz?P?P?R?R!S!SCJ+-D ,, ')FG"&y/)'377 &$+-F#GDD&*hhy&9&9G	&'+'7'7'F'F#, & & &%.%?%P(/1Drwwr{{1R'S $D,C,C,E,E F F F04W $VT 2 2 2 %& %)DMD$;$;$=$=>>>VT****"   &((*,,,?$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $F %CJ$CJ &  	$*+++       |~~H{ 5x{*<<)84445<s   J ABJ BJ "B#J )C J*F JBHJ7IJ
IJI+J;J JJ JJ 8L-K"!L-"
K/,L-.K//>L-rE   r   dict[str, object]c                    d|z   }t          | j        |d          }|dd| diS |dvr|d= |d=  || fi |}t          |t                    sJ |S )	z)Run a specific command from the registry.cmd_Nry   zUnrecognized command ''>   runcheckrecheckis_ttyterminal_width)getattr	__class__r   dict)r   rE   r   keymethodrets         rI   r   zServer.run_command  s    wd33>@g@@@AA999N)*&&&&&Cc4(((((Jrm   fswatcher_dump_filer,   c                H   i }|                     t                                 |r|t          | d          r| j                                        ni }t          j        |          }t          |d          5 }|                    |           ddd           n# 1 swxY w Y   |S )zReturn daemon status.	fswatcherr   N)	r   get_meminfohasattrr   dump_file_datar   r9   r]   r   )r   r   resr   sr   s         rI   
cmd_statuszServer.cmd_status$  s    !#

;==!!! 	6=dK6P6PX4>00222VXD
4  A)3// 1


              
s   5BBBc                8    t          j        | j                   i S )zStop daemon.)rW   r   r'   r   s    rI   cmd_stopzServer.cmd_stop0  s     		$"###	rm   versionargsSequence[str]export_typesrs   r   r   r.   c           
        t          j                    }t          j                    }	 t          |          5  t          |          5  t          j                            dgt          |          z   dd| j        dt          j
                  \  }}	ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |	                    | j                  sddiS t          |k    rddiS | j        rR| j        j        }
|
j        }t          j                            |	|
j        t(          j        d	
          \  }}||k    rddiS nk# t,          $ r}dt/          |          ddcY d}~S d}~wt0          $ r9}|                                |                                |j        dcY d}~S d}~ww xY w|                     ||||          S )z6Check a list of files, triggering a restart if needed.ru   Tzmypy-daemon)rv   rw   r   programheaderNrestartzconfiguration changedzmypy version changed )extra_pluginszplugins changedr   rQ   outerrstatus)ioStringIOr   r   r{   r|   r}   listr   argparseSUPPRESScompare_stabler   r"   r   managerplugins_snapshotbuildload_pluginserrorsr6   rT   r   r(   r   getvaluecoder   )r   r   r   r   r   r   rV   rT   sourcesr&   r   start_plugins_snapshotr   current_plugins_snapshotr   rH   s                   rI   cmd_runzServer.cmd_run9  s    	Z !(( 	 	$V,,  '+y'@'@d+(,'+ $ -'0 (A ( ($GW              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ))$*?@@ <!#:;;g%%!#9::( :3;)0)A&.2j.E.EW^SZr /F / /++ ,/EEE%'899  	= 	= 	=c#hh!<<<<<<<< 	Z 	Z 	Z!??,,V__5F5FRSRXYYYYYYYY	Zzz'<HHHs   E B3A	BB3B 	 B3#B 	$B3'E 3B77E :B7; E E +AE 
F-E'!F-'F-4.F("F-(F-filesc                    	 t          || j        | j                  }n*# t          $ r}dt	          |          ddcY d}~S d}~ww xY w|                     ||||          S )zCheck a list of files.r   rQ   r   N)r   r&   r   r   r(   r   )r   r  r   r   r   r   r   s          rI   	cmd_checkzServer.cmd_checkd  sz    	=(dlKKGG  	= 	= 	=c#hh!<<<<<<<<	=zz'<HHHs    
AA A Aremovelist[str] | Noner   c                   t          j                     }| j        sddiS | j        }|rt          |          fd|D             }|r~|                    d d           d |D             fd|D             }	 t          || j        | j                  }	n*# t          $ r}
d	t          |
          d
dcY d}
~
S d}
~
ww xY w||	z   }t          j                     }| j        j
        }|                    d||z
  dd           | j        j        }| j        j        p|| j        _        |                                 s|                     ||||          }n||J |                     ||          }|                     ||||          }|                                  |                     |           || j        _        |S )zCheck the same list of files we checked most recently.

        If remove/update is given, they modify the previous list;
        if all are None, stat() is called for each file in the previous list.
        ry   z7Command 'recheck' is only valid after a 'check' commandc                4    g | ]}|j         	|j         v|S r   r   ).0r   removalss     rI   
<listcomp>z&Server.cmd_recheck.<locals>.<listcomp>  s,    OOOQQVOh8N8Nq8N8N8Nrm   c                L    t           j                            |           d         S )Nr2   )rW   r   splitext)r   s    rI   <lambda>z$Server.cmd_recheck.<locals>.<lambda>  s    bg&6&6q&9&9!&< rm   T)r   reversec                *    h | ]}|j         	|j         S r   r	  r
  r   s     rI   	<setcomp>z%Server.cmd_recheck.<locals>.<setcomp>  s!    7777QV777rm   c                    g | ]}|v|	S r   r   )r
  pknowns     rI   r  z&Server.cmd_recheck.<locals>.<listcomp>  s    9991!5..Q...rm   r   rQ   r   Nz%fine-grained increment: cmd_recheck: .3fr   explicit_export_types)timer   previous_sourcessetsortr   r&   r   r   r(   r   logr   following_importsfine_grained_increment%fine_grained_increment_follow_importsincrement_outputflush_cachesupdate_stats)r   r   r   r   r  r   t0r   addedadded_sourcesr   t1r   old_export_typesmessagesr   r  r  s                   @@rI   cmd_recheckzServer.cmd_recheckn  s-    Y[[( 	XVWW' 	P6{{HOOOO'OOOG 
	.KK<<dKKKK77W777E9999999EA 25$, U U$ A A A!#c((a@@@@@@@@A-GY[[+3JBGJJJJKKK<4$(L$=$M!%%'' 	22| 3  HH >fnnnAA| B  H ##Hgv~NN#$4!
s   <B 
B?"B:4B?:B?r   list[BuildSource]dict[str, Any]c                   | j         j        }| j         j        p|| j         _        | j        s|                     |||          }n[|                                 s|                     ||          }n|                     ||          }|                     ||||          }|                                  | 	                    |           || j         _        |S )zCheck using fine-grained incremental mode.

        If is_tty is True format the output nicely with colors and summary line
        (unless disabled in self.options). Also pass the terminal_width to formatter.
        r  )
r&   r   r   initialize_fine_grainedr  r   r!  r"  r#  r$  )r   r   r   r   r   r)  r   r*  s           rI   r   zServer.check  s      <4$(L$=$M!( 		S..wOOCC))++ 66wVb6ccEE< F   '''6>RRC#$4!
rm   c                |    | j                                          | j        r| j                                         d S d S N)r   rU   r   flush_cacher   s    rI   r#  zServer.flush_caches  sF    $ 	4%1133333	4 	4rm   r   c                z    | j         r3| j         j        }|                                 |j        |d<   i |_        d S d S )Nstats)r   r   
dump_statsr4  )r   r   r   s      rI   r$  zServer.update_stats  sJ    $ 	/7G   "=CLGMMM		 	rm   c                "    | j         j        dk    S )zAre we following imports?rz   )r&   r   r   s    rI   r  zServer.following_imports  s     |*h66rm   c           
        t          | j                  | _        t          j                    }|                     |           t          j                    }	 t
          j                            || j        | j                  }n[# t
          j        j	        $ rD}d
                    d |j        D                       }|j        r|d}
}	nd|}
}	|	|
ddcY d }~S d }~ww xY w|j        }t          |          | _        t          |          }|                                 r/t#          | j        j        |          }|                     |           || _        |j        rt          j                    }| j        j                                        D ]a}|j        }||j        J | j                            |j        t3          t5          |j                  |j        |j                             b|                     |          \  }}||                     | j        j        tA                      | j        j!        j"                  z  }| j        j                                        D ]@}|#                                s*|j        J |$                    |j%        |j        f           At          j                    }| j        &                    ||          }|                                 r| '                    |          }t          j                    }| j        j!        (                    ||z
  ||z
  ||z
  ||z
  t          |          t          |          z              n| j                                         tR          rdd	l*m+}  |d
           tY          |          \  }}}|r|t          |          k     rdnd}| -                    ||||          }d
                    d |D                       d|dS )N)r   r&   r   r   c              3      K   | ]	}|d z   V  
dS r   Nr   r  s     rI   	<genexpr>z1Server.initialize_fine_grained.<locals>.<genexpr>  s&      ::!QX::::::rm   rQ   r   )st_mtimest_sizehash)update_sources_time
build_timefind_changes_timefg_update_timefiles_changedr   )print_memory_profileF)run_gcr2   c              3      K   | ]	}|d z   V  
dS r9  r   r  s     rI   r:  z1Server.initialize_fine_grained.<locals>.<genexpr>!  &      ::Aq4x::::::rm   ).r   r   r   r  update_sourcesr{   r   r&   r   CompileErrorr   r*  
use_stdoutr   r   lenr  find_all_sources_in_buildgraphr  
used_cachevaluesmetar   set_file_datar   floatmtimesizer=  find_changedfind_added_suppressedr  r   search_pathsis_freshr;   idr   r!  	add_statsr#   mypy.memprofilerC  r!   pretty_messages)r   r   r   r   r%  r(  resultrH   outputr   r   r*  original_sources_lent2staterO  changedremovedt3t4rC  __n_notesr   s                           rI   r/  zServer.initialize_fine_grained  s    +4<88Y[[G$$$Y[[	9Z%%gt|UYUa%bbFF{' 	9 	9 	9WW::qz:::::F| &!2SvSsa88888888	9 =$;F$C$C!"7||!!## 	)/0I0OQXYYG((( '
  .	*B 28??AA  z<z---,,JeDJ&7&7QUQZ[[[   
  $0099GWt11)/)1>  G 28??AA ; ;~~'' ; :111NNEHej#9:::B077IIH%%'' OEEgNNB%-77$&G7"$r'!Bw!'llS\\9 8     N''))) 	/<<<<<<  ....%h//GRA7S]]#:#:''2FP^__ww:::::::2QWXXXs   ,B C9CCCFr  rq   c                >   | j         J | j         j        }t          j                    }|0|.|                     |           |                     |          \  }}n|                     ||pg |pg           \  }}|rt          ||           ||                     | j         j        t                      |j
                  z  }t          ||j        |j                  |_
        t          j                    }	|                    d|	|z
  dd           | j                             ||          }
t          j                    }|                    d||	z
  dd           |                    |	|z
  ||	z
  t#          |          t#          |          z              || _        |
S )a  Perform a fine-grained type checking increment.

        If remove and update are None, determine changed paths by using
        fswatcher. Otherwise, assume that only these files have changes.

        Args:
            sources: sources passed on the command line
            remove: paths of files that have been removed
            update: paths of files that have been changed or created
            explicit_export_types: --export-type was passed in a check command
              (as opposite to being set in dmypy start)
        N&fine-grained increment: find_changed: r  r    fine-grained increment: update: )r@  rA  rB  )r   r   r  rG  rT  update_changedadd_all_sources_to_changedrU  rL  r  rV  r   r&   data_dirr  r   rY  rJ  r  )r   r   r  r   r  r   r%  ra  rb  r(  r*  r_  s               rI   r   zServer.fine_grained_increment#  s   & (444+3Y[[>fn (((#0099GWW  $227FLb&,TVWWGW  	9 'w8884--%+SUUG4H
 
 	
  4GW_gN^__Y[[KR"WKKKKLLL,33GWEEY[[ErBwEEEEFFF 2g7g,,W5 	 	
 	
 	
 !(rm   c           	     \   t          j                     }| j        J | j        j        }j        }t	          |                                          }|                     |           | j                                        }t          ||j
        |j                  |_        t          j                     }|                    d||z
  dd           d |D             |                     |||          \  }	}
|                     ||	           |rt!          ||	           |                    |
                               |	g d          }|	                                }|r|                                }|d         |vr!|                     ||          }fd	|D             }|                     |||          \  }	}
|                     |
                               |	g d          }|                    |	           |t          j                     }dfd}t	          |                                          D ],\  }}t/          ||j        j        || j        |          }||}-t          j                     }	 |                     ||j                  }|snyd |D             }
|                    |
           |                     |
                               |g d          }|D ]'\  }}t/          ||j        || j        |          }||}(t          j                     }g }|D ]3}||vr|vr(||         j        }|J |                    ||f           4|r                    g |          }t;          |           t=          |          | _        |                     | j                   | j                                         t          j                     }|                    d||z
  dd           |                     ||z
  ||z
  ||z
  ||z
  ||z
             |S )z0Like fine_grained_increment, but follow imports.Nrh  r  r   c                    h | ]	}|j         
S r   r   r
  sources     rI   r  z?Server.fine_grained_increment_follow_imports.<locals>.<setcomp>r  s    444&444rm   Tfollowedr   c                &    g | ]}|j         v|S r   r   )r
  rp  seens     rI   r  z@Server.fine_grained_increment_follow_imports.<locals>.<listcomp>  s%    SSS6d9R9R9R9R9Rrm   r   r(   r   r-   rq   c                :                         | |fgg d          S )NTrq  )r   )r   r   r   s     rI   refresh_filezBServer.fine_grained_increment_follow_imports.<locals>.refresh_file  s%    '../?d.SSSrm   c                J    g | ] }t          |d          |d         d          !S )r2   r   Trq  )r   )r
  mods     rI   r  z@Server.fine_grained_increment_follow_imports.<locals>.<listcomp>  s/    ```SVSVdCCC```rm   ri  )r@  rA  refresh_suppressed_timefind_added_suppressed_timecleanup_time)r   r(   r   r(   r-   rq   )!r  r   rL  r   r   keysrG  r   rT  r   r&   rl  rV  r  find_reachable_changed_modulesadd_explicitly_newrk  extendr   copyr   direct_importsitemsr   r   depsr   rU  r;   fix_module_depsrK  r  rY  )r   r   r  r%  rL  r   orig_moduleschanged_pathsr(  ra  	new_filesr*  worklistr   sources2r_  rv  	module_idr`  new_messagesrc  new_unsuppressedr   rd  	to_deletemodule_patht5r   rt  s                              @@rI   r!  z,Server.fine_grained_increment_follow_importsY  s    Y[[ (444#8$*&.EJJLL))G$$$33553GW_gN^__Y[[KR"WKKKKLLL
 54G444 "@@UD-
 
 	111  	9&w888y!!! (..wT.JJ <<>> 	%\\^^Fay%%**6599H TSSSXSSSH!%!D!D%}" "GY 	***+227B2NNHOOG$$$  	%  Y[[	T 	T 	T 	T 	T 	T !%U[[]] 3 3 	( 	(Iu85:';'@%Wc L ''Y[[	,#99%wG[\\# ``O_```INN9%%%	***+223CRRV2WWH#3 , ,	4<t%9%>t|Ua     ++H	,  Y[[ 	% 	; 	;I%%$$#I.3"...  )[!9::: 	B+222yAAH 9% @ @D1222 	##%%%Y[[ErBwEEEEFFF 2g7$&G')Bwb 	 	
 	
 	
 rm   rootsrL  mypy.build.Graphrt  set[str]r  AbstractSet[str]/tuple[list[tuple[str, str]], list[BuildSource]]c                   g }g }|                                 }|                    d |D                        |r|                                }|j        |vr/|                    |j                   |                    |           |j        |v r+|j        J |                    |j        |j        f           n|j        |v rw||j                 }	|	j        pg }
|	j        |
z   D ]V}||vrP|                    |           |                    t          ||         j        ||         j
        d                     W|||fS )a  Follow imports within graph from given sources until hitting changed modules.

        If we find a changed module, we can't continue following imports as the imports
        may have changed.

        Args:
            roots: modules where to start search from
            graph: module graph to use for the search
            seen: modules we've seen before that won't be visited (mutated here!!).
                  Needed to accumulate all modules encountered during update and remove
                  everything that no longer exists.
            changed_paths: which paths have changed (stop search here and return any found)

        Return (encountered reachable changed modules,
                unchanged files not in sources_set traversed).
        c              3  $   K   | ]}|j         V  d S r1  r   ro  s     rI   r:  z8Server.find_reachable_changed_modules.<locals>.<genexpr>  s$      99fFM999999rm   NTrq  )r  r   r   r   addr;   r   	ancestorsdependenciesr   rX  )r   r  rL  rt  r  ra  r  r  nxtr`  r  deps               rI   r}  z%Server.find_reachable_changed_modules  s]   . 	::<<99999999 	d,,..Cz%%$$$  %%%x=((x+++
CH56666u$$cj)!O1r	 -	9 d dC$ E#JOU3Z]]a(b(b(bccc  	d 	!!rm   r   tuple[str, str]c                F    |d                  }fd|j         D             S )z9Return the direct imports of module not included in seen.r   c                J    g | ]}t          |         j        |d            S )Trq  )r   r   )r
  r  rL  s     rI   r  z)Server.direct_imports.<locals>.<listcomp>  s.    ___SE#JOS4@@@___rm   )r  )r   r   rL  r`  s     ` rI   r  zServer.direct_imports  s0     fQi ____EL^____rm   rV  r   list[tuple[str, str]]c                X   t                      }                                D ]}||j        z  }fd|D             }d |D             }t          ||| j                  }t          || j        | j                  }g }|D ]}	|	                    dd          d         }
|
|vr#|                    |	d          }t          |t                    rZ|	|vrV|                                 s|                    d          s}|                    |	|f           |                    |	           |S )	a_  Find suppressed modules that have been added (and not included in seen).

        Args:
            seen: reachable modules we've seen before (mutated here!!).
                  Needed to accumulate all modules encountered during update and remove
                  everything that no longer exists.

        Return suppressed, added modules.
        c                :    h | ]}|vt          |          |S r   )r   )r
  r   rL  s     rI   r  z/Server.find_added_suppressed.<locals>.<setcomp>  s<     
 
 
U""+DV+L+L" """rm   c                F    h | ]}|                     d d          d         S ).r2   r   )split)r
  r   s     rI   r  z/Server.find_added_suppressed.<locals>.<setcomp>&  s+    IIIFLLa((+IIIrm   r  r2   r   T)	fast_path.pyi)r  rN  suppressed_set%filter_out_missing_top_level_packagesr   r   r&   r  find_moduler   r(   r  endswithr;   r  )r   rL  rt  rV  all_suppressedr`  packagesfinderfoundr   top_level_pkgr\  s    `          rI   rU  zServer.find_added_suppressed
  se    \\^^ 	3 	3Ee22NN

 
 
 
(
 
 
 JI.III8<QUQ]^^ !t|T\JJ$ 	! 	!F"LLa003MH,,''$'??F&#&& !6+=+=--// 8O8O ff-...   rm   r*  c                    |rdnd}|                      |t          |          ||          }d                    d |D                       d|dS )Nr2   r   r   c              3      K   | ]	}|d z   V  
dS r9  r   r  s     rI   r:  z*Server.increment_output.<locals>.<genexpr>C  rF  rm   r   )r[  rJ  r   )r   r*  r   r   r   r   s         rI   r"  zServer.increment_output>  s]     %A''#g,,WWww:::::::2QWXXXrm   	n_sourcesc                     j         j        o|} j         j        o|}|r j                            ||          } j         j        rnd }t          |          \  }}	}
|r j                            ||
||          }n0|r|	t          |          k    r j        	                    ||          }|r||gz   }|r fd|D             }|S )N)fixed_terminal_width)	use_colorc                D    g | ]}j                             |          S r   )r   colorize)r
  mr   s     rI   r  z*Server.pretty_messages.<locals>.<listcomp>_  s)    EEEq//22EEErm   )
r&   color_outputprettyr   fit_in_terminalerror_summaryr!   format_errorrJ  format_success)r   r*  r  r   r   r  	fit_widthsummaryn_errorsrf  n_filess   `          rI   r[  zServer.pretty_messagesE  s    L-8&	L'2F	 	~55~ 6  H <% 	0"&G)4X)>)>&Hgw N.55gyI 6    NCMM!9!9.77	9MM 0#wi/ 	FEEEEHEEEHrm   c                     d |D             }                                  r fd|D             } j                            |           d S )Nc                *    g | ]}|j         	|j         S r1  r	  ro  s     rI   r  z)Server.update_sources.<locals>.<listcomp>c  s!    NNNfk6M6M6M6Mrm   c                H    g | ]}j                             |          |S r   )r   r   )r
  r   r   s     rI   r  z)Server.update_sources.<locals>.<listcomp>f  s.    IIIdt|/B/B4/H/HITIIIrm   )r  r   add_watched_paths)r   r   pathss   `  rI   rG  zServer.update_sourcesb  s`    NN7NNN!!## 	JIIIIeIIIE((/////rm   r   c                d    | j                             ||          }|                     ||          S r1  )r   rj  _find_changed)r   r   r  r   r  s        rI   rj  zServer.update_changedi  s1     55ffEE!!'=999rm   c                `    | j                                         }|                     ||          S r1  )r   rT  r  )r   r   r  s      rI   rT  zServer.find_changedo  s+    3355!!'=999rm   c                  
 fd|D             }d |D             

fd| j         D             }g }|D ])}|j        }|sJ |                    |j        |f           *|                     ||           d | j         D             }|D ]r}	|	j        sJ |	j        |v r^||	j                 |	j        k    rH|                    ||	j                 |	j        f           |                    |	j        |	j        f           s||fS )Nc                L    g | ] }|j         r|j         v |j        |j         f!S r   r   r   )r
  rp  r  s     rI   r  z(Server._find_changed.<locals>.<listcomp>w  sE     
 
 
{
  &{m;; ]FK(;;;rm   c                    h | ]	}|j         
S r   r   ro  s     rI   r  z'Server._find_changed.<locals>.<setcomp>~  s    777V6=777rm   c                &    g | ]}|j         v|S r   r   )r
  rp  moduless     rI   r  z(Server._find_changed.<locals>.<listcomp>  s&    ^^^fV]A]A]6A]A]A]rm   c                (    i | ]}|j         |j        S r   r  r  s     rI   
<dictcomp>z(Server._find_changed.<locals>.<dictcomp>  s    @@@Q@@@rm   )r  r   r;   r   r~  )r   r   r  ra  omittedrb  rp  r   lastr   r  s     `       @rI   r  zServer._find_changeds  sI   
 
 
 
!
 
 
 87w777^^^^(=^^^ 	2 	2F;DKKKNNFM401111111 A@$*?@@@ 	3 	3A6MMMv~~$qv,!(":":QVaf5666!&1222rm   ra  c                    d | j         D             t          |          |                    fd|D                        d S )Nc                    h | ]	}|j         
S r   r   ro  s     rI   r  z,Server.add_explicitly_new.<locals>.<setcomp>  s    NNNfFMNNNrm   c                l    g | ]0}|j         r'|j        vr|j        |j         fv"|j        |j         f1S r   r  )r
  rp  changed_setprevious_moduless     rI   r  z-Server.add_explicitly_new.<locals>.<listcomp>  s]       ; M)999]FK0CC	 , DCCrm   )r  r  r  )r   r   ra  r  r  s      @@rI   r~  zServer.add_explicitly_new  st     ON8MNNN'll    %  	
 	
 	
 	
 	
rm   r   showlocation	verbositylimitinclude_spaninclude_kindinclude_object_attrsunion_attrsforce_reloadc
           
        | j         sddiS t          | j         |||||||	          }
| j        j        }d| j        _        	 |dk    r|
                    |          }nB|dk    r|
                    |          }n&|dk    r|
                    |          }n
J d	            || j        _        n# || j        _        w xY wd
|v r-t          |d
         t                    sJ |d
xx         dz  cc<   |S )z!Locate and inspect expression(s).ry   zWCommand "inspect" is only valid after a "check" command (that produces no parse errors))r  r  r  r  r  r  r  Ttypeattrs
definitionFzUnknown inspection kindr   r   )	r   r   r&   inspectionsget_type	get_attrsget_definitionr   r(   )r   r  r  r  r  r  r  r  r  r  engineold_inspectionsr\  s                rI   cmd_inspectzServer.cmd_inspect  s7    ( 	 3  "%%%!5#%	
 	
 	
 ,2#' 
	7v~~22))(33%%..x8877777'6DL$$DL$6666F??fUmS111115MMMT!MMMs   AB, ,B:function	callsiteskwargsr   c                   | j         sddiS t          | j         fi |}	 |r|                    |          }n|                    |          }|sd}n|                    d          s|dz  }|ddd|                                  S # t          $ r/}dt          |          icY d}~|                                  S d}~ww xY w# |                                  w xY w)	z#Suggest a signature for a function.ry   zWCommand 'suggest' is only valid after a 'check' command (that produces no parse errors)zNo suggestions
r   r   r   r   N)r   r   suggest_callsitessuggestr  r#  r   r(   )r   r  r  r  r  r   r   s          rI   cmd_suggestzServer.cmd_suggest  s,   ( 	 3  "$";FFvFF	  /..x88nnX..  (\\$'' trQ77 ! 	' 	' 	'SXX&&&&&& 	' s5   -B $C 
B>B9B> C 9B>>C Cc                .    t          j        d           i S )z&Hang for 100 seconds, as a debug hack.d   )r  sleepr   s    rI   cmd_hangzServer.cmd_hang  s    
3	rm   r1  )r&   r   r'   r(   r)   r*   r-   r   )r-   r   )r-   r   )rE   r(   r   r   r-   r   )r   r,   r-   r   )r-   r   )r   r(   r   r   r   rs   r   rs   r   r.   r-   r   )
r  r   r   rs   r   rs   r   r.   r-   r   NN)r   rs   r   r.   r   rs   r  r  r   r  r-   r   )
r   r,  r   rs   r   rs   r   r.   r-   r-  )r   r-  r-   r   )r-   rs   )r   r,  r   rs   r   r.   r-   r-  )NNF)
r   r,  r  r  r   r  r  rs   r-   rq   )F)r   r,  r  rs   r-   rq   )
r  r,  rL  r  rt  r  r  r  r-   r  )r   r  rL  r  r-   r,  )rL  r  rt  r  rV  r   r-   r  )
r*  rq   r   r,  r   rs   r   r.   r-   r-  )FN)
r*  rq   r  r.   r   rs   r   r*   r-   rq   )r   r,  r-   r   )r   r,  r  rq   r   rq   r-   r   )r   r,  r-   r   )r   r,  r  r  r-   r   r   r,  ra  r  r-   r   )r   r   FFFFF)r  r(   r  r(   r  r.   r  r.   r  rs   r  rs   r  rs   r  rs   r  rs   r-   r   )r  r(   r  rs   r  r   r-   r   ) __name__
__module____qualname__r   r   rl   r   r   r   r  r  r+  r   r#  r$  r  r/  r   r!  r}  r  rU  r"  r[  rG  rj  rT  r  r~  r  r  r  r   rm   rI   rk   rk      s       Z Z Z Z Z@Q Q Q Q?5 ?5 ?5 ?5B   "
 
 
 
 
   )I )I )I )IVI I I I $(#'1 1 1 1 1f   24 4 4 4
   7 7 7 7
VY VY VY VYv $(#'&+4 4 4 4 4n IN| | | | ||*" *" *" *"X` ` ` `2 2 2 2hY Y Y Y %)    :0 0 0 0: : : :: : : :       @
 
 
 
, ""%*!", , , , ,\       0     rm   rk   i   MiBr-  c                    i } 	 dd l }|                                }|                                }|j        t          z  | d<   |j        t          z  | d<   t          j        dk    r|j        t          z  | d<   n^dd l	}|
                    |j                  }t          j        dk    rd}nd}|j        |z  t          z  | d<   n# t          $ r d	| d
<   Y nw xY w| S )Nr   memory_rss_mibmemory_vms_mibr$   memory_maxrss_mibdarwinr2   i   zXpsutil not found, run pip install mypy[dmypy] to install the needed components for dmypymemory_psutil_missing)psutilProcessmemory_inforssr  vmsr6   r   	peak_wsetresource	getrusageRUSAGE_SELF	ru_maxrssImportError)r   r  processmeminfor  rusagefactors          rI   r   r     s   CG ..""%%'' 'c 1 'c 1<7""'.'83'>C#$$ OOO''(<==F|x'''-'7&'@3'FC#$$+  
 
 
9 	#$$$
, Js   C   CCr   rL  r  extraSequence[BuildSource]r,  c                    t          |          }d |D             }|                                 D ]1\  }}||vr(|                    t          |j        |                     2|S )Nc                    h | ]	}|j         
S r   r   ro  s     rI   r  z,find_all_sources_in_build.<locals>.<setcomp>  s    ///fFM///rm   )r   r  r;   r   r   )rL  r  r\  rt  r   r`  s         rI   rK  rK    sl     %[[F/////D ; ;MM+ej&99:::Mrm   r   ra  r  r   c                h    t          |          |                    fd| D                        dS )zAdd all (explicit) sources to the list changed files in place.

    Use this when re-processing of unchanged files is needed (e.g. for
    the purpose of exporting types for inspections).
    c                Z    g | ]'}|j         r|j        |j         fv|j        |j         f(S r   r  )r
  bsr  s     rI   r  z.add_all_sources_to_changed.<locals>.<listcomp>'  sL     	
 	
 	
w	
 Irw/{BB Y BBBrm   N)r  r  )r   ra  r  s     @rI   rk  rk    sV     g,,KNN	
 	
 	
 	
	
 	
 	
    rm   c                *   |                                  D ]}}g }g }|j        |j        z   D ]1}|| v r|                    |           |                    |           2||_        t	          |          |_        ||_        t	          |          |_        ~dS )zAfter an incremental update, update module dependencies to reflect the new state.

    This can make some suppressed dependencies non-suppressed, and vice versa (if modules
    have been added to or removed from the build).
    N)rN  r  
suppressedr;   r  dependencies_setr  )rL  r`  new_suppressednew_dependenciesr  s        rI   r  r  /  s      3 3%(88 	+ 	+Ce|| '',,,,%%c****-!$%5!6!6)">223 3rm   r  r  rV  r   r   r   c                   t                      }|j        |j        z   |j        z   |j        z   }|D ]}	 |                    |          }n# t          $ r g }Y nw xY w|D ]z}|                    d          r|dd         }n?|                    d          r|dd         }n|                    d          r
|dd         }|| v r|                    |           {|S )a  Quickly filter out obviously missing top-level packages.

    Return packages with entries that can't be found removed.

    This is approximate: some packages that aren't actually valid may be
    included. However, all potentially valid packages must be returned.
    z.pyNr  z-stubsi)	r  python_path	mypy_pathpackage_pathtypeshed_pathlistdirr   r  r  )r  rV  r   r  r  r  entriesentrys           rI   r  r  C  s*    EEE 

 	!

#	$ 
$	% 
  ! !	ooa((GG 	 	 	GGG	 	! 	!E ~~e$$ #crc
'' #crc
)) #crc
  		%   	! Ls   A		AAr  )
r&   r   r'   r(   r)   r*   r+   r,   r-   r.   r1  )rK   rL   r+   r,   r-   r.   )rp   rq   rr   rs   r-   r   )r   r(   r-   rs   )r-   r-  )r   )rL  r  r  r  r-   r,  r  )rL  r  r-   r   )r  r  rV  r   r   r   r-   r  )Y__doc__
__future__r   r   r<   r   r   rW   r8   rA   r6   r  r   collections.abcr   r   AbstractSet
contextlibr   r   typingr   r	   r
   typing_extensionsr   r   
mypy.buildr{   mypy.errors	mypy.mainmypy.dmypy_utilr   r   r   mypy.find_sourcesr   r   mypy.fscacher   mypy.fswatcherr   r   mypy.inspectionsr   mypy.ipcr   mypy.modulefinderr   r   r   r   mypy.optionsr   mypy.server.updater   r   mypy.suggestionsr   r   mypy.typestater   	mypy.utilr    r!   mypy.versionr"   r#   __annotations__r   r%   rJ   ri   ro   r   r   tupler(   r   r   r   r   rk   r  r   rK  rk  r  r  r   rm   rI   <module>rC     s
     # " " " " "   				  				      



      8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 7 ' ' ' ' ' ' ' ' ' ' 5 5 5 5 5 5             6 6 6 6 6 6 6 6 6 6 C C C C C C C C ( ( ( ( ( ( 6 6 6 6 6 6 6 6 - - - - - -       ] ] ] ] ] ] ] ] ] ] ] ]             U U U U U U U U @ @ @ @ @ @ @ @ - - - - - - 1 1 1 1 1 1 1 1 $ $ $ $ $ $    <7&&&&&& `d           >+ + + + +\ `dT T T T T !           &+ + + + #38_ , , , ,">2 2 2 2 2!&'G!H  H H H HD D D D D D D DT        < =?        3 3 3 3(# # # # # #rm   