-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add code to help filtering warning and errors in mypy's output #2417
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
Comments
Alternatively, we could have a command line option for each warning/error. We already have examples like Here are some tradeoffs:
|
Here is just an additional point, error codes can be also used in var.meth(other.attr) # type: ignore E231 |
Hi, I would like to implement this feature. Here is my plan: Step 1 (Internally support error code)
Step 2 (Fix compilation error introduced by step 1)
Step 3 (Make this feature available)
Step 4
PRO:
CON:
Note: This issue is currently tagged "Needs discussion"... so I am opening the discussion, any comment about my above plan? Note: Implementing all this will take time, I would like to make sure before starting that it would get merge once done. |
@elarivie In general I like your plan, but there is one weak point. Currently some error messages are not defined in |
To be honest, this will be such a big change that the core team may not have the capacity to review it in the near future, resulting in a long-lived PR that will be a pain to maintain. I think that the only reasonable approach for moving forward with this would be to do something like this:
This would require a relatively long-term commitment from you, since reviewing all the changes would likely take a long time. I actually doubt that it's going to very useful to ignore completely arbitrary errors. Mypy is different from a linter, as most errors aren't style-related but more "actionable". Before moving forward, I'd like to see additional real-world examples where ignoring a specific error would be useful. Here are a few examples which might be reasonable to ignore, but I'd like to see more:
If there is only a small number of additional errors that are useful to ignore, we can just continue to add new command-line options instead of doing a more major change to errors are categorized. Additional thoughts:
|
I'm going to take a shot at this, but I think I will do it as a separate tool at first, so that I can iterate faster, and also to add possibly more controversial ideas like colorized output. But the whole thing will start with a consolidation of error messages into
agreed.
As @sametmax proposed, this should be opt-in via a flag like
see above.
My time with flake8/pycodestyle has engendered a great dislike of inscrutable error codes for exactly this reason. I prefer error keys with somewhat descriptive names, like
True, but there are a LOT of error types. Adding a My current thinking is to take an approach inspired by pycodestyle and provide With this design, a config file would look like this: [mypy]
select_errors =
invalid_syntax,
not_defined,
invalid_type_arguments,
return_expected,
return_not_expected,
incompatible_return,
incompatible_yield, Alternately, to take an exclusive approach, you could use I'm still evaluating this design, so I may change my mind. There is one big advantage to on/off switches per error vs the select/ignore paradigm, which is that with individual on/off control you can create sparse overrides per module. With the select/ignore design I think you'd have to copy-paste the base config into each per-module section. @JukkaL Once the error messages are consolidated I'm going to create a tool prototype and use it with my team at work to better answer some of your questions/concerns. Here's how I see us using it:
As I'm sure you're aware, getting to that elusive |
@chadrik I like your plan! I didn't consider the workflow of starting with a small set of enabled errors, and gradually enabling more errors. I'd love to hear how this works in practice.
Maybe we can still support per-module configuration together with the select/ignore paradigm. Here's an idea:
This would also allow us to have some errors disabled by default (not included in the default selected errors set), while providing an easy way to turn them on. We could move many of the existing strictness flags such as |
…ker) (#6118) Consolidate all mypy error messages into one place (`mypy.messages`). This opens the door to some interesting features, such as adding language localization or a more systematic way of working with error messages, akin to error codes (#2417). It also helps create more consistent messages. e.g. it's now more apparent that there are a few outliers that use single quotes around type names. I'm breaking this up change up into several PRs by module, this is the first and simplest. Once all are complete, this will address #6116.
This is in preparation for message filtering (#2417). By moving constants to their own module we can easily inspect them to get both their name and value, for use within a message filtering system.
Now that #7334 is merged I think we can close this. (Note there are few follow-up issues tracked separately.) |
Uh oh!
There was an error while loading. Please reload this page.
As mentioned in #2411, it can become difficult to select what you want to see or not in mypy's ouput. This can lead to all-or-nothing behaviors, clutter display/logs, and make CI servers fail on errors we don't wish to check or ignore errors we do want to check.
A possible solution to this is to adopt the behaviour from popular linters such as flake8, pylint, etc.
Each type of error/warning have a code, and you can pass the ones you wish to ignore as a coma separated list using either the command line, a code comment or a config file. Each code is also displayed at the beginning of each respective warning/error in the tool output, so that you can grep for it easily.
E.G:
This is a general way of solving the filtering problem:
The text was updated successfully, but these errors were encountered: