-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support file-level type: ignore
comments
#15081
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
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()), | ||
) | ||
}; |
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.
This is the only new code in this block. Everything else was extracted from the suppressions
functions
7af6641
to
357825e
Compare
|
5259a0f
to
7078786
Compare
357825e
to
ec700b8
Compare
including module docstrings. | ||
""" | ||
|
||
# type: ignore |
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 emit a diagnostic? Or not necessary, because it just won't work and that will be obvious from other diagnostics in the file?
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.
This gets flagged by the unused-ignore-comment
rule
ec700b8
to
788bfd2
Compare
Summary
This PR adds support for file-level
type: ignore
commentsI intentionally didn't enable this behavior for
knot: ignore
comments 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