Skip to content

Report precision stats for imports and add new precision report #7254

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 14 commits into from
Jul 24, 2019

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 23, 2019

Previously when reporting per-line type checking precision, imports were
treated as empty lines, which seems inconsistent. Now treat an import as
precise if the target module exists, and as imprecise if the target module is
missing from the build.

Also add a new report, lineprecision, which is mostly designed to be used
in tests. The output is more compact and cleaner than the existing
XML-based reports.

Make it possible to run report generation tests without using full stubs,
since using full stubs is slow.

This is still not quite perfect. If using module-level __getattr__, the import
should probably be treated as imprecise. Also, if a missing name is ignored
using # type: ignore, we may want to treat that as imprecise. For multi-line
imports, we only report precision for the first line. These would be a bit tricky
to fix in the report generator so I decided to skip these for now.

@JukkaL JukkaL requested a review from msullivan July 23, 2019 16:43
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

This is great.

The fix is important, and making the reports actually testable is important

mypy/report.py Outdated
return True
if path.startswith('..'):
return True
if 'stubs' in path.split('/'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be os.sep?

mypy/report.py Outdated

file_info = FileInfo(path, tree._fullname)
for lineno, _ in iterate_python_lines(path):
print(repr((lineno, _)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Stray debug code?

mypy/report.py Outdated
output_files = sorted(self.files, key=lambda x: x.module)
report_file = os.path.join(self.output_dir, 'lineprecision.txt')
width = max(4, max(len(info.module) for info in output_files))
fmt = '{:%d} {:5} {:7} {:9} {:3} {:5} {:10}\n' % width
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe generate the width numbers here and below from the list of column headers instead of putting them in as magic numbers?

@JukkaL JukkaL merged commit 33d3df5 into master Jul 24, 2019
@msullivan msullivan deleted the precision-stats branch July 24, 2019 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants