Skip to content

Don't report unused type ignores in typeshed #1920

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 2 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down