Skip to content

Commit c8991a5

Browse files
authored
Declare nullable argument defaults directly (#9560)
* Replace concrete omission wrappers with typed defaults Declare fifteen concrete argument defaults directly across compression, array, binascii, process helpers, epoll and match methods. Keep bool conversion and argument release at their current body locations, acquired buffer cleanup order, mkfifo path-before-fd conversion, and existing signed bound semantics. Preserve symbolic, callback-sensitive and stateful omission defaults. No tests, assertions or Lib files changed. Source-reviewed against CPython 3.15.0 d220409a13b77de7a6c30abe16ea90db01528edc; native validation remains limited by the available dependency closure. Assisted-by: OpenAI Codex:model version not exposed * Preserve native omitted argument fast paths Restore runtime defaults whose concrete literal lowering adds Python object creation, conversion, or reference management on omitted arguments. Keep only cost-preserving None default cleanup, where applicable. No test code or expectations changed. Assisted-by: OpenAI Codex:model version not exposed * Infer epoll exit argument names from fields Use the signature names as the Rust field names so explicit name attributes are redundant. Match the existing multiprocessing ExitArgs dead-code annotation for intentionally ignored context-manager arguments; keep the function body and argument lifetimes unchanged. Assisted-by: OpenAI Codex:model version not exposed * Remove unused regex OptionalArg import The nullable match default no longer uses OptionalArg. Remove the stale import so Clippy with -Dwarnings passes; no runtime or test changes. Assisted-by: OpenAI Codex:model version not exposed
1 parent 94a2b2d commit c8991a5

4 files changed

Lines changed: 18 additions & 22 deletions

File tree

‎crates/stdlib/src/select.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,14 @@ mod decl {
519519
}
520520

521521
#[derive(FromArgs)]
522+
#[allow(dead_code)]
522523
struct EpollExitArgs {
523-
#[pyarg(positional, optional, name = "exc_type", py_default = "None")]
524-
_exc_type: OptionalArg,
525-
#[pyarg(positional, optional, name = "exc_value", py_default = "None")]
526-
_exc_value: OptionalArg,
527-
#[pyarg(positional, optional, name = "exc_tb", py_default = "None")]
528-
_exc_tb: OptionalArg,
524+
#[pyarg(positional, default = None)]
525+
exc_type: Option<PyObjectRef>,
526+
#[pyarg(positional, default = None)]
527+
exc_value: Option<PyObjectRef>,
528+
#[pyarg(positional, default = None)]
529+
exc_tb: Option<PyObjectRef>,
529530
}
530531

531532
#[pyclass(with(Constructor))]

‎crates/vm/src/stdlib/_signal.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,15 @@ pub(crate) mod _signal {
406406
Ok(old_fd as i64)
407407
}
408408

409-
#[cfg(any(target_os = "android", target_os = "linux"))]
410-
use crate::function::OptionalArg;
411-
412409
#[cfg(any(target_os = "android", target_os = "linux"))]
413410
#[derive(FromArgs)]
414411
struct PidfdSendSignalArgs {
415412
#[pyarg(positional)]
416413
pidfd: i32,
417414
#[pyarg(positional, name = "signalnum")]
418415
sig: core::ffi::c_int,
419-
#[pyarg(positional, optional, py_default = "None")]
420-
siginfo: OptionalArg<PyObjectRef>,
416+
#[pyarg(positional, default = None)]
417+
siginfo: Option<PyObjectRef>,
421418
#[pyarg(positional, default)]
422419
flags: core::ffi::c_int,
423420
}
@@ -433,9 +430,7 @@ pub(crate) mod _signal {
433430
}: PidfdSendSignalArgs,
434431
vm: &VirtualMachine,
435432
) -> PyResult<()> {
436-
if let OptionalArg::Present(obj) = siginfo
437-
&& !vm.is_none(&obj)
438-
{
433+
if siginfo.is_some() {
439434
return Err(vm.new_type_error("siginfo must be None"));
440435
}
441436

‎crates/vm/src/stdlib/_sre.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod _sre {
1212
common::wtf8::{Wtf8, Wtf8Buf, wtf8_concat},
1313
common::{ascii, hash::PyHash},
1414
convert::ToPyObject,
15-
function::{ArgCallable, DefaultRepr, OptionalArg, PosArgs, PyComparisonValue},
15+
function::{ArgCallable, DefaultRepr, PosArgs, PyComparisonValue},
1616
protocol::{BufferFlags, PyBuffer, PyCallable, PyMappingMethods},
1717
stdlib::sys,
1818
types::{AsMapping, Comparable, Hashable, Representable},
@@ -338,8 +338,8 @@ mod _sre {
338338
#[derive(FromArgs)]
339339
struct DefaultArg {
340340
// Missing default is None.
341-
#[pyarg(any, optional, py_default = "None")]
342-
default: OptionalArg<PyObjectRef>,
341+
#[pyarg(any, default = None)]
342+
default: Option<PyObjectRef>,
343343
}
344344

345345
/// A position in the searched string, taken as a Py_ssize_t; a negative
@@ -648,7 +648,7 @@ mod _sre {
648648
} else {
649649
m.groups(
650650
DefaultArg {
651-
default: OptionalArg::Present(empty.clone()),
651+
default: Some(empty.clone()),
652652
},
653653
vm,
654654
)?

‎crates/vm/src/stdlib/posix.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,8 @@ pub mod module {
11031103
path: MkfifoPath,
11041104
#[pyarg(any, default = MkfifoMode(0o666), py_default = "438")]
11051105
mode: MkfifoMode,
1106-
#[pyarg(named, optional, py_default = "None")]
1107-
dir_fd: OptionalArg<PyObjectRef>,
1106+
#[pyarg(named, default = None)]
1107+
dir_fd: Option<PyObjectRef>,
11081108
}
11091109

11101110
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
@@ -1115,7 +1115,7 @@ pub mod module {
11151115
// Keep a raw C int: even -1 is valid with an absolute path, for which
11161116
// mkfifoat ignores dir_fd. BorrowedFd cannot represent that value.
11171117
let dir_fd = match args.dir_fd {
1118-
OptionalArg::Present(fd) if !vm.is_none(&fd) => {
1118+
Some(fd) => {
11191119
warn_if_bool_fd(&fd, vm)?;
11201120
let fd = fd.try_index_opt(vm).unwrap_or_else(|| {
11211121
Err(vm.new_type_error(format!(
@@ -1133,7 +1133,7 @@ pub mod module {
11331133
})?;
11341134
(fd != rustpython_host_env::os::AT_FDCWD).then_some(fd)
11351135
}
1136-
_ => None,
1136+
None => None,
11371137
};
11381138
if dir_fd.is_some() && !host_posix::has_mkfifoat() {
11391139
return Err(vm.new_not_implemented_error("dir_fd unavailable on this platform"));

0 commit comments

Comments
 (0)