mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:34:40 +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
|
@ -1,5 +1,5 @@
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{Constant, PatternMatchSingleton};
|
||||
use ruff_python_ast::{PatternMatchSingleton, Singleton};
|
||||
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
@ -10,10 +10,9 @@ pub struct FormatPatternMatchSingleton;
|
|||
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
|
||||
fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
match item.value {
|
||||
Constant::None => token("None").fmt(f),
|
||||
Constant::Bool(true) => token("True").fmt(f),
|
||||
Constant::Bool(false) => token("False").fmt(f),
|
||||
_ => unreachable!(),
|
||||
Singleton::None => token("None").fmt(f),
|
||||
Singleton::True => token("True").fmt(f),
|
||||
Singleton::False => token("False").fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue