ML idZddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z GddZddZdd ZGd d eZdd Zdd ZGddZy)zBasic introspection of modules.) annotationsN)Queue get_context) ModuleTypec<eZdZ d ddZy)ModulePropertiesNc`||_||_||_||_||_|xsg|_yNnamefilepathall is_c_module subpackages)selfr r rrrrs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/moduleinspect.py__init__zModuleProperties.__init__s5   &&,")NNNFN)r strr str | Nonerlist[str] | NonerrrboolrrreturnNone)__name__ __module__ __qualname__rrrrrs_!% $!(,--- -  -  -&- -rrc|jjdytjj |jdddvS)N__file__T)z.soz.pydz.dll)__dict__getosrsplitext)modules rrr"sE :&. 77  FOOJ7 8 <@W WWrct|xr6|jdxr#tjj |dd S)Nz.pycr#)rendswithr&rexists)r s r is_pyc_onlyr,*s6 Pv.Prww~~d3Bi7P3P QQrc eZdZy) InspectErrorN)rrrr rrr.r..srr.c tj|}t |d|}t |dd}t |dd}t |tsd}t |dd}| t|}t|}|q|rltj|Dcgc]K\}}tj|r1|j|jdz|zk(r|jdz|zM} }}n@g} n=tj||jdzd} | D cgc]\} } } |  } } } } t!||||| S#t$r}tt ||d}~wwxYw#t$rd}YwxYwcc}}wcc} } } w) zDUse runtime introspection to get information about a module/package.Nrr"__path____all__.cyr r )rs rz(get_package_properties..Usr)prefixonerrorr ) importlib import_module BaseExceptionr.rgetattr isinstancelist Exceptionrinspect getmembersismodulerpkgutil walk_packagesr) package_idpackageer r rpkg_allis_cvalr all_packagesimporterqualified_nameispkgs rget_package_propertiesrN2s*))*5 7J 3D 7J -D$Wj$?D dD !gy$/G 7mG w D |  ")!3!3G!<D###C(S\\W=M=MPS=SVZ=Z-Z  3&-KK,, ))C/ NZZZ*I(NE~Z Z  4W$T_ E *3q6")* G [s6D7 EAE. E47 EEE E+*E+c|t_ |j} t|}|j |.#t$r$}|j t |Yd}~Wd}~wwxYw)z0The main loop of a worker introspection process.N)sysrr%rNr.putr)tasksresultssys_pathmodproprFs rworkerrW]s^CH iik )#.D  D   KKA   s ; A(A##A(cHeZdZdZd dZd dZd dZd dZd dZd dZ ddZ y ) ModuleInspecta9Perform runtime introspection of modules in a separate process. Reuse the process for multiple modules for efficiency. However, if there is an error, retry using a fresh process to avoid cross-contamination of state between modules. We use a separate process to isolate us from many side effects. For example, the import of a module may kill the current process, and we want to recover from that. Always use in a with statement for proper clean-up: with ModuleInspect() as m: p = m.get_package_properties('urllib.parse') c$|jyr )_startrs rrzModuleInspect.__init__zs  rcptjdk(r td}n td}|j|_|j|_|j t|j|j tjf|_ |jjd|_ y)Nlinux forkserverspawn)targetargsr) rPplatformrrrRrSProcessrWrprocstartcounter)rctxs rr[zModuleInspect._start}sx <<7 "l+Cg&C!$ 69iik KKvTZZsxx4XKY   rc8|jjy)zFree any resources used.N)re terminater\s rclosezModuleInspect.closes rc||jj||j}||jt d|t |t rK|jdkDr1|j|j|j|St ||xjdz c_|S)zReturn some properties of a module/package using runtime introspection. Raise InspectError if the target couldn't be imported. zProcess died when importing r) rRrQ_get_from_queuer[r.r<rrgrkrN)rrDress rrNz$ModuleInspect.get_package_propertiess z"""$ ; KKM!=j^LM M c3 ||a  22:>>s# #   rcd}d} ||k(r td |jjdS#tj$r|j j sYyYnwxYw|dz }h)z{Get value from the queue. Return the value read from the queue, or None if the process unexpectedly died. iXrzTimeout waiting for subprocessg?)timeoutNrm) RuntimeErrorrSr%queueEmptyreis_alive)rmax_iterns rrnzModuleInspect._get_from_queues|  H}"#CDD ||'''55;; yy))+,  FAs3-A%$A%c|Sr r r\s r __enter__zModuleInspect.__enter__s rc$|jyr )rk)rrbs r__exit__zModuleInspect.__exit__s  rN)rrrDrrr)rzModuleProperties | str | None)rrY)rbobjectrr) rrr__doc__rr[rkrNrnryr{r rrrYrYjs*  ."rrY)r(rrr)r rrrr|)rRz Queue[str]rSzQueue[str | ModuleProperties]rTz list[str]rr)r~ __future__rr8r?r&rBrsrPmultiprocessingrrtypesrrrr,r>r.rNrWrYr rrrs\%"  .--&XR 9 (V NNr