mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-21 11:00:31 +00:00
New Singleton
enum for PatternMatchSingleton
node (#8063)
## Summary This PR adds a new `Singleton` enum for the `PatternMatchSingleton` node. Earlier the node was using the `Constant` enum but the value for this pattern can only be either `None`, `True` or `False`. With the coming PR to remove the `Constant`, this node required a new type to fill in. This also has the benefit of narrowing the type down to only the possible values for the node as evident by the removal of `unreachable`. ## Test Plan Update the AST snapshots and run `cargo test`.
This commit is contained in:
parent
ee7d445ef5
commit
78bbf6d403
10 changed files with 70 additions and 28 deletions
|
@ -1923,7 +1923,7 @@ impl From<PatternMatchValue> for Pattern {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PatternMatchSingleton {
|
||||
pub range: TextRange,
|
||||
pub value: Constant,
|
||||
pub value: Singleton,
|
||||
}
|
||||
|
||||
impl From<PatternMatchSingleton> for Pattern {
|
||||
|
@ -2578,6 +2578,23 @@ impl Ranged for Identifier {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Singleton {
|
||||
None,
|
||||
True,
|
||||
False,
|
||||
}
|
||||
|
||||
impl From<bool> for Singleton {
|
||||
fn from(value: bool) -> Self {
|
||||
if value {
|
||||
Singleton::True
|
||||
} else {
|
||||
Singleton::False
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
pub enum Constant {
|
||||
None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue