Add flag to tag known messages with an error code (take 2) #6472
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
I'm back with a new PR to replace #6152. I've tried to get satisfactory answers to the great questions that @JukkaL and @ilevkivskyi posed in the last PR, which I've reposted below with answers:
This has been partially addressed by #6194, by moving many message constants to
mypy.message_registry
, however, we have a lot more to move.Also in
mypy.message_registry
. String format args must be passed tofail()
methods rather than formatting first, in order to preserve the message constant until it reachesMessageBuilder
, so that an id can be looked up from the string literal. I haven't made that change throughout the code yet since it will be a lot of repetitive work and I wanted to get some feedback on the design of this PR first. That means in its current form, registered messages that are pre-formatted before being passed tofail()
are still being marked as 'uncategorized_error' in mypy output.For output examples, you can see some examples in
check-error-codes.txt
.Silencing error messages via a config file has been discussed here and here. This PR sets up all of the data necessary to implement filtering and the semantics of configuration and filtering messages can be solved in a separate PR.
I'm assuming this is about listing message ids. This is not in the tests yet, but here's an example of what it looks like:
This is a great question. My current thinking is that message grouping can be added using a separate dictionary at a later point.
I've simplified my approach from the original PR, so I think we should be in the clear, but I have not run any tests against mypyc yet.
I provided an example for
attrs
, and if we like it I can propagate it to the other builtin plugins.That said, since I'm using the plugin module as a unique namespace to prefix the error codes, this PR would benefit from the default plugin being broken up into a series of plugins:
mypy.plugins.attrs
,mypy.plugins.ctypes
, andmypy.plugins.dataclasses
.In addition to improving error labels for this PR, breaking up the default plugin has some other advantages:
attrs
here)If you agree, I'm happy to do that in a separate PR.
Covered above: the name of the plugin module is used. For the core error codes I use the namespace 'mypy'.
I decided to provide a default namespace for 3 reasons:
--list-error-codes
:
in mypy output with--show-error-codes
makes for easier parsing by 3rd party scriptsmypy.parse
mypy.analysis
,mypy.check
, etc.TBD