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
Eliminate the indexing
  • Loading branch information
msullivan committed Jan 4, 2018
commit 5c9abec810acce51a7ee688b8cbb52532d130a6a
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def build(sources: List[BuildSource],
except CompileError as e:
serious = not e.use_stdout
if flush_errors:
flush_errors(e.messages[e.num_already_seen:], serious)
flush_errors(e.fresh_messages, serious)
raise


Expand Down
27 changes: 15 additions & 12 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class Errors:
# files were processed.
error_info_map = None # type: Dict[str, List[ErrorInfo]]

# The size of error_info the last time that error messages were flushed
new_errors_start_map = None # type: Dict[str, int]
# Errors that haven't been flushed out yet
fresh_error_info_map = None # type: Dict[str, List[ErrorInfo]]

# A cache of the formatted messages
formatted_messages = None # type: List[str]
Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(self, show_error_context: bool = False,

def initialize(self) -> None:
self.error_info_map = OrderedDict()
self.new_errors_start_map = defaultdict(int)
self.fresh_error_info_map = OrderedDict()
self.import_ctx = []
self.formatted_messages = []
self.error_files = set()
Expand Down Expand Up @@ -302,7 +302,9 @@ def report(self,
def _add_error_info(self, info: ErrorInfo) -> None:
if info.file not in self.error_info_map:
self.error_info_map[info.file] = []
self.fresh_error_info_map[info.file] = []
self.error_info_map[info.file].append(info)
self.fresh_error_info_map[info.file].append(info)

def add_error_info(self, info: ErrorInfo) -> None:
(file, line) = cast(Tuple[str, int], info.origin) # see issue 1855
Expand Down Expand Up @@ -365,12 +367,13 @@ def raise_error(self) -> None:
"""
# self.new_messages() will format all messages that haven't already
# been returned from a new_module_messages() call. Count how many
# we've seen before that.
# we've seen before that so we can determine which are fresh.
already_seen = len(self.formatted_messages)
raise CompileError(self.messages(),
messages = self.messages()
raise CompileError(messages,
use_stdout=True,
module_with_blocker=self.blocker_module(),
num_already_seen=already_seen)
fresh_messages=messages[already_seen:])

def format_messages(self, error_info: List[ErrorInfo]) -> List[str]:
"""Return a string list that represents the error messages.
Expand Down Expand Up @@ -406,8 +409,8 @@ def new_file_messages(self, path: str) -> List[str]:
"""
if path not in self.error_info_map:
return []
msgs = self.format_messages(self.error_info_map[path][self.new_errors_start_map[path]:])
self.new_errors_start_map[path] = len(self.error_info_map[path])
msgs = self.format_messages(self.fresh_error_info_map[path])
self.fresh_error_info_map[path] = []
self.formatted_messages += msgs
return msgs

Expand Down Expand Up @@ -518,7 +521,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[Tuple[Optional[str],
def sort_messages(self, errors: List[ErrorInfo]) -> List[ErrorInfo]:
"""Sort an array of error messages locally by line number.

I.e., sort a run of consecutive messages with the same file
I.e., sort a run of consecutive messages with the same
context by line number, but otherwise retain the general
ordering of the messages.
"""
Expand Down Expand Up @@ -574,18 +577,18 @@ class CompileError(Exception):
use_stdout = False
# Can be set in case there was a module with a blocking error
module_with_blocker = None # type: Optional[str]
num_already_seen = 0
fresh_messages = None # type: List[str]

def __init__(self,
messages: List[str],
use_stdout: bool = False,
module_with_blocker: Optional[str] = None,
num_already_seen: int = 0) -> None:
fresh_messages: Optional[List[str]] = None) -> None:
super().__init__('\n'.join(messages))
self.messages = messages
self.use_stdout = use_stdout
self.module_with_blocker = module_with_blocker
self.num_already_seen = num_already_seen
self.fresh_messages = fresh_messages if fresh_messages is not None else messages


class DecodeError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testerrorstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_error_stream(testcase: DataDrivenTestCase) -> None:
logged_messages = [] # type: List[str]
real_messages = [] # type: List[str]

def flush_errors(msgs: List[str], serious: bool, is_real: bool=True) -> None:
def flush_errors(msgs: List[str], serious: bool, is_real: bool = True) -> None:
if msgs:
logged_messages.append('==== Errors flushed ====')
logged_messages.extend(msgs)
Expand Down
0