
    %^g@                       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
mZmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlm Z  ddl!m"Z" ddl#m$Z$  G d d      Z%ee&e'f   Z(ee(   Z)ee&eee*e*f   eee*e*f      f   f   Z+de,d<   ddgZ-de,d<   e G d de             Z.ee&e.f   Z/ G d d      Z0 G d d      Z1 G d d      Z2	 	 	 	 	 	 	 	 	 	 d*dZ3d+dZ4d,d Z5d-d!Z6d.d"Z7	 	 	 	 	 	 	 	 d/d#Z8 ejr                  d$      d0d%       Z:	 d1	 	 	 	 	 	 	 	 	 d2d&Z;d3d'Z<d4d(Z=d5d)Z>y)6zmLow-level infrastructure to find modules.

This builds on fscache.py; find_sources.py builds on top of this.
    )annotationsN)Enumunique)DictFinalListOptionalTupleUnion)	TypeAlias)pyinfo)CompileError)FileSystemCache)MypyFile)Options)stub_distribution_name)os_path_joinc                  0    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZddZy)SearchPathsc                   t        t        t        j                  j                  |            | _        t        t        t        j                  j                  |            | _        t        t        t        j                  j                  |            | _        t        t        t        j                  j                  |            | _        y N)	tuplemapospathabspathpython_path	mypy_pathpackage_pathtypeshed_path)selfr   r   r   r    s        1lib/python3.12/site-packages/mypy/modulefinder.py__init__zSearchPaths.__init__   ss     !RWW__k!BCs277??I>?!#bggoo|"DE"3rww#FG    c                `    | j                   | j                  | j                  | j                  dS )Nr   r   r   r    r&   r!   s    r"   asdictzSearchPaths.asdict.   s.    ++ --!//	
 	
r$   N)
r   tuple[str, ...]r   r)   r   r)   r    r)   returnNone)r*   zdict[str, tuple[str, ...]])__name__
__module____qualname__r#   r(    r$   r"   r   r      sB    H$H #H &	H
 'H 
H 
r$   r   
_TypeAliasStdlibVersionsz.pyi.pyr   PYTHON_EXTENSIONSc                  $    e Zd ZdZdZdZdZddZy)ModuleNotFoundReasonr            c                *   d}| t         j                  u r	d}|g}||fS | t         j                  u r	d}dg}||fS | t         j                  u r	d}|g}||fS | t         j                  u r-d}dg}|s|j                  d       |j                  |       ||fS J )NzKSee https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-importszFCannot find implementation or library stub for module named "{module}"zOYou may be running mypy in a subpackage, mypy should be run on the package rootz`Skipping analyzing "{module}": module is installed, but missing library stubs or py.typed markerz*Library stubs not installed for "{module}"z*Hint: "python3 -m pip install {stub_dist}"zD(or run "mypy --install-types" to install all missing stub packages))r5   	NOT_FOUNDWRONG_WORKING_DIRECTORYFOUND_WITHOUT_TYPE_HINTSAPPROVED_STUBS_NOT_INSTALLEDappend)r!   daemondoc_linkmsgnotess        r"   error_message_templatesz,ModuleNotFoundReason.error_message_templatesW   s    `'111ZCJE, Ez+ )AAAZCaE& Ez! )BBB%  JE Ez )FFF>CABEZ LL" Ez 5r$   N)r?   boolr*   ztuple[str, list[str]])r,   r-   r.   r:   r<   r;   r=   rC   r/   r$   r"   r5   r5   D   s&     I  !   $% r$   r5   c                  >    e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZy)BuildSourcezA single source file.Nc                R    || _         |xs d| _        || _        || _        || _        y )N__main__)r   moduletextbase_dirfollowed)r!   r   rI   rJ   rK   rL   s         r"   r#   zBuildSource.__init__|   s,     	*
	  r$   c                    dj                  | j                  | j                  | j                  d u| j                  | j
                        S )NzLBuildSource(path={!r}, module={!r}, has_text={}, base_dir={!r}, followed={}))formatr   rI   rJ   rK   rL   r'   s    r"   __repr__zBuildSource.__repr__   s9    Zaa		4;;		(=t}}dmm	
r$   )NNF)r   
str | NonerI   rP   rJ   rP   rK   rP   rL   rD   r*   r+   )r*   str)r,   r-   r.   __doc__r#   rO   r/   r$   r"   rF   rF   y   sT      #!! ! 	!
 ! ! 
!
r$   rF   c                       e Zd ZdZddZddZy)BuildSourceSetzIHelper to efficiently test a file's membership in a set of build sources.c                <   d| _         i | _        t               | _        |D ]z  }|j                  d| _         |j
                  r%| j                  j                  |j
                         |j                  sT|j
                  xs d| j                  |j                  <   | y )NFT )source_text_presentsource_modulessetsource_pathsrJ   r   addrI   )r!   sourcessources      r"   r#   zBuildSourceSet.__init__   s{    #( .0&)eF{{&+/({{!!%%fkk2}}5;[[5FB##FMM2 r$   c                    |j                   xr |j                   | j                  v xs& |j                  | j                  v xs | j                  S r   )r   rZ   	_fullnamerX   rW   )r!   files     r"   	is_sourcezBuildSourceSet.is_source   sG    YY9499(9(99 (~~!4!44(''	
r$   N)r\   list[BuildSource]r*   r+   )r`   r   r*   rD   )r,   r-   r.   rR   r#   ra   r/   r$   r"   rT   rT      s    SG
r$   rT   c                      e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZddZdd	dd
Z	ddZ
	 	 	 	 	 	 ddZddZddZddZddZy)FindModuleCacheaK  Module finder with integrated cache.

    Module locations and some intermediate results are cached internally
    and can be cleared with the clear() method.

    All file system accesses are performed through a FileSystemCache,
    which is not ever cleared by this class. If necessary it must be
    cleared by client code.
    Nc                    || _         || _        |xs
 t               | _        i | _        i | _        i | _        || _        d }|r|j                  }|xs t        |      | _
        y r   )search_paths
source_setr   fscacheinitial_componentsresultsns_ancestorsoptionscustom_typeshed_dirload_stdlib_py_versionsstdlib_py_versions)r!   rf   rh   rl   ro   rg   rm   s          r"   r#   zFindModuleCache.__init__   sq     )$3/"3 PR68,."")"="="4 #
8O9
r$   c                    | j                   j                          | j                  j                          | j                  j                          y r   )rj   clearri   rk   r'   s    r"   rq   zFindModuleCache.clear   s6    %%'!r$   c                     j                   sy j                   j                  j                  |d      }|r j                  j	                  |      rzt
        j                  j                  |      t        |j                  d            D ]<  }t         fdt        D              s yt
        j                  j                        > |S |j                  d      }|dk7  r j                  |d|       t        t              syt
        j                  j!                        \  }}t        fdt        D              s3|t        v r+ j                  j#                  |      st$        j&                  S y)zFast path to find modules by looking through the input sources

        This is only used when --fast-module-lookup is passed on the command line.N.c              3  n   K   | ],  }j                   j                  t        d |z                . ywr#   N)rh   isfiler   ).0xdr!   s     r"   	<genexpr>z=FindModuleCache.find_module_via_source_set.<locals>.<genexpr>   s0      RcQDLL''Q
Q(GHRcs   25c              3  F   K   | ]  }j                  d |z           ywru   )endswith)rw   rx   parents     r"   rz   z=FindModuleCache.find_module_via_source_set.<locals>.<genexpr>   s!     R@Q1vzA~6@Qs   !)rg   rX   getrh   rv   r   r   dirnamerangecountanyr3   rfindfind_module_via_source_set
isinstancerQ   splitextisdirr5   r:   )	r!   idp_idxbasenameextry   r~   s	   `      @@r"   r   z*FindModuleCache.find_module_via_source_set   s,    OO**..r48$$Q'
 "A288C=) Rc   GGOOA& * Hhhsm"9 44RX>F~Z%<GG,,V4MHcR@QRR((1C1CH1M ,555r$   c                $   |j                  d      }t        j                  j                  |dd       }g }| j	                  ||d         D ]B  }|rt        ||      }n|}| j                  j                  |      s0|j                  |df       D |S )zMFind which elements of a lib_path have the directory a module needs to exist.rs   Nr{   r   T)	splitr   sepjoinget_toplevel_possibilitiesr   rh   r   r>   )r!   r   lib_path
components	dir_chaindirspathitemdirs           r"   find_lib_path_dirsz"FindModuleCache.find_lib_path_dirs  s    XXc]
FFKK
3B0	77*Q-PH"8Y7||!!#&S$K( Q r$   c                   || j                   v r| j                   |   j                  |g       S i }|D ]h  }	 | j                  j                  |      }|D ]E  }t
        j                  j                  |      d   }|j                  |g       j                  |       G j || j                   |<   |j                  |g       S # t        $ r g }Y zw xY w)a  Find which elements of lib_path could contain a particular top-level module.

        In practice, almost all modules can be routed to the correct entry in
        lib_path by looking at just the first component of the module name.

        We take advantage of this by enumerating the contents of all of the
        directories on the lib_path and building a map of which entries in
        the lib_path could contain each potential top-level module that appears.
        r   )
ri   r   rh   listdirOSErrorr   r   r   
setdefaultr>   )r!   r   r   r   r   contentsnames          r"   r   z*FindModuleCache.get_toplevel_possibilities  s     t...**8488R@@ ,.
C<<//4 !ww''-a0%%dB/66s; !  -7)~~b"%%  s   B>>CCF	fast_pathc                  || j                   vr|j                  d      d   }d}|| j                  v r| j                  |      }n|| j                  v r| j                  |      }| j	                  ||      | j                   |<   |so| j
                  | j
                  j                  sM| j                   |   t        j                  u r.| j                  |      rt        j                  | j                   |<   | j                   |   S )zReturn the path of the module source file or why it wasn't found.

        If fast_path is True, prioritize performance over generating detailed
        error descriptions.
        rs   r   T)rj   	partitionro   _typeshed_has_version_find_modulerl   fast_module_lookupr5   r:   _can_find_module_in_parent_dirr;   )r!   r   r   	top_leveluse_typesheds        r"   find_modulezFindModuleCache.find_module3  s     T\\!S)!,ILT,,,#99"=d555#99)D#00\BDLL4<<#;@_@_LL$(<(F(FF77;#7#O#OR ||Br$   c                    | j                   syt        | j                         }| j                  |   \  }}||k\  xr |d u xs ||k  S )NT)rl   typeshed_py_versionro   )r!   rI   versionmin_versionmax_versions        r"   r   z%FindModuleCache._typeshed_has_versionI  sN    ||%dll3#'#:#:6#B [+%Y;$+>+X'[BXYr$   c                   d}|}|j                  d      }t        |      D ]  \  }}t        ||      }| j                  j	                  t        |d            r*t        j                  j                  |g|d d  |dk(  fc S |s;| j                  j                  |      s| j                  j	                  |dz         rd}| j                  j                  |      r n |rh| j                  rL| j                  j                  |      }|j                  r%t        j                  j                  |g|d d  dfS t        j                  S t        j                  S )NFrs   py.typedr{   r   r2   T)r   	enumerater   rh   rv   r   r   r   r   rl   clone_for_modulefollow_untyped_importsr5   r<   r:   )	r!   r   pkg_dirplausible_matchdir_pathr   index	componentmodule_specific_optionss	            r"   _find_module_non_stub_helperz,FindModuleCache._find_module_non_stub_helperP  s%     XXc]
 )* 5E9#Hi8H||""<*#EFww||G>j"o>
JJ$""8,0C0CHuDT0U"&<<%%h/ !6 ||*.,,*G*G*K'*AA77<<B*Sb/BEII'@@@'111r$   c                   |\  }}t        dt        |            D ]n  }dj                  |d |        }|| j                  vr*| j                  j                  |      r|| j                  |<   t        j                  j                  |      }p y )Nr6   rs   )	r   lenr   rk   rh   r   r   r   r   )r!   r   matchr   verifyipkg_ids          r"   _update_ns_ancestorsz$FindModuleCache._update_ns_ancestorsj  sw    fq#j/*AXXj1"o.FT...4<<3E3Ed3K,0!!&)77??4(D	 +r$   c                   t        j                         }t        t        dddd      | j                  | j
                  | j                        }t        d t        j                  |      D              rzt         j                  j                  |      }t        |fddd      |_        t        |j                  |d      t              syt        d t        j                  |      D              rzy)zsTest if a module can be found by checking the parent directories
        of the current working directory.
        r/   )ro   c              3  2   K   | ]  }t        |        y wr   )is_init_file)rw   r`   s     r"   rz   zAFindModuleCache._can_find_module_in_parent_dir.<locals>.<genexpr>}  s     I1H,t$1Hs   FT)r   getcwdrd   r   rh   rl   ro   r   r   r   r   rf   r   r   r5   )r!   r   working_dirparent_searchs       r"   r   z.FindModuleCache._can_find_module_in_parent_dirr  s     iik'BB'LLLL#66	
 IK1HII''//+6K)4k^RR)PM&m88UCEYZ	 IK1HII
 r$   c           
     \   | j                   }| j                  '| j                  j                  r| j                  |      nd }|r|S |j	                  d      }t
        j                  j                  |d d       }g }g }d}	|d   |d   dz   fD 
ch c]2  }
| j                  |
| j                  j                        D ]  }|d   	 4 }}
}| j                  j                  D ]n  }||vr	|d   dz   }t        ||      }|j                  |      rt        |d      }|g|dd  z   }t        j                  j                  |g|d d  }|j                  |      r|j                  |      rw|j                  |      j!                         j#                         dk(  r3t        ||      }|j%                  |d	f       |j%                  |df       n'|j%                  |d	f       n|j%                  |d	f       | j'                  ||      }t)        |t*              r|t*        j,                  u sHd	}	L|j%                  |       | j/                  ||       q | j                  r8| j                  j0                  r"|j3                          |j3                          d}	| j                  j4                  | j                  j6                  z   }| j                  ||      }|r)|| j                  || j                  j8                        z  }|||z   z  }t
        j                  |d   z   }t
        j                  d
z   }g }|D ]  \  }}||z   }d}|}t;        t=        |      dz
        D ]!  }t
        j                  j?                  |      }# t@        D ]  } ||z   | z   }|dz   |z   | z   }!|jC                  ||      r,d	}|r"tE        ||||      s|j%                  ||f       N|c c S |jC                  |!|      sg|r"tE        |||!|      s|j%                  |!|f       |!c c S  | j                  rO| j                  jF                  r9|s7|jI                  ||      r%|jC                  ||      s|j%                  ||f       t@        D ]C  } || z   }|jC                  ||      s|r"tE        ||||      s|j%                  ||f       ?|c c S   | j                  rZ| j                  jF                  rD|rB|D cg c]  \  }}tK        ||||       }"}}|"jM                  tO        |"            }#||#   d   S | jP                  jS                  |      }$|$|$S tU        |      }%|%rt=        |      dk(  rt*        jV                  S t;        dt=        |            D ]&  }&dj                  |d |&       }'tU        |'      |%k(  s& n t*        jV                  S | jY                  |'      t*        jV                  u rt*        jV                  S t*        jZ                  S |	rt*        j,                  S t*        jZ                  S c c}}
w c c}}w )Nrs   r{   Fr   z-stubsr   r6   partialTr#   ).rh   rl   r   r   r   r   r   r   r   rf   r   r   r   r   rv   readdecodestripr>   r   r   r5   r<   r   use_builtins_fixturesrq   r   r   r    r   r   r   r3   isfile_caseverify_modulenamespace_packagesexists_casehighest_init_levelr   maxrk   r   r   r=   r   r:   )(r!   r   r   rh   r   r   r   third_party_inline_dirsthird_party_stubs_dirs-found_possible_third_party_missing_type_hintsr   package_dircandidate_package_dirsr   	stub_namestub_dirstub_typed_filestub_componentsr   runtime_pathnon_stub_matchpython_mypy_pathcandidate_base_dirsseplastsepinitnear_missesrK   r   	base_pathhas_init
dir_prefixr   	extension
path_stubslevelsr   ancestorapproved_dist_namer   	parent_ids(                                           r"   r   zFindModuleCache._find_module  s   ,,> (T\\-L-L ++B/ 	

 H XXc]
FFKK
3B0	 02.08=5 )mZ]X-EF"
F	#66y$BSBSB`B`a Na F 	 "

 ((55G44"10I#GY7H}}X&".x"D#,+
12">ww||GCocr.BC==&~~o6
 #<<8??AGGIYV+7+KL3::L$;OP 3994-H 3994,G.55tTlC!>>r7KN.*>?!%9%R%RRDHA'..~>))*nEC 6F <<DLL>>#))+"((*<A9,,669J9J9V9VV"55b:JK  4#:#:2t?P?P?^?^#__58OOO &&:b>)&&:% 3Hf 7*IH!J3z?Q./WW__Z8
 0 /	 7*Y6&1G;iG
&&tZ8#HmGRz&R#**D*+=> K((Z@mGRZ&X#**J
+CD %% /  || ? ? ++IzB#//	:F&&	:'>? /	 9,&&tZ8mGRz&R#**D*+=> K /A !4z <<DLL;; )4(3$D* #7BjA(3   LLV-Eu%a(( $$((,O3B7:!#+HHH 1c*o.HHZ^4	))48JJ /
 ,HHH	*.B._.__+HHH'1118'@@@#---y"
vs   7X"*X(c                   | j                  |d      }t        |t              rg S t        ||d       g}d }t	        |      r t
        j                  j                  |      }n| j                  j                  |      r|}||S t               }t        | j                  j                  |            }|D ]  }|dv s|j                  d      rt        ||      }| j                  rDt!        || j                  j"                  | j                  | j                  j$                  dk\        rv| j                  j                  |      r| j                  r| j                  j&                  sK| j                  j)                  t        |d            s&| j                  j)                  t        |d            s|j+                  |       |j-                  | j/                  |dz   |z                7t
        j                  j1                  |      \  }	}
|	dk(  r`|	|vsfd|	vsl|
t2        v sv|j+                  |	       |j-                  | j/                  |dz   |	z                 |S )	NTr   )__pycache__zsite-packagesnode_modulesrs   r7   __init__.py__init__.pyir#   )r   r   r5   rF   r   r   r   r   rh   r   rY   sortedr   
startswithr   rl   matches_excludeexclude	verbosityr   rv   r[   extendfind_modules_recursiver   r3   )r!   rI   module_pathr\   r   seennamesr   subpathstemsuffixs              r"   r   z&FindModuleCache.find_modules_recursiveU  s   &&v&>k#78I{FD9:$77??;7L\\,&LN t||++L9:DGG4??[^K_"<6G||--t||T\\=S=SWX=X! ||!!'*LLT\\%D%DLL''Wm(LM||**<+PQHHTNNN4#>#>v|d?R#ST!ww//5f:%t#4FFW<W HHTNNN4#>#>v|d?R#ST7 8 r$   )NN)rf   r   rh   zFileSystemCache | Nonerl   zOptions | Nonero   zStdlibVersions | Nonerg   zBuildSourceSet | Noner*   r+   )r*   r+   )r   rQ   r*   zModuleSearchResult | None)r   rQ   r   r)   r*   PackageDirs)r   r)   r   rQ   r*   	list[str])r   rQ   r   rD   r*   ModuleSearchResult)rI   rQ   r*   rD   )r   rQ   r   rQ   r*   z$OnePackageDir | ModuleNotFoundReason)r   r  r   ztuple[str, bool]r*   r+   )r   rQ   r*   rD   )r   rQ   r   rD   r*   r  )rI   rQ   r*   rb   )r,   r-   r.   rR   r#   rq   r   r   r   r   r   r   r   r   r   r   r/   r$   r"   rd   rd      s     59,0
!
 (
  	

 2
 *
 

2"
/b &> 9>  ,Z22 #2	-24)$O.b1r$   rd   c                6   |syt         j                  j                  |       j                  t         j                  d      }|j                  |       r|dz  }|D ]>  }t        j                  ||      s|r"t        d| d| dt        j                          y y)NF/zTRACE: Excluding z (matches pattern )r`   T)r   r   relpathreplacer   r   researchprintsysstderr)r   excludesrh   verbosesubpath_strr   s         r"   r   r     s     ''//'*222663?K}}Ws99Wk*'}4FwiqQX[XbXb   r$   c                D    t         j                  j                  |       dv S )N)r   r   )r   r   r   )r   s    r"   r   r     s    77D!%DDDr$   c                    t              rt        j                  j                        t	        |j                  d            D ]=  }t        j                  j                        t         fdt        D              r= y y)z;Check that all packages containing id have a __init__ file.rs   c              3  \   K   | ]#  }j                  t        d |              % ywru   r   r   rw   r   rh   r   prefixs     r"   rz   z verify_module.<locals>.<genexpr>  s4      
.	 TXi[3I JFS.   ),FTr   r   r   r   r   r   r   r3   )rh   r   r   r  r   s   ` `` r"   r   r     se    Dwwt$288C=!wwt$ 
.
 
  " r$   c                     t              rt        j                  j                        d}t	        |j                  d            D ]A  }t        j                  j                        t         fdt        D              s=|dz   }C |S )z:Compute the highest level where an __init__ file is found.r   rs   c              3  \   K   | ]#  }j                  t        d |              % ywru   r  r  s     r"   rz   z%highest_init_level.<locals>.<genexpr>  s4      
.	 TXi[3I JFS.r  r6   r  )rh   r   r   r  levelr   s   ` ``  r"   r   r     sr    Dwwt$E288C=!wwt$ 
.
 
 EE " Lr$   c                 r    t        j                  d      } | sg S | j                  t         j                        S )NMYPYPATH)r   getenvr   pathsep)path_envs    r"   r   r     s+    yy$H	>>"**%%r$   c                \   t         j                  j                  |       } g }|rt         j                  j                  |      }t         j                  j                  |d      }t         j                  j                  |dd      }t         j                  j                  |d      }t         j                  j	                  |      rt         j                  j                  |      st        dj                  |             t        j                  d       nt         j                  j                  | d      }t         j                  j	                  |      r|} t         j                  j                  | dd      }t         j                  j                  | ddd      }|j                  |       |j                  |       t        j                  d	k7  r|j                  d
       |sNt        dj                  t        j                  |       t        j                         t        j                  d       |S )zJReturn default standard library search paths. Guaranteed to be normalised.stdlibstubszmypy-extensionsVERSIONSzDerror: --custom-typeshed-dir does not point to a valid typeshed ({})r7   z
stubs-autotypeshedwin32z/usr/local/lib/mypyz~Could not resolve typeshed subdirectories. Your mypy install is broken.
Python executable is located at {}.
Mypy located at {}r  r6   )r   r   r   r   r   rv   r  rN   r  exitr>   platform
executabler  )data_dir	pyversionrm   r   typeshed_dirmypy_extensions_dirversions_fileautos           r"   default_lib_pathr1    s   
 wwx(HD ggoo.ABww||$7B ggll+>IZ[\:>ww}}\*"''..2OV]]'
 HHQKww||Hl377==Hww||Hj(C ggll8ZJ[\KK 	KK#$ ||w)*FFLfG 	
 	Kr$   )maxsizec                   | g g fS | t         j                  k(  rt        j                         \  }}||fS i t	        t
        j                        ddi}	 t        j                  t        j                  | t        j                  dg|t        j                        j                               \  }}||fS # t        j                  $ r0}t        |j                          t        |j"                          d}~wt$        $ rE}|j&                  J t        j(                  |j&                        }t+        d|  d| g      |d}~ww xY w)a  Find package directories for given python. Guaranteed to return absolute paths.

    This runs a subprocess call, which generates a list of the directories in sys.path.
    To avoid repeatedly calling a subprocess (which can be slow!) we
    lru_cache the results.
    NPYTHONSAFEPATH1getsearchdirs)envr  z!mypy: Invalid python executable 'z': )r  r*  r   r6  dictr   environastliteral_eval
subprocesscheck_output__file__PIPEr   CalledProcessErrorr  r  stdoutr   errnostrerrorr   )python_executablesys_pathsite_packagesr7  errreasons         r"   get_search_dirsrI    s5     Bx	cnn	,"("6"6"8-. ]""' :bjj!9#3S9	&)&6&6''&I%?? &('#Hm" ]"" ,, 	#**#** 	99((([[+F45F4Gs6(ST	s&   AB4 4E+C22E>A D>>Ec                "   t        j                  t        ||j                  |j                              }|j
                  rt        j                  dd      }|s@t        j                  j                  t        j                  j                  t                    }t        j                  j                  |      }|j                  t        j                  j                  |ddd             g }|so| D ]1  }|j                  s|j                  }||vs!|j                  |       3 |j                   rd}nt        j"                         }||vr|j%                  d|       t'               }	|	j)                  |j&                         |r|	j%                  d|       t+        |j,                        \  }
}|D ]  |vsJ |	v sDt/        fd	|	D              s0t        j                  j0                  s<t/        fd
|	D              sQt3         dt4        j6                         t3        dt4        j6                         t5        j8                  d        t;        t=        t?        |            t=        |	      t=        |
|z         t=        |            S )a/  Compute the search paths as specified in PEP 561.

    There are the following 4 members created:
    - User code (from `sources`)
    - MYPYPATH (set either via config or environment variable)
    - installed package directories (which will later be split into stub-only and inline)
    - typeshed
    )rm   MYPY_TEST_PREFIXNz	test-dataunitzlib-stubrs   r   c              3  v   K   | ]0  }|j                  t        j                  j                  z          2 y wr   )r   r   r   r   rw   r   sites     r"   rz   z'compute_search_paths.<locals>.<genexpr>^  s(     FX1<<rww{{ 23X   69c              3  v   K   | ]0  }|j                  t        j                  j                  z          2 y wr   )r   r   r   altseprN  s     r"   rz   z'compute_search_paths.<locals>.<genexpr>_  s*     &]T\qq||D277>>4I'JT\rP  z& is in the MYPYPATH. Please remove it.r  zbSee https://mypy.readthedocs.io/en/stable/running_mypy.html#how-mypy-handles-imports for more infor6   r&   ) collectionsdequer1  python_versionrm   r   r   r  r   r   r>  r   
appendleftr   rK   r>   bazelr   insertr   r   rI  rD  r   rR  r  r  r  r(  r   r   reversed)r\   rl   r+  alt_lib_pathr   root_dirr   r]   r   mypypathrE  rF  rO  s               @r"   compute_search_pathsr]    s      g,,'B]B]	
H $$
 99/6wwrwwx'@AH77??8,BGGLL;
ST  KFook)&&s+  ==C))+Chq#& {H OOG%%& <(-g.G.GHHm8###HFXFF3&]T\&]#]TF@A

S:ZZ
 HHQK  (;/0/8m34Ho	 r$   c                n   | xs- t        t        j                  j                  t              d      }t        |d      }i }t        |d      }t        j                  j                  |      sJ | |t        f       t        |      5 }|D ]  }|j                  d      d   j                         }|dk(  r+|j                  d      \  }}|j                  d      }	t        |	d         }
t        |	      d	k\  r!|	d
   j                         rt        |	d
         nd}|
|f||<    	 ddd       |S # 1 sw Y   |S xY w)zReturn dict with minimum and maximum Python versions of stdlib modules.

    The contents look like
    {..., 'secrets': ((3, 6), None), 'symbol': ((2, 7), (3, 9)), ...}

    None means there is no maximum version.
    r&  r#  r%  #r   rV   :-r7   r6   N)r   r   r   r   r>  rv   openr   r   parse_versionr   )rm   r-  
stdlib_dirresultversions_pathflinerI   version_rangeversionsr   r   s               r"   rn   rn   q  s#    '],rwwx7PR\*]LlH5JF Z8M77>>-(X+>x*XX(	m	D::c?1%++-Drz$(JJsO!FM$**3/H'4K.1(mq.@Xa[EVEVEXhqk*^b  )+5F6N  
 M 
 Ms   BD**D4c                r    | j                         j                  d      \  }}t        |      t        |      fS )Nrs   )r   r   int)r   majorminors      r"   rc  rc    s/    ==?((-LE5u:s5z!!r$   c                .    t        | j                  d      S )zIReturn Python version used for checking whether module supports typeshed.)r8      )r   rU  )rl   s    r"   r   r     s     w%%v..r$   )
r   rQ   r  r  rh   r   r  rD   r*   rD   )r   rQ   r*   rD   )
rh   r   r   rQ   r   rQ   r  rQ   r*   rD   )
rh   r   r   rQ   r   rQ   r  rQ   r*   rl  )r*   r  )r+  rQ   r,  tuple[int, int]rm   rP   r*   r  )rD  rP   r*   ztuple[list[str], list[str]]r   )
r\   rb   rl   r   r+  rQ   rZ  rP   r*   r   )rm   rP   r*   r1   )r   rQ   r*   rq  )rl   r   r*   rq  )?rR   
__future__r   r:  rS  	functoolsr   r
  r<  r  enumr   r   typingr   r   r   r	   r
   r   typing_extensionsr   r0   mypyr   mypy.errorsr   mypy.fscacher   
mypy.nodesr   mypy.optionsr   mypy.stubinfor   	mypy.utilr   r   rQ   rD   OnePackageDirr  rl  r1   __annotations__r3   r5   r  rF   rT   rd   r   r   r   r   r   r1  	lru_cacherI  r]  rn   rc  r   r/   r$   r"   <module>r     s  
 # 
   	 	  
  < < 5  $ (    0 "
 
6 c4i =! "#uU38_huSRUX>W-W'X"XY
 Y"E? 5 * ,4 , ,b 3 445 
 
2
 
0\ \~%0?JN	$E&,,-,DN,,^ T"## ###N ]aUU)0U<?UOYUUp:"
/r$   