8000 Flush error messages incrementally after processing a file by msullivan · Pull Request #4396 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Flush error messages incrementally after processing a file #4396

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

Merged
merged 15 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Perform various cleanups
  • Loading branch information
msullivan committed Jan 9, 2018
commit cc64198041dcd6698535522c33f08a79b360d9da
10 changes: 5 additions & 5 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import time
from os.path import dirname, basename
import errno
from functools import wraps

from typing import (AbstractSet, Any, cast, Dict, Iterable, Iterator, List,
Mapping, NamedTuple, Optional, Set, Tuple, Union, Callable)
Expand Down Expand Up @@ -174,6 +173,10 @@ def default_flush_errors(new_messages: List[str], is_serious: bool) -> None:
result.errors = messages
return result
except CompileError as e:
# CompileErrors raised from an errors object carry all of the
# messages that have not been reported out by error streaming.
# Patch it up to contain either none or all none of the messages,
# depending on whether we are flushing errors.
serious = not e.use_stdout
flush_errors(e.messages, serious)
e.messages = messages
Expand Down Expand Up @@ -743,9 +746,6 @@ def add_stats(self, **kwds: Any) -> None:
def stats_summary(self) -> Mapping[str, object]:
return self.stats

def error_flush(self, msgs: List[str], serious: bool=False) -> None:
self.flush_errors(msgs, serious)


def remove_cwd_prefix_from_path(p: str) -> str:
"""Remove current working directory prefix from p, if present.
Expand Down Expand Up @@ -2535,7 +2535,7 @@ def process_stale_scc(graph: Graph, scc: List[str], manager: BuildManager) -> No
for id in stale:
graph[id].finish_passes()
graph[id].generate_unused_ignore_notes()
manager.error_flush(manager.errors.file_messages(graph[id].xpath))
manager.flush_errors(manager.errors.file_messages(graph[id].xpath), False)
graph[id].write_cache()
graph[id].mark_as_rechecked()

Expand Down
4 changes: 2 additions & 2 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def report(self,
self.add_error_info(info)

def _add_error_info(self, file: str, info: ErrorInfo) -> None:
assert file not in self.flushed_files
if file not in self.error_info_map:
self.error_info_map[file] = []
self.error_info_map[file].append(info)
Expand Down Expand Up @@ -358,7 +359,7 @@ def raise_error(self) -> None:
Render the messages suitable for displaying.
"""
# self.new_messages() will format all messages that haven't already
# been returned from a new_module_messages() call.
# been returned from a file_messages() call.
raise CompileError(self.new_messages(),
use_stdout=True,
module_with_blocker=self.blocker_module())
Expand Down Expand Up @@ -596,7 +597,6 @@ def report_internal_error(err: Exception, file: Optional[str], line: int,
# Dump out errors so far, they often provide a clue.
# But catch unexpected errors rendering them.
try:
errors.flushed_files = set() # Print out already flushed messages too
for msg in errors.new_messages():
print(msg)
except Exception as e:
Expand Down
8 changes: 4 additions & 4 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def main(script_path: Optional[str], args: Optional[List[str]] = None) -> None:

messages = []

def flush_errors(a: List[str], serious: bool) -> None:
messages.extend(a)
def flush_errors(new_messages: List[str], serious: bool) -> None:
messages.extend(new_messages)
f = sys.stderr if serious else sys.stdout
try:
for m in a:
f.write(m + '\n')
for msg in new_messages:
f.write(msg + '\n')
f.flush()
except BrokenPipeError:
sys.exit(1)
Expand Down
1 change: 1 addition & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Options:
"show_none_errors",
"warn_no_return",
"warn_return_any",
"warn_unused_ignores",
Copy link
Member

Choose a reason for hiding this comment

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

Oh, now the docs also need to be updated (it has separate sections for global and per-module flags).

"ignore_errors",
"strict_boolean",
"no_implicit_optional",
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testerrorstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def flush_errors(msgs: List[str], serious: bool) -> None:
alt_lib_path=test_temp_dir,
flush_errors=flush_errors)
except CompileError as e:
pass
assert e.messages == []

assert_string_arrays_equal(testcase.output, logged_messages,
'Invalid output ({}, line {})'.format(
Expand Down
4 changes: 3 additions & 1 deletion test-data/unit/check-kwargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ m.A(x=1)
class A:
def __init__(self) -> None:
pass

[out]
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a comment (--) explaining why the errors appear out of order?

-- Note that the messages appear "out of order" because the m.py:3
-- message is really an attachment to the main:2 error and should be
-- reported with it.
tmp/m.py:1: error: Unsupported operand types for + ("int" and "str")
main:2: error: Unexpected keyword argument "x" for "A"
tmp/m.py:3: note: "A" defined here
0