8000 Don't report unused type ignores in typeshed by ddfisher · Pull Request #1920 · python/mypy · GitHub
[go: up one dir, main page]

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
Changes from 1 commit
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
Next Next commit
Don't report unused type ignores in typeshed
  • Loading branch information
ddfisher committed Jul 21, 2016
commit 08e935648a3e344f447c946180e5099d09fcb247
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs annotations.

If you make this the accepted, public interface to determine whether a file is in the typeshed or not, you can refactor the code in checker.py that sets is_typeshed_stub there like this:

    self.is_typeshed_stub = self.errors.is_typeshed_file(path)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice improvement. Fixed!

# 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
0