mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 09:00:26 +00:00
Correctly handle references in __all__
definitions when renaming symbols in autofixes (#10527)
This commit is contained in:
parent
61b7982422
commit
9feb9b0aa8
16 changed files with 173 additions and 20 deletions
|
@ -1590,6 +1590,13 @@ impl<'a> SemanticModel<'a> {
|
|||
.intersects(SemanticModelFlags::COMPREHENSION_ASSIGNMENT)
|
||||
}
|
||||
|
||||
/// Return `true` if the model is visiting the r.h.s. of an `__all__` definition
|
||||
/// (e.g. `"foo"` in `__all__ = ["foo"]`)
|
||||
pub const fn in_dunder_all_definition(&self) -> bool {
|
||||
self.flags
|
||||
.intersects(SemanticModelFlags::DUNDER_ALL_DEFINITION)
|
||||
}
|
||||
|
||||
/// Return an iterator over all bindings shadowed by the given [`BindingId`], within the
|
||||
/// containing scope, and across scopes.
|
||||
pub fn shadowed_bindings(
|
||||
|
@ -1941,6 +1948,18 @@ bitflags! {
|
|||
/// ```
|
||||
const DOCSTRING = 1 << 21;
|
||||
|
||||
/// The model is visiting the r.h.s. of a module-level `__all__` definition.
|
||||
///
|
||||
/// This could be any module-level statement that assigns or alters `__all__`,
|
||||
/// for example:
|
||||
/// ```python
|
||||
/// __all__ = ["foo"]
|
||||
/// __all__: str = ["foo"]
|
||||
/// __all__ = ("bar",)
|
||||
/// __all__ += ("baz,")
|
||||
/// ```
|
||||
const DUNDER_ALL_DEFINITION = 1 << 22;
|
||||
|
||||
/// The context is in any type annotation.
|
||||
const ANNOTATION = Self::TYPING_ONLY_ANNOTATION.bits() | Self::RUNTIME_EVALUATED_ANNOTATION.bits() | Self::RUNTIME_REQUIRED_ANNOTATION.bits();
|
||||
|
||||
|
|
|
@ -93,6 +93,12 @@ impl ResolvedReference {
|
|||
self.flags
|
||||
.intersects(SemanticModelFlags::TYPE_CHECKING_BLOCK)
|
||||
}
|
||||
|
||||
/// Return `true` if the context is in the r.h.s. of an `__all__` definition.
|
||||
pub const fn in_dunder_all_definition(&self) -> bool {
|
||||
self.flags
|
||||
.intersects(SemanticModelFlags::DUNDER_ALL_DEFINITION)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for ResolvedReference {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue