mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 16:40:19 +00:00
Make unpacked assignment a flag rather than a BindingKind
(#8595)
## Summary An assignment can be _both_ (e.g.) a loop variable _and_ assigned via unpacking. In other words, unpacking is a quality of an assignment, not a _kind_.
This commit is contained in:
parent
4ebd0bd31e
commit
0ac124acef
6 changed files with 27 additions and 51 deletions
|
@ -87,6 +87,12 @@ impl<'a> Binding<'a> {
|
|||
self.flags.intersects(BindingFlags::INVALID_ALL_OBJECT)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an unpacked assignment (e.g., `x` in
|
||||
/// `(x, y) = 1, 2`).
|
||||
pub const fn is_unpacked_assignment(&self) -> bool {
|
||||
self.flags.intersects(BindingFlags::UNPACKED_ASSIGNMENT)
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] represents an unbound variable
|
||||
/// (e.g., `x` in `x = 1; del x`).
|
||||
pub const fn is_unbound(&self) -> bool {
|
||||
|
@ -212,7 +218,7 @@ impl<'a> Binding<'a> {
|
|||
bitflags! {
|
||||
/// Flags on a [`Binding`].
|
||||
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct BindingFlags: u8 {
|
||||
pub struct BindingFlags: u16 {
|
||||
/// The binding represents an explicit re-export.
|
||||
///
|
||||
/// For example, the binding could be `FastAPI` in:
|
||||
|
@ -284,6 +290,14 @@ bitflags! {
|
|||
/// _T = "This is a private variable"
|
||||
/// ```
|
||||
const PRIVATE_DECLARATION = 1 << 7;
|
||||
|
||||
/// The binding represents an unpacked assignment.
|
||||
///
|
||||
/// For example, the binding could be `x` in:
|
||||
/// ```python
|
||||
/// (x, y) = 1, 2
|
||||
/// ```
|
||||
const UNPACKED_ASSIGNMENT = 1 << 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,12 +407,6 @@ pub enum BindingKind<'a> {
|
|||
/// ```
|
||||
NamedExprAssignment,
|
||||
|
||||
/// A binding for a unpacking-based assignment, like `x` in:
|
||||
/// ```python
|
||||
/// x, y = (1, 2)
|
||||
/// ```
|
||||
UnpackedAssignment,
|
||||
|
||||
/// A binding for a "standard" assignment, like `x` in:
|
||||
/// ```python
|
||||
/// x = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue