From 08e935648a3e344f447c946180e5099d09fcb247 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Thu, 21 Jul 2016 16:05:33 -0700 Subject: [PATCH 1/2] Don't report unused type ignores in typeshed --- mypy/errors.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mypy/errors.py b/mypy/errors.py index 25f7ed0c2057..9161e7de072e 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): + # 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.""" From cb51a1e1901ee85adefc97092f04f39f698cef74 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Fri, 22 Jul 2016 13:49:33 -0700 Subject: [PATCH 2/2] minor fixup --- mypy/checker.py | 3 +-- mypy/errors.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) 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 9161e7de072e..08290f096289 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -210,7 +210,7 @@ def generate_unused_ignore_notes(self) -> None: False, False) self.error_info.append(info) - def is_typeshed_file(self, file): + 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)