mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 17:40:37 +00:00
Move undefined deletions into post-model-building pass (#5904)
## Summary Similar to #5902, but for undefined names in deletions (e.g., `del x` where `x` is unbound).
This commit is contained in:
parent
266e684192
commit
fe7505b738
3 changed files with 41 additions and 38 deletions
|
@ -78,19 +78,23 @@ pub struct UnresolvedReference {
|
|||
}
|
||||
|
||||
impl UnresolvedReference {
|
||||
/// The range of the reference in the source code.
|
||||
pub const fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
|
||||
/// The set of exceptions that were handled when resolution was attempted.
|
||||
pub const fn exceptions(&self) -> Exceptions {
|
||||
self.exceptions
|
||||
}
|
||||
|
||||
pub const fn wildcard_import(&self) -> bool {
|
||||
/// Returns `true` if the unresolved reference may be resolved by a wildcard import.
|
||||
pub const fn is_wildcard_import(&self) -> bool {
|
||||
self.flags
|
||||
.contains(UnresolvedReferenceFlags::WILDCARD_IMPORT)
|
||||
}
|
||||
|
||||
/// Returns the name of the reference.
|
||||
pub fn name<'a>(&self, locator: &Locator<'a>) -> &'a str {
|
||||
locator.slice(self.range)
|
||||
}
|
||||
|
@ -99,7 +103,15 @@ impl UnresolvedReference {
|
|||
bitflags! {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct UnresolvedReferenceFlags: u8 {
|
||||
/// The unresolved reference appeared in a context that includes a wildcard import.
|
||||
/// The unresolved reference may be resolved by a wildcard import.
|
||||
///
|
||||
/// For example, the reference `x` in the following code may be resolved by the wildcard
|
||||
/// import of `module`:
|
||||
/// ```python
|
||||
/// from module import *
|
||||
///
|
||||
/// print(x)
|
||||
/// ```
|
||||
const WILDCARD_IMPORT = 1 << 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue