
    i+                       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mZ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)CallableSequenceSet)redirect_stderrredirect_stdout)AnyFinal	TypeAlias)	b64encode)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          |                                           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appendr   decoder&   dwFlagswShowWindow
subprocessPopenCalledProcessError
returncode)r'   r(   r*   r,   commandpickled_optionsinfoes           P/root/projects/qq-shell/venv/lib64/python3.11/site-packages/mypy/dmypy_server.py	daemonizerI   .   s    >4U]^ ,w'7'7'9'9::P)O*D*D*K*K*M*MPPPQQQ 	3NN111222 	5NN333444}}	 WDdKKKK1, 	  	  	 <	 s   C C;*C60C;6C;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/nullr3      a)	bufferingN)r7   stdoutflushstderrosforkwaitpidprintsetsidumaskopenO_RDWRdup2close_exitfileno)rJ   r,   pidnpidstssigdevnullfds           rH   _daemonize_cbrh   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.
        )rh   Serverserve)r'   r(   r*   r,   s       rH   rI   rI   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_dirsrY   	junit_xmlincrementalr7   exitfollow_imports)ro   rq   _r'   s       rH   process_start_optionsr      s    **	d +  JAw  dbccc ![	
 	
 	
 ! MKLLL%@@@=>>>Nrl   modulec                ,    |                      d          S )z=Can we skip looking for newly unsuppressed imports to module?z
encodings.)
startswithr   s    rH   ignore_suppressed_importsr      s    
 \***rl   
_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 )rj   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_managerrV   pathisfileunlinkr   fscacheraise_exceptionsr   fine_grained_incrementalshow_tracebackuse_fine_grained_cachecache_fine_grainedrf   	cache_dirlocal_partial_typesr(   r!   r7   rS   rU   hide_error_codes	formatter)selfr'   r(   r*   s       rH   __init__zServer.__init__   s     ' 0 0 2 2DH!7>>+&& 	#Ik"""&((#' "+/(!%) 	+ *.G&& "
G '+#& (
CJ@XYYrl   dict[str, str]c                n    | j         j        d          d| j         j        d          }| j         j        |dS )Nr   r   r3   )platformpython_version)r'   r   r   )r   
py_versions     rH   _response_metadatazServer._response_metadata   s=    3A6YY9TUV9WYY
 L1ZPPPrl   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)rb   connection_name
TrS   rU   rD   rx   zNo command found in requestzCommand is not a stringzDaemon crashed!
 finalstopr   )$r   rn   r*   r7   rS   rU   r\   r(   jsondumprV   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   rD   serverorig_stdoutorig_stderrfdataresptbr   s
             rH   rk   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-rD   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_Nrx   zUnrecognized command ''>   runcheckrecheckis_ttyterminal_width)getattr	__class__r   dict)r   rD   r   keymethodrets         rH   r   zServer.run_command  s    wd33>@g@@@AA999N)*&&&&&Cc4(((((Jrl   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   r:   r\   r   )r   r   resr   sr   s         rH   
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.)rV   r   r(   r   s    rH   cmd_stopzServer.cmd_stop0  s     		$"###	rl   versionargsSequence[str]export_typesrr   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.rt   Tzmypy-daemon)ru   rv   r   programheaderNrestartzconfiguration changedzmypy version changed )extra_pluginszplugins changedr   rP   outerrstatus)ioStringIOr   r   rz   r{   r|   listr   argparseSUPPRESScompare_stabler   r#   r   managerplugins_snapshotbuildload_pluginserrorsr7   rS   r   r)   r   getvaluecoder   )r   r   r   r   r   r   rU   rS   sourcesr'   r   start_plugins_snapshotr   current_plugins_snapshotr   rG   s                   rH   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   rP   r   N)r   r'   r   r   r)   r   )r   r  r   r   r   r   r   s          rH   	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.
        rx   z7Command 'recheck' is only valid after a 'check' commandc                4    g | ]}|j         	|j         v|S r   r   ).0r   removalss     rH   
<listcomp>z&Server.cmd_recheck.<locals>.<listcomp>  s,    OOOQQVOh8N8Nq8N8N8Nrl   c                L    t           j                            |           d         S )Nr3   )rV   r   splitext)r   s    rH   <lambda>z$Server.cmd_recheck.<locals>.<lambda>  s    bg&6&6q&9&9!&< rl   T)r   reversec                *    h | ]}|j         	|j         S r   r  r	  r   s     rH   	<setcomp>z%Server.cmd_recheck.<locals>.<setcomp>  s!    7777QV777rl   c                    g | ]}|v|	S r   r   )r	  pknowns     rH   r  z&Server.cmd_recheck.<locals>.<listcomp>  s    9991!5..Q...rl   r   rP   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                   @@rH   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           rH   r   zServer.check  s      <4$(L$=$M!( 		S..wOOCC))++ 66wVb6ccEE< F   '''6>RRC#$4!
rl   c                |    | j                                          | j        r| j                                         d S d S N)r   rT   r   flush_cacher   s    rH   r"  zServer.flush_caches  sF    $ 	4%1133333	4 	4rl   r   c                z    | j         r3| j         j        }|                                 |j        |d<   i |_        d S d S )Nstats)r   r   
dump_statsr3  )r   r   r   s      rH   r#  zServer.update_stats  sJ    $ 	/7G   "=CLGMMM		 	rl   c                "    | j         j        dk    S )zAre we following imports?ry   )r'   r   r   s    rH   r  zServer.following_imports  s     |*h66rl   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     rH   	<genexpr>z1Server.initialize_fine_grained.<locals>.<genexpr>  s&      ::!QX::::::rl   rP   r   )st_mtimest_sizehash)update_sources_time
build_timefind_changes_timefg_update_timefiles_changedr   )print_memory_profileF)run_gcr3   c              3      K   | ]	}|d z   V  
dS r8  r   r  s     rH   r9  z1Server.initialize_fine_grained.<locals>.<genexpr>!  &      ::Aq4x::::::rl   ).r   r   r   r  update_sourcesrz   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.memprofilerB  r"   pretty_messages)r   r   r   r   r$  r'  resultrG   outputr   r   r)  original_sources_lent2staterN  changedremovedt3t4rB  __n_notesr   s                           rH   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  rp   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?  r@  rA  )r   r   r  rF  rS  update_changedadd_all_sources_to_changedrT  rK  r  rU  r   r'   data_dirr  r   rX  rI  r  )r   r   r  r   r  r   r$  r`  ra  r'  r)  r^  s               rH   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 	 	
 	
 	
 !(rl   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.Nrg  r  r   c                    h | ]	}|j         
S r   r   r	  sources     rH   r  z?Server.fine_grained_increment_follow_imports.<locals>.<setcomp>r  s    444&444rl   Tfollowedr   c                &    g | ]}|j         v|S r   r   )r	  ro  seens     rH   r  z@Server.fine_grained_increment_follow_imports.<locals>.<listcomp>  s%    SSS6d9R9R9R9R9Rrl   r   r)   r   r.   rp   c                :                         | |fgg d          S )NTrp  )r   )r   r   r   s     rH   refresh_filezBServer.fine_grained_increment_follow_imports.<locals>.refresh_file  s%    '../?d.SSSrl   c                J    g | ] }t          |d          |d         d          !S )r3   r   Trp  )r   )r	  mods     rH   r  z@Server.fine_grained_increment_follow_imports.<locals>.<listcomp>  s/    ```SVSVdCCC```rl   rh  )r?  r@  refresh_suppressed_timefind_added_suppressed_timecleanup_time)r   r)   r   r)   r.   rp   )!r  r   rK  r   r   keysrF  r   rS  r   r'   rk  rU  r  find_reachable_changed_modulesadd_explicitly_newrj  extendr   copyr   direct_importsitemsr   r   depsr   rT  r<   fix_module_depsrJ  r  rX  )r   r   r  r$  rK  r   orig_moduleschanged_pathsr'  r`  	new_filesr)  worklistr   sources2r^  ru  	module_idr_  new_messagesrb  new_unsuppressedr   rc  	to_deletemodule_patht5r   rs  s                              @@rH   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 	 	
 	
 	
 rl   rootsrK  mypy.build.Graphrs  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 r0  r   rn  s     rH   r9  z8Server.find_reachable_changed_modules.<locals>.<genexpr>  s$      99fFM999999rl   NTrp  )r  r   r   r   addr<   r   	ancestorsdependenciesr   rW  )r   r  rK  rs  r  r`  r  r  nxtr_  r  deps               rH   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 	!!rl   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 )Trp  )r   r   )r	  r  rK  s     rH   r  z)Server.direct_imports.<locals>.<listcomp>  s.    ___SE#JOS4@@@___rl   )r  )r   r   rK  r_  s     ` rH   r  zServer.direct_imports  s0     fQi ____EL^____rl   rU  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   rK  s     rH   r  z/Server.find_added_suppressed.<locals>.<setcomp>  s<     
 
 
U""+DV+L+L" """rl   c                F    h | ]}|                     d d          d         S ).r3   r   )split)r	  r   s     rH   r  z/Server.find_added_suppressed.<locals>.<setcomp>&  s+    IIIFLLa((+IIIrl   r  r3   r   T)	fast_path.pyi)r  rM  suppressed_set%filter_out_missing_top_level_packagesr   r   r'   r  find_moduler   r)   r  endswithr<   r  )r   rK  rs  rU  all_suppressedr_  packagesfinderfoundr   top_level_pkgr[  s    `          rH   rT  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-...   rl   r)  c                    |rdnd}|                      |t          |          ||          }d                    d |D                       d|dS )Nr3   r   r   c              3      K   | ]	}|d z   V  
dS r8  r   r  s     rH   r9  z*Server.increment_output.<locals>.<genexpr>C  rE  rl   r   )rZ  rI  r   )r   r)  r   r   r   r   s         rH   r!  zServer.increment_output>  s]     %A''#g,,WWww:::::::2QWXXXrl   	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     rH   r  z*Server.pretty_messages.<locals>.<listcomp>_  s)    EEEq//22EEErl   )
r'   color_outputprettyr   fit_in_terminalerror_summaryr"   format_errorrI  format_success)r   r)  r  r   r   r  	fit_widthsummaryn_errorsre  n_filess   `          rH   rZ  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rl   c                     d |D             }                                  r fd|D             } j                            |           d S )Nc                *    g | ]}|j         	|j         S r0  r  rn  s     rH   r  z)Server.update_sources.<locals>.<listcomp>c  s!    NNNfk6M6M6M6Mrl   c                H    g | ]}j                             |          |S r   )r   r   )r	  r   r   s     rH   r  z)Server.update_sources.<locals>.<listcomp>f  s.    IIIdt|/B/B4/H/HITIIIrl   )r  r   add_watched_paths)r   r   pathss   `  rH   rF  zServer.update_sourcesb  s`    NN7NNN!!## 	JIIIIeIIIE((/////rl   r   c                d    | j                             ||          }|                     ||          S r0  )r   ri  _find_changed)r   r   r  r   r  s        rH   ri  zServer.update_changedi  s1     55ffEE!!'=999rl   c                `    | j                                         }|                     ||          S r0  )r   rS  r  )r   r   r  s      rH   rS  zServer.find_changedo  s+    3355!!'=999rl   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	  ro  r  s     rH   r  z(Server._find_changed.<locals>.<listcomp>w  sE     
 
 
{
  &{m;; ]FK(;;;rl   c                    h | ]	}|j         
S r   r   rn  s     rH   r  z'Server._find_changed.<locals>.<setcomp>~  s    777V6=777rl   c                &    g | ]}|j         v|S r   r   )r	  ro  moduless     rH   r  z(Server._find_changed.<locals>.<listcomp>  s&    ^^^fV]A]A]6A]A]A]rl   c                (    i | ]}|j         |j        S r   r  r  s     rH   
<dictcomp>z(Server._find_changed.<locals>.<dictcomp>  s    @@@Q@@@rl   )r  r   r<   r   r}  )r   r   r  r`  omittedra  ro  r   lastr   r  s     `       @rH   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rl   r`  c                    d | j         D             t          |          |                    fd|D                        d S )Nc                    h | ]	}|j         
S r   r   rn  s     rH   r  z,Server.add_explicitly_new.<locals>.<setcomp>  s    NNNfFMNNNrl   c                l    g | ]0}|j         r'|j        vr|j        |j         fv"|j        |j         f1S r   r  )r	  ro  changed_setprevious_moduless     rH   r  z-Server.add_explicitly_new.<locals>.<listcomp>  s]       ; M)999]FK0CC	 , DCCrl   )r  r  r~  )r   r   r`  r  r  s      @@rH   r}  zServer.add_explicitly_new  st     ON8MNNN'll    %  	
 	
 	
 	
 	
rl   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).rx   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                rH   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.rx   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          rH   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    rH   cmd_hangzServer.cmd_hang  s    
3	rl   r0  )r'   r   r(   r)   r*   r+   r.   r   )r.   r   )r.   r   )rD   r)   r   r   r.   r   )r   r-   r.   r   )r.   r   )r   r)   r   r   r   rr   r   rr   r   r/   r.   r   )
r  r   r   rr   r   rr   r   r/   r.   r   NN)r   rr   r   r/   r   rr   r  r  r   r  r.   r   )
r   r+  r   rr   r   rr   r   r/   r.   r,  )r   r,  r.   r   )r.   rr   )r   r+  r   rr   r   r/   r.   r,  )NNF)
r   r+  r  r  r   r  r  rr   r.   rp   )F)r   r+  r  rr   r.   rp   )
r  r+  rK  r  rs  r  r  r  r.   r  )r   r  rK  r  r.   r+  )rK  r  rs  r  rU  r   r.   r  )
r)  rp   r   r+  r   rr   r   r/   r.   r,  )FN)
r)  rp   r  r/   r   rr   r   r+   r.   rp   )r   r+  r.   r   )r   r+  r  rp   r   rp   r.   r   )r   r+  r.   r   )r   r+  r  r  r.   r   r   r+  r`  r  r.   r   )r   r   FFFFF)r  r)   r  r)   r  r/   r  r/   r  rr   r  rr   r  rr   r  rr   r  rr   r.   r   )r  r)   r  rr   r  r	   r.   r   ) __name__
__module____qualname__r   r   rk   r   r   r   r   r  r*  r   r"  r#  r  r.  r  r   r|  r  rT  r!  rZ  rF  ri  rS  r  r}  r  r  r  r   rl   rH   rj   rj      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     rl   rj   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darwinr3   i   zXpsutil not found, run pip install mypy[dmypy] to install the needed components for dmypymemory_psutil_missing)psutilProcessmemory_inforssr  vmsr7   r   	peak_wsetresource	getrusageRUSAGE_SELF	ru_maxrssImportError)r   r  processmeminfor
  rusagefactors          rH   r   r     s   CG ..""%%'' 'c 1 'c 1<7""'.'83'>C#$$ OOO''(<==F|x'''-'7&'@3'FC#$$+  
 
 
9 	#$$$
, Js   C   CCr   rK  r  extraSequence[BuildSource]r+  c                    t          |          }d |D             }|                                 D ]1\  }}||vr(|                    t          |j        |                     2|S )Nc                    h | ]	}|j         
S r   r   rn  s     rH   r  z,find_all_sources_in_build.<locals>.<setcomp>  s    ///fFM///rl   )r   r  r<   r   r   )rK  r  r[  rs  r   r_  s         rH   rJ  rJ    sl     %[[F/////D ; ;MM+ej&99:::Mrl   r   r`  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     rH   r  z.add_all_sources_to_changed.<locals>.<listcomp>'  sL     	
 	
 	
w	
 Irw/{BB Y BBBrl   N)r  r~  )r   r`  r  s     @rH   rj  rj    sV     g,,KNN	
 	
 	
 	
	
 	
 	
    rl   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)rM  r  
suppressedr<   r  dependencies_setr  )rK  r_  new_suppressednew_dependenciesr  s        rH   r  r  /  s      3 3%(88 	+ 	+Ce|| '',,,,%%c****-!$%5!6!6)">223 3rl   r  r  rU  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  rU  r   r  r  r  entriesentrys           rH   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/   r0  )rJ   rK   r,   r-   r.   r/   )ro   rp   rq   rr   r.   r   )r   r)   r.   rr   )r.   r,  )r   )rK  r  r  r  r.   r+  r  )rK  r  r.   r   )r  r  rU  r   r   r   r.   r  )Y__doc__
__future__r   r   r   r   rV   r9   r@   r7   r  r   collections.abcr   r   r   AbstractSet
contextlibr   r   typingr	   r
   r   r   librt.base64r   
mypy.buildrz   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&   rI   rh   rn   r   r   tupler)   r   r   r   r   rj   r  r   rJ  rj  r  r  r   rl   rH   <module>rB     s     # " " " " "  				  				      



      B B B B B B B B B B 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 6 6 6 " " " " " "             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(# # # # # #rl   