Support silencing only some error codes#8102
Support silencing only some error codes#8102ilevkivskyi wants to merge 4 commits intopython:masterfrom
Conversation
JukkaL
left a comment
There was a problem hiding this comment.
Nice, this will be a useful feature, especially if/when we add more error codes.
My biggest feedback is that I think that we should merge ignored error codes (see my comment below for why I think so).
| .. option:: --ignore-error-codes CODES | ||
|
|
||
| This flag makes mypy ignore all errors with given error codes. Flag accepts | ||
| error codes as a comma separated list (there should be no spaces after commas). |
There was a problem hiding this comment.
It might be better for usability if spaces around commas were ignored. Error codes can't have spaces.
Grammar nit: "comma separated" -> "comma-separated" (we use the latter spelling elsewhere)
| def __init__(self, attr: str, value: object) -> None: | ||
| setattr(self, attr, value) | ||
|
|
||
| magic_builtin # error: Name "magic_builtin" is not defined |
There was a problem hiding this comment.
The comments make this example look kind of busy, since some of the messages are long. Also, it would be nice to include the error codes in the message, as now it's unclear where the error codes come from (--show-error-codes is introduced only later).
Here's a suggested change:
- Remove the comments from the example.
- Include full output from a mypy run, without
--ignore-error-codesflag, but with--show-error-codes. - Show output from another mypy run, now with the the various error codes ignored.
|
|
||
| To make mypy show error codes in error messages use :option:`--show-error-codes`. | ||
| See also the lists of :ref:`default error codes <error-code-list>` and | ||
| :ref:`optional error codes <error-codes-optional>`. |
There was a problem hiding this comment.
I think that we should have a warning here, as ignoring some errors could be quite confusing and dangerous, especially misc.
| Show absolute paths to files. | ||
|
|
||
| ``ignore_error_codes`` (comma-separated list of strings) | ||
| Ignore errors with these error codes in given files or directories. |
There was a problem hiding this comment.
The part "in given files or directories" seems redundant. It's not included in other descriptions, and so it raises the question why this option applies to given files or directories, while other options don't apply to given files or directories?
| ``ignore_error_codes`` (comma-separated list of strings) | ||
| Ignore errors with these error codes in given files or directories. | ||
| See :option:`--ignore-error-codes <mypy --ignore-error-codes>` for | ||
| more details. |
There was a problem hiding this comment.
Really tiny consistency nit: we use "for more information" about and "more details here". Maybe use "for more information" here as well.
| error codes. Currently it's only possible to disable arbitrary error | ||
| codes on individual lines using this comment. | ||
| error codes. Also you can use :option:`--ignore-error-codes <mypy --ignore-error-codes>` | ||
| for more coarse-grained (per file or per directory) silencing of errors. |
There was a problem hiding this comment.
The actual command line flag only allows global silencing of errors, but this implies that it's per file or per directory. Either leave the parenthetical remark out, or somehow make it clear that per-file/directory options are only available through the config file or # mypy: ... comments. For consistency, I'd leave it out, since we probably don't want to discuss this separately for every reference to every option.
| group=error_group) | ||
| error_group.add_argument( | ||
| '--ignore-error-codes', metavar='CODES', type=split_commas, | ||
| help="Ignore errors with these error codes (comma separated)") |
There was a problem hiding this comment.
Spelling nit: use "comma-separated" (similar to above)
| # Files in which to ignore all non-fatal errors | ||
| self.ignore_errors = False | ||
|
|
||
| # Ignore errors with these error codes in a given file. |
There was a problem hiding this comment.
Nit: "in a given files." seems redunant. Also omit period at the end for consistency?
| \[mypy] | ||
| ignore_error_codes = attr-defined, arg-type | ||
| \[mypy-b] | ||
| ignore_error_codes = name-defined, assignment |
There was a problem hiding this comment.
I'd like to eventually move various strictness flags to be enabled/disabled through error codes. To do this, it seems that per-file options need to be a delta over global settings, instead of replacing them. Also, command-line options probably should be a delta over settings in the ini file. I.e., the ignored error codes would be the union of error codes ignored in the config file, on the command line, and in per-file options.
The logic gets a bit more involved once we allow enabling error codes as well, but at least we should be able to design the semantic for ignoring error codes in a way that we don't need to introduce a compatibility break.
| not_defined # E: Name 'not_defined' is not defined | ||
| x: int = 'no' # E: Incompatible types in assignment (expression has type "str", variable has type "int") | ||
| 'no'.no_way | ||
| def test(x: str) -> None: ... |
There was a problem hiding this comment.
Also add daemon test case (to make sure the daemon applies these after updates).
|
Actually I decided not to do this. I will not have time, I will leave the branch if someone wants to work on this. |
This PR adds support for silencing particular error codes either on command line, in config file or in inline mypy options. The implementation is mostly straightforward, here are however two important comments:
--always-trueand--always-false), I am not sure this is the most obvious behavior, but it looks like it is most flexible. We can reconsider this later if people will find it confusing.