mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Respect # noqa
directives on __all__
openers (#10798)
## Summary Historically, given: ```python __all__ = [ # noqa: F822 "Bernoulli", "Beta", "Binomial", ] ``` The F822 violations would be attached to the `__all__`, so this `# noqa` would be enforced for _all_ definitions in the list. This changed in https://github.com/astral-sh/ruff/pull/10525 for the better, in that we now use the range of each string. But these `# noqa` directives stopped working. This PR sets the `__all__` as a parent range in the diagnostic, so that these directives are respected once again. Closes https://github.com/astral-sh/ruff/issues/10795. ## Test Plan `cargo test`
This commit is contained in:
parent
83db62bcda
commit
7fb5f47efe
6 changed files with 102 additions and 33 deletions
|
@ -39,6 +39,34 @@ impl Ranged for DunderAllName<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Abstraction for a collection of names inside an `__all__` definition,
|
||||
/// e.g. `["foo", "bar"]` in `__all__ = ["foo", "bar"]`
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DunderAllDefinition<'a> {
|
||||
/// The range of the `__all__` identifier.
|
||||
range: TextRange,
|
||||
/// The names inside the `__all__` definition.
|
||||
names: Vec<DunderAllName<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> DunderAllDefinition<'a> {
|
||||
/// Initialize a new [`DunderAllDefinition`] instance.
|
||||
pub fn new(range: TextRange, names: Vec<DunderAllName<'a>>) -> Self {
|
||||
Self { range, names }
|
||||
}
|
||||
|
||||
/// The names inside the `__all__` definition.
|
||||
pub fn names(&self) -> &[DunderAllName<'a>] {
|
||||
&self.names
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for DunderAllDefinition<'_> {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract the names bound to a given __all__ assignment.
|
||||
///
|
||||
/// Accepts a closure that determines whether a given name (e.g., `"list"`) is a Python builtin.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue