Add --almost-silent, which modifies --silent-imports to warn about silenced imports#1371
Add --almost-silent, which modifies --silent-imports to warn about silenced imports#1371gvanrossum merged 6 commits intomasterfrom
Conversation
…lenced imports. Also deprecated --silent (at least in --help output).
|
I should add some discussion. The existing --silent-imports flag does two different things:
The error messages about missing modules (when not suppressed) take on different forms depending on whether the missing module is recognized as a stdlib module or a well-known third-party module, or neither. The decision with form to use is in module_not_found(). The new --almost-silent flag implies --silent-imports but modifies it in two ways:
The note about a suppressed module takes a different form depending on whether the import being suppressed is an implied import of a module's ancestor (parent) package, or a regular import. This difference is important, because these are really two quite different things being suppressed.
PS: A thought that just popped into my head: maybe the note about a suppressed ancestor dependency would look better if it was associated with the "import bar.baz" line in foo.py, rather than with the first line of bar/baz.py. |
|
Well, the idea from that PS is no good, because guess what -- the only ancestors that are ever being suppressed are the ancestors of files passed on the command line. For example, suppose we have a.py: from b.c import dand b/c.py: d = 42Now if we run: then mypy will suppress the ancestor package b when it's processing b/c.py, not when it's processing a.py, so there is no import context for b. (And in fact this makes sense -- it would come to the same conclusion even if a.py was not given.) |
…if`. Suppressing the line number was David's idea. It's easy. But it has one downside: in Emacs' grep/compile mode, you can't click on the line to go to the file. Maybe that's okay, I have to think about it. See the conversation in the PR for why my other idea (using the import line as the context) won't work.
mypy/build.py
Outdated
| DUMP_TYPE_STATS = 'dump-type-stats' | ||
| DUMP_INFER_STATS = 'dump-infer-stats' | ||
| SILENT_IMPORTS = 'silent-imports' # Silence imports of .py files | ||
| ALMOST_SILENT = 'silent-imports' # If SILENT_IMPORTS: report silenced imports as errors |
There was a problem hiding this comment.
Whoops! Should be 'almost-silent'!
mypy/build.py
Outdated
| manager.errors.report(-1, "(This note brought to you by --almost-silent)", | ||
| severity='note', only_once=True) | ||
|
|
||
| def skipping_module(self, id, path): |
|
LGTM. Have you thought about giving a special message if a base class is |
|
I filed #1374 to track the idea of warning about a base class being Any. |
| manager.errors.set_import_context([]) | ||
| manager.errors.set_file(ancestor_for.xpath) | ||
| manager.errors.report(-1, "Ancestor package '%s' silently ignored" % (id,), | ||
| severity='note', only_once=True) |
There was a problem hiding this comment.
Did you intend to apply this only_once here?
There was a problem hiding this comment.
I did -- if a package has many children it would be annoying to hear about this each time. And there's no possibility that some of the children have their ancestor ignored while others don't -- it's one ancestor and it's either ignored or not.
Also deprecated --silent (at least in --help output).
Fixes #1367.