-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Change flag names for silent modes and add a new mode ("follow silently") #2513
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
Well, I'd hope not. :O |
This makes sense to me. What's the rationale of keeping the current behavior of --silent-imports? Apart from worse performance, your new halfassed mode looks strictly better. |
Backwards compatibility. When I use this on our internal semi-annotated codebases (which are currently clean using --silent-imports), I get thousands of new errors. I don't have the time to fix all of those instantly -- realistically it can take months. (It's similar with --strict-optional and even --warn-no-return; we have to be able to gradually turn these new strictness options on for sections of the code.) |
e327591
to
5f47b23
Compare
@@ -222,6 +222,11 @@ def process_options(args: List[str], | |||
# which will make the cache writing process output pretty-printed JSON (which | |||
# is easier to debug). | |||
parser.add_argument('--debug-cache', action='store_true', help=argparse.SUPPRESS) | |||
# --half-assed mode is a bit like --silent-imports in that it distinguishes | |||
# modules listed on the command line; however instead of ignoring such | |||
# imports, it follows them but silences errors. Stubs are unaffected. |
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.
Perhaps mention how blocker errors work in --half-assed
mode. What if we have both --half-assed
and --silent-imports
-- would we then follow imports (but ignore errors) if we can find an implementation of a module not listed on the command line, and ignore the import silently if no implementation can be found?
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.
Blockers still abort the run. If both flags are set, indeed we process the module silently if found, and skip it silently if not found.
@gvanrossum In |
It would be useful to have a short specification of how this works. It would also make it easier to check whether the implementation matches the spec. |
OK, here's an attempt at a specification. First the categories of files (modules) we consider:
Remember that when looking for a module on MYPYPATH, if a .py file and a .pyi stub are found in the same directory, the .pyi stub always takes preference. All three options involved here (--silent-imports, --almost-silent and --half-assed) only affect categories (3) and (4). When considering combinations, --almost-silent implies --silent-imports but otherwise they are all independent. For (4), we get an error except when --silent-imports is present without --almost-silent. For (3):
Another way of looking at it:
|
Maybe we need to create a different set of flags? E.g. one tri-value flag that determines how to handle (3) (normal, quiet or skip) and one Boolean flag that determines whether (4) is reported as an error or not. That might be simpler to explain and understand. |
5f47b23
to
bd5744d
Compare
Still left to do:
|
f815d4d
to
dac96ba
Compare
9ff183a
to
2d95bf2
Compare
This is ready for more review. The only thing left to do is documentation, and I'd like to do that in a separate PR. To summarize the new flags:
|
print("Warning: --almost-silent has been replaced by " | ||
"--follow=imports=errors", file=sys.stderr) | ||
if options.follow_imports == 'normal': | ||
options.follow_imports = 'skip' |
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 'errors'
?
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.
Good catch! Will fix.
@@ -229,9 +229,9 @@ mypy.ini: [mypy]: Unrecognized report type: bad_report | |||
# cmd: mypy -c pass | |||
[file mypy.ini] | |||
[[mypy] | |||
silent_imports = nah | |||
ignore_missing_imports = nah |
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.
What about adding test cases that use config file to use the new options?
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.
Will do.
What about test cases that use the new silent import mode together |
If there are existing tests for that I'll convert them.
Yes, the new flags are included in PER_MODULE_OPTIONS (see options.py) and those are included in OPTIONS_AFFECTING_CACHE. Whenever such an option changes the cache is invalidated. |
6da40e1
to
b63c899
Compare
@JukkaL, what do you think of this now? |
# cmd: mypy main.py | ||
[file main.py] | ||
import a | ||
a.x + 0 |
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.
Test generating an error here, e.g. a.x + 'x'
?
[out] | ||
main:2: note: Import of 'a' ignored | ||
main:2: note: (Using --follow-imports=error, module not passed on command line) | ||
[out2] |
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.
I wonder if it would be useful to have test cases where the output differs between the first and the second run (e.g. error -> no error, no error -> error)? Is it possible to test incremental with changes in config file only (so that config file change should affect output)?
I did everything you requested, no new problems were revealed by the added tests. Note that I also added an error message if the config file cannot be found (only when specified explicitly). |
Thanks for the updates! This is now ready to merge. This will likely conflict with the error context PR and I leave it up to you to decide which should go in first. |
…now some tests are failing)
…low-imports=error
…config file. Also mark --fast-parser flag recommended (except on Windows) instead of experimental.
8dc3960
to
cb88aaa
Compare
Originally called "half-assed mode (not its real name)".