-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
There was a problem hiding this 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('/'): |
There was a problem hiding this comment.
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, _))) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
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 usedin 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 importshould 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-lineimports, 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.