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ory rather than having to read it back from disk on each run. ) annotationsN)Mapping)AnyCallableNoReturn)alivekill)DEFAULT_STATUS_FILEreceivesend) IPCClient IPCException)RECURSION_LIMIT)check_python_versionget_terminal_widthshould_force_color) __version__c eZdZdfd ZxZS)AugmentedHelpFormatterc *t|d|dd|y)N)progmax_help_position)super__init__)selfrkwargs __class__s W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/dmypy/client.pyrzAugmentedHelpFormatter.__init__ s CdbCFC)rstrrrreturnNone)__name__ __module__ __qualname__r __classcell__)rs@r rrsDDr!rdmypyzClient for mypy daemon mode@)r descriptionfromfile_prefix_charsactionz --status-filez&status file to retrieve daemon details)defaulthelpz-Vz --versionversionz %(prog)s z&Show program's version number and exit)r.r1r0startz Start daemon)r0z --log-fileFILEz#Direct daemon stdout/stderr to FILE)metavartyper0z --timeoutTIMEOUTz$Server shutdown timeout (in seconds)flagsFLAG*z$Regular mypy flags (precede with --))r4nargsr5r0restartz/Restart daemon (stop or kill followed by start)statuszShow daemon statusz-vz --verbose store_truezPrint detailed status)r.r0z--fswatcher-dump-filez0Collect information about the current file statestopz)Stop daemon (asks it politely to go away)r zKill daemon (kills the process)checkz"Check some files (requires daemon))formatter_classr0z-qz--quietz --junit-xmlz!Write junit.xml to the given filez--perf-stats-filez/write performance information to the given filefiles+zFile (or directory) to check)r4r:r0z--export-typeszLStore types of all expressions in a shared location (useful for inspections)runz2Check some files, [re]starting daemon if necessaryARGz.Regular mypy flags and files (precede with --)recheckzRRe-check the previous list of files, with optional modifications (requires daemon)z--updatezGFiles in the run to add or check again (default: all from previous run)z--removezFiles to remove from the runsuggestz>Suggest a signature or show call sites for a specific functionfunctionFUNCTIONz9Function specified as '[package.]module.[class.]function'z--jsonz:Produce json that pyannotate can use to apply a suggestionz --no-errorsz-Only produce suggestions that cause no errorsz--no-anyz/Only produce suggestions that don't contain Anyz --flex-anyzJAllow anys in types if they go above a certain score (scores are from 0-1))r5r0z --callsitesz+Find callsites instead of suggesting a typez --use-fixmeNAMEzCA dummy name to use instead of Any for types that can't be inferredz --max-guesseszBSet the maximum number of types to try for a function (default 64)inspectz+Locate and statically inspect expression(s)locationLOCATIONzLocation specified as path/to/file.py:line:column[:end_line:end_column]. If position is given (i.e. only line and column), this will return all enclosing expressionsz--show INSPECTIONr5)r5attrs definitionzWhat kind of inspection to run)r4r5r/choicesr0countzFIncrease verbosity of the type string representation (can be repeated))r.r/r0z--limitNUMzQReturn at most NUM innermost expressions (if position is given); 0 means no limit)r4r5r/r0z--include-spanz]Prepend each inspection result with the span of corresponding expression (e.g. 1:2:3:4:"int")z--include-kindz^Prepend each inspection result with the kind of corresponding expression (e.g. NameExpr:"int")z--include-object-attrsz4Include attributes of "object" in "attrs" inspectionz --union-attrszgInclude attributes valid for some of possible expression types (by default an intersection is returned)z--force-reloadz?Re-parse and re-type-check file before inspection (may be slow)hangzHang for 100 secondsdaemonzRun daemon in foregroundz--options-datar0ceZdZdZy) BadStatuszException raised when there is something wrong with the status file. For example: - No status file found - Status file malformed - Process whose pid is in the status file does not exist N)r%r&r'__doc__rr!r rVrVsr!rVctdtjttj |}|j stjy |j |y#t$r"}t|jdYd}~yd}~wt$r,tjtjdYywxYw)zThe code is top-down.r)rN)rsyssetrecursionlimitrparser parse_argsr. print_usagerVfailargs Exception traceback print_excexit)argvr`errs r mainrg s!/*   T "D ;;  KK   !       ! HHQK  sA.. C 7B5C  C cdt|tjtjdy)N)filerY)printrZstderrrd)msgs r r_r_#s #CJJHHQKr!cdfd }|S)z3Decorator to tie an action function to a subparser.c,j||S)Nr-) set_defaults)func subparsers r registerzaction..register.sd+ r!)rpActionFunctionr#rsr)rqrrs` r r.r.+s Or!cz t|jtdt |y#t$rYwxYw)a Start daemon (it must not already be running). This is where mypy flags are set from the command line. Setting flags is a bit awkward; you have to use e.g.: dmypy start -- --strict since we don't want to duplicate mypy's huge list of flags. zDaemon is still aliveN) get_status status_filer_rV start_serverr`s r do_startry8s<&4##$ $%    s . ::ct|y)zRestart daemon (it may or may not be running; but not hanging). We first try to stop it politely if it's running. This also sets mypy flags from the command line (see do_start()). N)restart_serverrxs r do_restartr|Ns 4r!cR t|t||y#t$rYwxYw)z?Restart daemon (it may or may not be running; but not hanging).N)do_stoprVrw)r` allow_sourcess r r{r{Xs.  }%    s  &&cddlm}m}||j|}|||j|j |j rtjdt|jy)z8Start the server from command arguments and wait for it.r) daemonizeprocess_start_options)timeoutlog_filerYN) mypy.dmypy_serverrrr7rvrrrZrdwait_for_server)r`rrr start_optionss r rwrwbsPC)$**mDM 0 0$,,QUQ^Q^_  D$$%r!ctj|z}tj|kr# t|}t |t dyt dy#t$rtjdYfwxYw)zTWait until the server is up. Exit if it doesn't happen within the timeout. g?zDaemon startedNz%Timed out waiting for daemon to start)time read_statusrVsleep check_statusrjr_)rvrendtimedatas r rrmso iikG#G ))+  {+D T  01  JJsO  s AA?>A?c t|js t|dtj}t |jdt |j |j}d|vrPtd|dt|dt |jdt |j |j}tj}||z |d<t||j|j|jy) aDo a check, starting (or restarting) the daemon as necessary Restarts the daemon if the running daemon reports that it is required (due to a configuration change, for example). Setting flags is a bit awkward; you have to use e.g.: dmypy run -- --strict a.py b.py ... since we don't want to duplicate mypy's huge list of flags. (The -- is only necessary if flags are specified.) TrrC)r1r` export_typesr;z Restarting: roundtrip_timeN) is_runningrvrwrrequestrr7rrjr{ check_outputverbose junit_xmlperf_stats_filer`t0responset1s r do_runrs d&& 'T. B   ZZ&& HH Xi0123t40    **   B!#bH 4<<9M9MNr!cLt|j}|jr t|t |t |jd|j d}|jsd|vr t|d|vr tdtjddtdy ) zOPrint daemon status. This verifies that it is responsive to requests. r<)fswatcher_dump_filererror:Daemon may be busy processing; if this persists, consider r killzDaemon is up and runningN) rrvr show_statsrrrr_rZrerj)r`r<rs r do_statusrs )) *F ||6 (8P8PZ[H ||w(*8( I#((ST+V[ \] $%r!ct|jdd}d|vr,t|tdtj ddy t dy ) z!Stop daemon via a 'stop' request.r>rrrrrrzDaemon stoppedN)rrvrr_rZrerjr`rs r r~r~sMt'';H(8 I#((ST+V[ \] r!ct|j\}} t|tdy#t$r}t t |Yd}~yd}~wwxYw)z!Kill daemon process with SIGKILL.z Daemon killedN)rurvr rjOSErrorr_r")r`pid_rfs r do_killrsM(( )FC S  o  SXs 1 AAActj}t|jd|j|j}tj}||z |d<t ||j |j|jy)z(Ask the daemon to check a list of files.r?)rArrN) rrrvrArrrrrrs r do_checkrsf Bt'' QUQbQbcH B!#bH 4<<9M9MNr!ctj}|j |j9t|jd|j |j|j}n"t|jd|j }tj}||z |d<t ||j|j|jy)aAsk the daemon to recheck the previous list of files, with optional modifications. If at least one of --remove or --update is given, the server will update the list of files to check accordingly and assume that any other files are unchanged. If none of these flags are given, the server will call stat() on each file last checked to determine its status. Files given in --update ought to exist. Files given in --remove need not exist; if they don't they will be ignored. The lists may be empty but oughtn't contain duplicates or overlap. NOTE: The list of files is lost when the daemon is restarted. NrE)rremoveupdate)rr) rrrrrvrrrrrrs r do_recheckrs B {{$++"9    **;;;;  4++YTEVEVW B!#bH 4<<9M9MNr!c t|jd|j|j|j|j |j |j|j|j }t|dddy)zAsk the daemon for a suggested signature. This just prints whatever the daemon reports as output. For now it may be closer to a list of call sites. rF)rGjson callsites no_errorsno_anyflex_any use_fixme max_guessesFNrrr) rrvrGrrrrrrrrrs r do_suggestrsd  YY....{{..$$ H5D$Or!c t|jd|j|j|j|j |j |j|j|j|j }t|dddy)z.Ask daemon to print the type of an expression.rJ) showrK verbositylimit include_span include_kindinclude_object_attrs union_attrs force_reloadFNr) rrvrrKrrrrrrrrrs r do_inspectrss  YY,,jj&&&&!66$$&& H5D$Or!c :tjdk(rtjdd|vrt|d |d|d|d}}}t jjt jjt jjt jj|r t||r>dd l m }||zj}||d t||rd |ini||d |d |r=|j!di} t#|d5} t%j&| | d d d rt j(|y y #t$rtdt |YBwxYw#1swYIxYw)zkPrint the output from a check or recheck command. Call sys.exit() unless the status code is zero. ntroutrfr<z Response: r)write_junit_xmlrNpython_versionplatformstatsw)osnamesystemr_KeyErrorr"rZstdoutwriteflushrkr mypy.utilr splitlinesboolgetopenrdumprd) rrrrrrf status_codermessages telemetryfs r rr+so ww$ " ( Xg + (%(8BT+SJJSJJJJSJJ8-#I))+ % & I (T8 b  % & Z  LL"- /3 ' $1 IIi # $ 5 + z#h- )*+. $ $sE*2F* F FFc &t|jD]u\}}|dvrEt|dd}t|dkDr|dddt|dz d}t |dd |Ot |dd t |t rd |zn|d wy) N)rrfrrk2(z ... z more characters24z: z%.3fz>10)sorteditemsreprlenrj isinstancefloat)rkeyvalues r rrXsX^^-.\ U 4 4K"%E5zB ":,eCJrM?:JK e, -  sj6NFUNTY$YZ[\r!cFtt|jddy)z&Hang for 100 seconds, as a debug hack.rSrrN)rjrrvrxs r do_hangrds '$""FA 67r!cTddlm}m}|jrvt |jddxt _t _t j j}tj|dtj|d|jrQddl m }tjt!j"|j}|}|j%|}n||j&d }|||j(|j* j-y ) z!Serve requests in the foreground.r)Serverrar) bufferingrY)OptionsFrrN)rrrrrrZrrkfilenordup2 options_data mypy.optionsrpickleloadsbase64 b64decode apply_changesr7rvrserve)r`rrfdr options_dict options_objoptionss r do_daemonrjs@ }}"&t}}cQ"GG SZ ZZ    A A (||F$4$4T5F5F$GH i ++L9' %H 7D$$dll;AACr!c,tjy)z'Print full help (same as dmypy --help).N)r\ print_helprxs r do_helprs r!rc i}t|}||d<tjjxs t |d<t |d<t |\}} t||5}t||d} | st|}t|jdd} |jdd} | rtjj| |jdd} | rtjj| | sddd|S#1swY|SxYw#ttf$r} d t!| icYd} ~ Sd} ~ wwxYw) aSend a request to the daemon. Return the JSON dict with the response. Raise BadStatus if there is something wrong with the status file or if the process whose pid is in the status file has died. Return {'error': } if an IPC operation or receive() raised OSError. This covers cases such as connection refused or closed prematurely as well as invalid JSON received. commandis_ttyterminal_widthFfinalrNrkr)dictrZrisattyrrrur r r rpoprrkrrr") rvr rkwdsrr`rrclientr rrkrfs r rrs- "H :DDOZZ&&(@,>,@DN/1D %GAt# tW % -  E"6?X\\'59:"h5JJ$$V,!h5JJ$$V,  -( O) -( O \ "#S""#s= D(BDDDDDE. E:EEc.t|}t|S)zRead status file and check if the process is alive. Return (pid, connection_name) on success. Raise BadStatus if something's wrong. )rr)rvrs r rurus { #D  r!cd|vr td|d}t|ts tdt|s tdd|vr td|d}t|ts td||fS)z}Check if the process is alive. Return (pid, connection_name) on success. Raise BadStatus if something's wrong. rz"Invalid status file (no pid field)zpid field is not an intzDaemon has diedconnection_namez.Invalid status file (no connection_name field)z%connection_name field is not a string)rVrintrr")rrrs r rrs D<== u+C c3 122 :)**$HII,-O os +?@@  r!c8tjj|s tdt |5} t j |} dddtts td|S#t$r}td|d}~wwxYw#1swYCxYw)zRead status file. Raise BadStatus if the status file doesn't exist or contains invalid JSON or the JSON is not a dict. zNo status file foundz Malformed status file (not JSON)Nz Invalid status file (not a dict)) rpathisfilerVrrloadrarr)rvrres r rrs 77>>+ &.// k Ga G99Q?Q F GGGs(BA33 B < BB  BBc: t|y#t$rYywxYw)z&Check if the server is running cleanlyFT)rurV)rvs r rrs(;  s  c<ttjddy)Nr)rgrZrerr!r console_entryrs!"r!)rez list[str]r#r$)rlr"r#r)rqzargparse.ArgumentParserr#z*Callable[[ActionFunction], ActionFunction])r`argparse.Namespacer#r$)F)r`rrrr#r$)g@)rvr"rrr#r$) rdict[str, Any]rrr str | Nonerr!r#r$)rzMapping[str, object]r#r$) rvr"r r"rz int | Nonerobjectr#r )rvr"r#tuple[int, str])rr r#r#)rvr"r#zdict[str, object])rvr"r#r)r#r$)]rW __future__rargparserrrrrZrrbcollections.abcrtypingrrr mypy.dmypy_osrr mypy.dmypy_utilr r r mypy.ipcr r mypy.mainrrrrr mypy.versionrRawDescriptionHelpFormatterrArgumentParserr\ro add_argumentadd_subparsers subparsers add_parser start_parserpr"rrestart_parser status_parser stop_parser kill_parser check_parserSUPPRESS run_parserrecheck_parsersuggest_parserrinspect_parser hang_parser daemon_parser help_parserrarVrgr_ Namespacersr.ryr|r{rwrrrr~rrrrrrrrrrrrurrrrrr!r rCs  # #**%>>,%RR$ DXAAD ! ;SV 4 07_  + % 1  " " $ ((~(FF q|V#B++"+0:+KQ++\ ,$r!