mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 13:18:52 +00:00
Use Flags::intersects
rather than Flags::contains
(#6007)
## Summary This is equivalent for a single flag, but I think it's more likely to be correct when the bitflags are modified -- the primary reason being that we sometimes define flags as the union of other flags, e.g.: ```rust const ANNOTATION = Self::TYPING_ONLY_ANNOTATION.bits() | Self::RUNTIME_ANNOTATION.bits(); ``` In this case, `flags.contains(Flag::ANNOTATION)` requires that _both_ flags in the union are set, whereas `flags.intersects(Flag::ANNOTATION)` requires that _at least one_ flag is set.
This commit is contained in:
parent
0bb175f7f6
commit
057faabcdd
7 changed files with 31 additions and 31 deletions
|
@ -45,44 +45,44 @@ impl<'a> Binding<'a> {
|
|||
/// Return `true` if this [`Binding`] represents an explicit re-export
|
||||
/// (e.g., `FastAPI` in `from fastapi import FastAPI as FastAPI`).
|
||||
pub const fn is_explicit_export(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::EXPLICIT_EXPORT)
|
||||
self.flags.intersects(BindingFlags::EXPLICIT_EXPORT)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an external symbol
|
||||
/// (e.g., `FastAPI` in `from fastapi import FastAPI`).
|
||||
pub const fn is_external(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::EXTERNAL)
|
||||
self.flags.intersects(BindingFlags::EXTERNAL)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an aliased symbol
|
||||
/// (e.g., `app` in `from fastapi import FastAPI as app`).
|
||||
pub const fn is_alias(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::ALIAS)
|
||||
self.flags.intersects(BindingFlags::ALIAS)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents a `nonlocal`. A [`Binding`] is a `nonlocal`
|
||||
/// if it's declared by a `nonlocal` statement, or shadows a [`Binding`] declared by a
|
||||
/// `nonlocal` statement.
|
||||
pub const fn is_nonlocal(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::NONLOCAL)
|
||||
self.flags.intersects(BindingFlags::NONLOCAL)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents a `global`. A [`Binding`] is a `global` if it's
|
||||
/// declared by a `global` statement, or shadows a [`Binding`] declared by a `global` statement.
|
||||
pub const fn is_global(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::GLOBAL)
|
||||
self.flags.intersects(BindingFlags::GLOBAL)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an assignment to `__all__` with an invalid
|
||||
/// value (e.g., `__all__ = "Foo"`).
|
||||
pub const fn is_invalid_all_format(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::INVALID_ALL_FORMAT)
|
||||
self.flags.intersects(BindingFlags::INVALID_ALL_FORMAT)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an assignment to `__all__` that includes an
|
||||
/// invalid member (e.g., `__all__ = ["Foo", 1]`).
|
||||
pub const fn is_invalid_all_object(&self) -> bool {
|
||||
self.flags.contains(BindingFlags::INVALID_ALL_OBJECT)
|
||||
self.flags.intersects(BindingFlags::INVALID_ALL_OBJECT)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an unbound variable
|
||||
|
|
|
@ -163,7 +163,7 @@ impl<'a> Scope<'a> {
|
|||
|
||||
/// Returns `true` if this scope uses locals (e.g., `locals()`).
|
||||
pub const fn uses_locals(&self) -> bool {
|
||||
self.flags.contains(ScopeFlags::USES_LOCALS)
|
||||
self.flags.intersects(ScopeFlags::USES_LOCALS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue