From 188d438e00741dccda8484576b03041aa5ca4d61 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Sun, 1 Feb 2026 23:00:28 +0900 Subject: [PATCH] Use new_os_subtype_error for termios error construction - Replace manual exception creation with new_os_subtype_error in termios - Remove redundant .to_owned() calls in os.link() error messages --- crates/stdlib/src/termios.rs | 9 ++++----- crates/vm/src/stdlib/os.rs | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/stdlib/src/termios.rs b/crates/stdlib/src/termios.rs index 48dfae25a..de4027244 100644 --- a/crates/stdlib/src/termios.rs +++ b/crates/stdlib/src/termios.rs @@ -261,13 +261,12 @@ mod termios { } fn termios_error(err: std::io::Error, vm: &VirtualMachine) -> PyBaseExceptionRef { - vm.new_exception( + vm.new_os_subtype_error( error_type(vm), - vec![ - err.posix_errno().to_pyobject(vm), - vm.ctx.new_str(err.to_string()).into(), - ], + Some(err.posix_errno()), + vm.ctx.new_str(err.to_string()), ) + .upcast() } #[pyattr(name = "error", once)] diff --git a/crates/vm/src/stdlib/os.rs b/crates/vm/src/stdlib/os.rs index d4a3b085b..95836e383 100644 --- a/crates/vm/src/stdlib/os.rs +++ b/crates/vm/src/stdlib/os.rs @@ -1278,9 +1278,9 @@ pub(super) mod _os { { use std::os::unix::ffi::OsStrExt; let src_cstr = std::ffi::CString::new(src.path.as_os_str().as_bytes()) - .map_err(|_| vm.new_value_error("embedded null byte".to_owned()))?; + .map_err(|_| vm.new_value_error("embedded null byte"))?; let dst_cstr = std::ffi::CString::new(dst.path.as_os_str().as_bytes()) - .map_err(|_| vm.new_value_error("embedded null byte".to_owned()))?; + .map_err(|_| vm.new_value_error("embedded null byte"))?; let flags = if follow_symlinks.0 { libc::AT_SYMLINK_FOLLOW @@ -1315,7 +1315,7 @@ pub(super) mod _os { // or raise NotImplementedError if explicitly set to False if !follow_symlinks.0 { return Err(vm.new_not_implemented_error( - "link: follow_symlinks unavailable on this platform".to_owned(), + "link: follow_symlinks unavailable on this platform", )); }