module documentation

Client for mypy daemon mode. This manages a daemon process which keeps useful state in memory rather than having to read it back from disk on each run.

Class AugmentedHelpFormatter Undocumented
Exception BadStatus Exception raised when there is something wrong with the status file.
Function action Decorator to tie an action function to a subparser.
Function check_output Print the output from a check or recheck command.
Function check_status Check if the process is alive.
Function console_entry Undocumented
Function do_check Ask the daemon to check a list of files.
Function do_daemon Serve requests in the foreground.
Function do_hang Hang for 100 seconds, as a debug hack.
Function do_help Print full help (same as dmypy --help).
Function do_inspect Ask daemon to print the type of an expression.
Function do_kill Kill daemon process with SIGKILL.
Function do_recheck Ask the daemon to recheck the previous list of files, with optional modifications.
Function do_restart Restart daemon (it may or may not be running; but not hanging).
Function do_run Do a check, starting (or restarting) the daemon as necessary
Function do_start Start daemon (it must not already be running).
Function do_status Print daemon status.
Function do_stop Stop daemon via a 'stop' request.
Function do_suggest Ask the daemon for a suggested signature.
Function fail Undocumented
Function get_status Read status file and check if the process is alive.
Function is_running Check if the server is running cleanly
Function main The code is top-down.
Function read_status Read status file.
Function request Send a request to the daemon.
Function restart_server Restart daemon (it may or may not be running; but not hanging).
Function show_stats Undocumented
Function start_server Start the server from command arguments and wait for it.
Function wait_for_server Wait until the server is up.
Type Alias ActionFunction Undocumented
Variable check_parser Undocumented
Variable daemon_parser Undocumented
Variable hang_parser Undocumented
Variable help_parser Undocumented
Variable inspect_parser Undocumented
Variable kill_parser Undocumented
Variable p Undocumented
Variable parser Undocumented
Variable recheck_parser Undocumented
Variable restart_parser Undocumented
Variable run_parser Undocumented
Variable start_parser Undocumented
Variable status_parser Undocumented
Variable stop_parser Undocumented
Variable subparsers Undocumented
Variable suggest_parser Undocumented

Decorator to tie an action function to a subparser.

def check_output(response: dict[str, Any], verbose: bool, junit_xml: str|None, perf_stats_file: str|None): (source)

Print the output from a check or recheck command. Call sys.exit() unless the status code is zero.

def check_status(data: dict[str, Any]) -> tuple[int, str]: (source)

Check if the process is alive. Return (pid, connection_name) on success. Raise BadStatus if something's wrong.

def console_entry(): (source)

Undocumented

Ask the daemon to check a list of files.

Serve requests in the foreground.

Hang for 100 seconds, as a debug hack.

Print full help (same as dmypy --help).

Ask daemon to print the type of an expression.

Kill daemon process with SIGKILL.

Ask 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.

Restart 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()).

Do 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.)

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.

Print daemon status. This verifies that it is responsive to requests.

Stop daemon via a 'stop' request.

Ask 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.

def fail(msg: str) -> NoReturn: (source)

Undocumented

def get_status(status_file: str) -> tuple[int, str]: (source)

Read status file and check if the process is alive. Return (pid, connection_name) on success. Raise BadStatus if something's wrong.

def is_running(status_file: str) -> bool: (source)

Check if the server is running cleanly

def main(argv: list[str]): (source)

The code is top-down.

def read_status(status_file: str) -> dict[str, object]: (source)

Read status file. Raise BadStatus if the status file doesn't exist or contains invalid JSON or the JSON is not a dict.

def request(status_file: str, command: str, *, timeout: int|None = None, **kwds: object) -> dict[str, Any]: (source)

Send 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': <message>} if an IPC operation or receive() raised OSError. This covers cases such as connection refused or closed prematurely as well as invalid JSON received.

def restart_server(args: argparse.Namespace, allow_sources: bool = False): (source)

Restart daemon (it may or may not be running; but not hanging).

def show_stats(response: Mapping[str, object]): (source)

Undocumented

def start_server(args: argparse.Namespace, allow_sources: bool = False): (source)

Start the server from command arguments and wait for it.

def wait_for_server(status_file: str, timeout: float = 5.0): (source)

Wait until the server is up. Exit if it doesn't happen within the timeout.

ActionFunction = (source)

Undocumented

Value
Callable[[argparse.Namespace], None]
check_parser = (source)

Undocumented

daemon_parser = (source)

Undocumented

hang_parser = (source)

Undocumented

help_parser = (source)

Undocumented

inspect_parser = (source)

Undocumented

kill_parser = (source)

Undocumented

Undocumented

Undocumented

recheck_parser = (source)

Undocumented

restart_parser = (source)

Undocumented

run_parser = (source)

Undocumented

start_parser = (source)

Undocumented

status_parser = (source)

Undocumented

stop_parser = (source)

Undocumented

subparsers = (source)

Undocumented

suggest_parser = (source)

Undocumented