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
Key errors based on origin file
  • Loading branch information
msullivan committed Jan 5, 2018
commit 92dfc2daaa426ef51240768f149be4d660b82ef4
1 change: 0 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def _build(sources: List[BuildSource],

try:
graph = dispatch(sources, manager)
manager.error_flush(manager.errors.new_messages())
return BuildResult(manager, graph)
finally:
manager.log("Build finished in %.3f seconds with %d modules, and %d errors" %
Expand Down
17 changes: 10 additions & 7 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class ErrorInfo:
# Only report this particular messages once per program.
only_once = False

# Actual origin of the error message
origin = None # type: Tuple[str, int]

# Fine-grained incremental target where this was reported
target = None # type: Optional[str]

Expand Down Expand Up @@ -291,13 +294,13 @@ def report(self,
target=self.current_target())
self.add_error_info(info)

def _add_error_info(self, info: ErrorInfo) -> None:
if info.file not in self.error_info_map:
self.error_info_map[info.file] = []
self.error_info_map[info.file].append(info)
def _add_error_info(self, file: str, info: ErrorInfo) -> None:
if file not in self.error_info_map:
self.error_info_map[file] = []
self.error_info_map[file].append(info)

def add_error_info(self, info: ErrorInfo) -> None:
(file, line) = cast(Tuple[str, int], info.origin) # see issue 1855
file, line = info.origin
if not info.blocker: # Blockers cannot be ignored
if file in self.ignored_lines and line in self.ignored_lines[file]:
# Annotation requests us to ignore all errors on this line.
Expand All @@ -309,7 +312,7 @@ def add_error_info(self, info: ErrorInfo) -> None:
if info.message in self.only_once_messages:
return
self.only_once_messages.add(info.message)
self._add_error_info(info)
self._add_error_info(file, info)

def generate_unused_ignore_notes(self, file: str) -> None:
ignored_lines = self.ignored_lines[file]
Expand All @@ -319,7 +322,7 @@ def generate_unused_ignore_notes(self, file: str) -> None:
info = ErrorInfo(self.import_context(), file, self.current_module(), None,
None, line, -1, 'note', "unused 'type: ignore' comment",
False, False)
self._add_error_info(info)
self._add_error_info(file, info)

def is_typeshed_file(self, file: str) -> bool:
# gross, but no other clear way to tell
Expand Down
10 changes: 8 additions & 2 deletions test-data/unit/check-kwargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,14 @@ A.B(x=1) # E: Unexpected keyword argument "x" for "B"

[case testUnexpectedMethodKwargFromOtherModule]
import m
m.A(x=1) # E: Unexpected keyword argument "x" for "A"
m.A(x=1)
[file m.py]
1+'asdf'
class A:
def __init__(self) -> None: # N: "A" defined here
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?

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