Skip to content

Commit 578a2c8

Browse files
committed
OnceCell
1 parent ade0d69 commit 578a2c8

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

crates/vm/src/exception_group.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ fn create_exception_group(ctx: &Context) -> PyRef<PyType> {
3333
}
3434

3535
pub fn exception_group() -> &'static Py<PyType> {
36-
static EXCEPTION_GROUP: std::sync::LazyLock<PyTypeRef> =
37-
std::sync::LazyLock::new(|| create_exception_group(Context::genesis()));
38-
EXCEPTION_GROUP.as_ref()
36+
::rustpython_vm::common::static_cell! {
37+
static CELL: ::rustpython_vm::builtins::PyTypeRef;
38+
}
39+
CELL.get_or_init(|| create_exception_group(Context::genesis()))
3940
}
4041

4142
pub(super) mod types {
@@ -253,7 +254,7 @@ pub(super) mod types {
253254
let result = vm.call_method(&exc, "split", (condition.clone(),))?;
254255
let result_tuple: PyTupleRef = result.try_into_value(vm)?;
255256
let match_part = result_tuple
256-
.get(0)
257+
.first()
257258
.cloned()
258259
.unwrap_or_else(|| vm.ctx.none());
259260
let rest_part = result_tuple
@@ -378,10 +379,10 @@ pub(super) mod types {
378379
vm: &VirtualMachine,
379380
) -> PyResult<ConditionMatcher> {
380381
// If it's a type and subclass of BaseException
381-
if let Some(typ) = condition.downcast_ref::<PyType>() {
382-
if typ.fast_issubclass(vm.ctx.exceptions.base_exception_type) {
383-
return Ok(ConditionMatcher::Type(typ.to_owned()));
384-
}
382+
if let Some(typ) = condition.downcast_ref::<PyType>()
383+
&& typ.fast_issubclass(vm.ctx.exceptions.base_exception_type)
384+
{
385+
return Ok(ConditionMatcher::Type(typ.to_owned()));
385386
}
386387

387388
// If it's a tuple of types
@@ -456,11 +457,11 @@ pub(super) mod types {
456457
}
457458

458459
// Copy notes (if present) - make a copy of the list
459-
if let Ok(notes) = orig.as_object().get_attr("__notes__", vm) {
460-
if let Some(notes_list) = notes.downcast_ref::<PyList>() {
461-
let notes_copy = vm.ctx.new_list(notes_list.borrow_vec().to_vec());
462-
new_group.set_attr("__notes__", notes_copy, vm)?;
463-
}
460+
if let Ok(notes) = orig.as_object().get_attr("__notes__", vm)
461+
&& let Some(notes_list) = notes.downcast_ref::<PyList>()
462+
{
463+
let notes_copy = vm.ctx.new_list(notes_list.borrow_vec().to_vec());
464+
new_group.set_attr("__notes__", notes_copy, vm)?;
464465
}
465466

466467
Ok(new_group)

crates/vm/src/vm/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,11 @@ impl VirtualMachine {
373373
self.print_exception(e);
374374
}
375375

376-
let expect_stdlib =
376+
let _expect_stdlib =
377377
cfg!(feature = "freeze-stdlib") || !self.state.settings.path_list.is_empty();
378378

379379
#[cfg(feature = "encodings")]
380-
if expect_stdlib {
380+
if _expect_stdlib {
381381
if let Err(e) = self.import_encodings() {
382382
eprintln!(
383383
"encodings initialization failed. Only utf-8 encoding will be supported."

0 commit comments

Comments
 (0)