diff --git a/mypy/checker.py b/mypy/checker.py index 5bacc9d2bb62..64dee5a9c13b 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -145,8 +145,7 @@ def visit_file(self, file_node: MypyFile, path: str) -> None: self.globals = file_node.names self.weak_opts = file_node.weak_opts self.enter_partial_types() - # gross, but no other clear way to tell - self.is_typeshed_stub = self.is_stub and 'typeshed' in os.path.normpath(path).split(os.sep) + self.is_typeshed_stub = self.errors.is_typeshed_file(path) for d in file_node.defs: self.accept(d) diff --git a/mypy/errors.py b/mypy/errors.py index 25f7ed0c2057..08290f096289 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -202,12 +202,17 @@ def add_error_info(self, info: ErrorInfo) -> None: def generate_unused_ignore_notes(self) -> None: for file, ignored_lines in self.ignored_lines.items(): - for line in ignored_lines - self.used_ignored_lines[file]: - # Don't use report since add_error_info will ignore the error! - info = ErrorInfo(self.import_context(), file, None, None, - line, 'note', "unused 'type: ignore' comment", - False, False) - self.error_info.append(info) + if not self.is_typeshed_file(file): + for line in ignored_lines - self.used_ignored_lines[file]: + # Don't use report since add_error_info will ignore the error! + info = ErrorInfo(self.import_context(), file, None, None, + line, 'note', "unused 'type: ignore' comment", + False, False) + self.error_info.append(info) + + def is_typeshed_file(self, file: str) -> bool: + # gross, but no other clear way to tell + return 'typeshed' in os.path.normpath(file).split(os.sep) def num_messages(self) -> int: """Return the number of generated messages."""