Support file-level type: ignore comments#15081
Merged
MichaReiser merged 1 commit intomainfrom Dec 23, 2024
Merged
Conversation
MichaReiser
commented
Dec 20, 2024
Comment on lines
+181
to
+198
| let (suppressions, suppressed_range) = | ||
| // `type: ignore` comments at the start of the file apply to the entire range. | ||
| // > A # type: ignore comment on a line by itself at the top of a file, before any docstrings, | ||
| // > imports, or other executable code, silences all errors in the file. | ||
| // > Blank lines and other comments, such as shebang lines and coding cookies, | ||
| // > may precede the # type: ignore comment. | ||
| // > https://typing.readthedocs.io/en/latest/spec/directives.html#type-ignore-comments | ||
| if comment.kind.is_type_ignore() && !self.seen_non_trivia_token { | ||
| ( | ||
| &mut self.file, | ||
| TextRange::new(0.into(), self.source.text_len()), | ||
| ) | ||
| } else { | ||
| ( | ||
| &mut self.line, | ||
| TextRange::new(line_start, comment.range.end()), | ||
| ) | ||
| }; |
Member
Author
There was a problem hiding this comment.
This is the only new code in this block. Everything else was extracted from the suppressions functions
7af6641 to
357825e
Compare
Contributor
|
5259a0f to
7078786
Compare
357825e to
ec700b8
Compare
carljm
approved these changes
Dec 22, 2024
| including module docstrings. | ||
| """ | ||
|
|
||
| # type: ignore |
Contributor
There was a problem hiding this comment.
Should this emit a diagnostic? Or not necessary, because it just won't work and that will be obvious from other diagnostics in the file?
Member
Author
There was a problem hiding this comment.
ec700b8 to
788bfd2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds support for file-level
type: ignorecommentsI intentionally didn't enable this behavior for
knot: ignorecomments because we may want to introduce a distinct syntax that not only allows suppressing errors but also enabling rules or changing the rule's severity:knot: possibly-undefined-variable="warn"Test Plan
Added mtests