Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dmypy run on Windows #15429

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,9 @@ def do_daemon(args: argparse.Namespace) -> None:
options = options_obj.apply_changes(options_dict)
else:
options = process_start_options(args.flags, allow_sources=False)
options_dict = options.snapshot()

Server(options, args.status_file, timeout=args.timeout).serve()
Server(options, args.status_file, timeout=args.timeout, options_snapshot=options_dict).serve()


@action(help_parser)
Expand Down
10 changes: 8 additions & 2 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,17 @@ class Server:
# NOTE: the instance is constructed in the parent process but
# serve() is called in the grandchild (by daemonize()).

def __init__(self, options: Options, status_file: str, timeout: int | None = None) -> None:
def __init__(
self,
options: Options,
status_file: str,
timeout: int | None = None,
options_snapshot: dict[str, object] | None = None,
Copy link
Collaborator

@svalentin svalentin Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accepted it since it work, but thinking out loud, it feels like it shouldn't be necessary to pass both options and options_snapshot. One or the other should be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but then we will need something like "stable compare", which will be a tiny bit slower (this is btw the original way I did it). OTOH, then motivation is much more obvious, so let's go that way indeed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svalentin Could you please test again just in case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
Still works:

PS C:\src\mypy-play> python -m mypy.dmypy run .\test.py
Success: no issues found in 1 source file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, I think this is a much more elegant fix

) -> None:
"""Initialize the server with the desired mypy flags."""
self.options = options
# Snapshot the options info before we muck with it, to detect changes
self.options_snapshot = options.snapshot()
self.options_snapshot = options_snapshot or options.snapshot()
self.timeout = timeout
self.fine_grained_manager: FineGrainedBuildManager | None = None

Expand Down
8 changes: 8 additions & 0 deletions mypy/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def __init__(
def __str__(self) -> str:
return f"<ErrorCode {self.code}>"

def __eq__(self, other: object) -> bool:
if not isinstance(other, ErrorCode):
return False
return self.code == other.code

def __hash__(self) -> int:
return hash((self.code,))


ATTR_DEFINED: Final = ErrorCode("attr-defined", "Check that attribute exists", "General")
NAME_DEFINED: Final = ErrorCode("name-defined", "Check that name is defined", "General")
Expand Down
27 changes: 27 additions & 0 deletions test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ Daemon stopped
[file foo.py]
def f(): pass

[case testDaemonRunIgnoreMissingImports]
$ dmypy run -- foo.py --follow-imports=error --ignore-missing-imports
Daemon started
Success: no issues found in 1 source file
$ dmypy stop
Daemon stopped
[file foo.py]
def f(): pass

[case testDaemonRunErrorCodes]
$ dmypy run -- foo.py --follow-imports=error --disable-error-code=type-abstract
Daemon started
Success: no issues found in 1 source file
$ dmypy stop
Daemon stopped
[file foo.py]
def f(): pass

[case testDaemonRunCombinedOptions]
$ dmypy run -- foo.py --follow-imports=error --ignore-missing-imports --disable-error-code=type-abstract
Daemon started
Success: no issues found in 1 source file
$ dmypy stop
Daemon stopped
[file foo.py]
def f(): pass

[case testDaemonIgnoreConfigFiles]
$ dmypy start -- --follow-imports=error
Daemon started
Expand Down