Skip to content
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

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

Merged
merged 14 commits into from Jul 24, 2019

Conversation

@JukkaL
Copy link
Collaborator

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 Jul 23, 2019
Copy link
Collaborator

left a comment

This is great.

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

return True
if path.startswith('..'):
return True
if 'stubs' in path.split('/'):

This comment has been minimized.

Copy link
@msullivan

msullivan Jul 24, 2019

Collaborator

Should this be os.sep?


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

This comment has been minimized.

Copy link
@msullivan

msullivan Jul 24, 2019

Collaborator

Stray debug code?

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

This comment has been minimized.

Copy link
@msullivan

msullivan Jul 24, 2019

Collaborator

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
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@msullivan msullivan deleted the precision-stats branch Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.