Skip to content

Commit 647954c

Browse files
ddfishergvanrossum
authored andcommitted
Don't report unused type ignores in typeshed (#1920)
1 parent a3a25eb commit 647954c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

mypy/checker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ def visit_file(self, file_node: MypyFile, path: str) -> None:
145145
self.globals = file_node.names
146146
self.weak_opts = file_node.weak_opts
147147
self.enter_partial_types()
148-
# gross, but no other clear way to tell
149-
self.is_typeshed_stub = self.is_stub and 'typeshed' in os.path.normpath(path).split(os.sep)
148+
self.is_typeshed_stub = self.errors.is_typeshed_file(path)
150149

151150
for d in file_node.defs:
152151
self.accept(d)

mypy/errors.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,17 @@ def add_error_info(self, info: ErrorInfo) -> None:
206206

207207
def generate_unused_ignore_notes(self) -> None:
208208
for file, ignored_lines in self.ignored_lines.items():
209-
for line in ignored_lines - self.used_ignored_lines[file]:
210-
# Don't use report since add_error_info will ignore the error!
211-
info = ErrorInfo(self.import_context(), file, None, None,
212-
line, 'note', "unused 'type: ignore' comment",
213-
False, False)
214-
self.error_info.append(info)
209+
if not self.is_typeshed_file(file):
210+
for line in ignored_lines - self.used_ignored_lines[file]:
211+
# Don't use report since add_error_info will ignore the error!
212+
info = ErrorInfo(self.import_context(), file, None, None,
213+
line, 'note', "unused 'type: ignore' comment",
214+
False, False)
215+
self.error_info.append(info)
216+
217+
def is_typeshed_file(self, file: str) -> bool:
218+
# gross, but no other clear way to tell
219+
return 'typeshed' in os.path.normpath(file).split(os.sep)
215220

216221
def num_messages(self) -> int:
217222
"""Return the number of generated messages."""

0 commit comments

Comments
 (0)