8000 Key errors based on origin file · python/mypy@92dfc2d · GitHub
[go: up one dir, main page]

Skip to content

Commit 92dfc2d

Browse files
committed
Key errors based on origin file
1 parent caa8477 commit 92dfc2d

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

mypy/build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ def _build(sources: List[BuildSource],
253253

254254
try:
255255
graph = dispatch(sources, manager)
256-
manager.error_flush(manager.errors.new_messages())
257256
return BuildResult(manager, graph)
258257
finally:
259258
manager.log("Build finished in %.3f seconds with %d modules, and %d errors" %

mypy/errors.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class ErrorInfo:
5151
# Only report this particular messages once per program.
5252
only_once = False
5353

54+
# Actual origin of the error message
55+
origin = None # type: Tuple[str, int]
56+
5457
# Fine-grained incremental target where this was reported
5558
target = None # type: Optional[str]
5659

@@ -291,13 +294,13 @@ def report(self,
291294
target=self.current_target())
292295
self.add_error_info(info)
293296

294-
def _add_error_info(self, info: ErrorInfo) -> None:
295-
if info.file not in self.error_info_map:
296-
self.error_info_map[info.file] = []
297-
self.error_info_map[info.file].append(info)
297+
def _add_error_info(self, file: str, info: ErrorInfo) -> None:
298+
if file not in self.error_info_map:
299+
self.error_info_map[file] = []
300+
self.error_info_map[file].append(info)
298301

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

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

324327
def is_typeshed_file(self, file: str) -> bool:
325328
# gross, but no other clear way to tell

test-data/unit/check-kwargs.test

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,14 @@ A.B(x=1) # E: Unexpected keyword argument "x" for "B"
390390

391391
[case testUnexpectedMethodKwargFromOtherModule]
392392
import m
393-
m.A(x=1) # E: Unexpected keyword argument "x" for "A"
393+
m.A(x=1)
394394
[file m.py]
395+
1+'asdf'
395396
class A:
396-
def __init__(self) -> None: # N: "A" defined here
397+
def __init__(self) -> None:
397398
pass
399+
400+
[out]
401+
tmp/m.py:1: error: Unsupported operand types for + ("int" and "str")
402+
main:2: error: Unexpected keyword argument "x" for "A"
403+
tmp/m.py:3: note: "A" defined here

0 commit comments

Comments
 (0)
0