Skip to content

Commit b6dfa84

Browse files
committed
impl more ast
1 parent b4a3143 commit b6dfa84

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

crates/vm/src/stdlib/ast/pattern.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,31 @@ impl Node for ruff::PatternMatchSingleton {
199199
}
200200

201201
impl Node for ruff::Singleton {
202-
fn ast_to_object(self, _vm: &VirtualMachine, _source_file: &SourceFile) -> PyObjectRef {
203-
todo!()
202+
fn ast_to_object(self, vm: &VirtualMachine, _source_file: &SourceFile) -> PyObjectRef {
203+
match self {
204+
ruff::Singleton::None => vm.ctx.none(),
205+
ruff::Singleton::True => vm.ctx.new_bool(true).into(),
206+
ruff::Singleton::False => vm.ctx.new_bool(false).into(),
207+
}
204208
}
205209

206210
fn ast_from_object(
207-
_vm: &VirtualMachine,
211+
vm: &VirtualMachine,
208212
_source_file: &SourceFile,
209-
_object: PyObjectRef,
213+
object: PyObjectRef,
210214
) -> PyResult<Self> {
211-
todo!()
215+
if vm.is_none(&object) {
216+
Ok(ruff::Singleton::None)
217+
} else if object.is(&vm.ctx.true_value) {
218+
Ok(ruff::Singleton::True)
219+
} else if object.is(&vm.ctx.false_value) {
220+
Ok(ruff::Singleton::False)
221+
} else {
222+
Err(vm.new_value_error(format!(
223+
"Expected None, True, or False, got {:?}",
224+
object.class().name()
225+
)))
226+
}
212227
}
213228
}
214229

0 commit comments

Comments
 (0)