Skip to content

Commit ba3c47f

Browse files
committed
Match sequence, translation, and timestamp signature metadata
Use the platform-independent Clinic default for sequence searches and match Python 3.15 argument names and timestamp defaults without changing conversions. Assisted-by: OpenAI Codex: model version not exposed
1 parent 3d0f6fc commit ba3c47f

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

‎crates/vm/src/builtins/str.rs‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,29 +1579,29 @@ impl Py<PyStr> {
15791579

15801580
#[pystaticmethod]
15811581
fn maketrans(
1582-
dict_or_str: PyObjectRef,
1583-
to_str: OptionalArg<PyStrRef>,
1584-
none_str: OptionalArg<PyStrRef>,
1582+
x: PyObjectRef,
1583+
y: OptionalArg<PyStrRef>,
1584+
z: OptionalArg<PyStrRef>,
15851585
vm: &VirtualMachine,
15861586
) -> PyResult {
15871587
let new_dict = vm.ctx.new_dict();
1588-
if let OptionalArg::Present(to_str) = to_str {
1589-
match dict_or_str.downcast::<PyStr>() {
1588+
if let OptionalArg::Present(y) = y {
1589+
match x.downcast::<PyStr>() {
15901590
Ok(from_str) => {
1591-
if to_str.len() == from_str.len() {
1591+
if y.len() == from_str.len() {
15921592
for (c1, c2) in from_str
15931593
.as_wtf8()
15941594
.code_points()
1595-
.zip(to_str.as_wtf8().code_points())
1595+
.zip(y.as_wtf8().code_points())
15961596
{
15971597
new_dict.set_item(
15981598
&*vm.new_pyobj(c1.to_u32()),
15991599
vm.new_pyobj(c2.to_u32()),
16001600
vm,
16011601
)?;
16021602
}
1603-
if let OptionalArg::Present(none_str) = none_str {
1604-
for c in none_str.as_wtf8().code_points() {
1603+
if let OptionalArg::Present(z) = z {
1604+
for c in z.as_wtf8().code_points() {
16051605
new_dict.set_item(&*vm.new_pyobj(c.to_u32()), vm.ctx.none(), vm)?;
16061606
}
16071607
}
@@ -1618,9 +1618,8 @@ impl Py<PyStr> {
16181618
}
16191619
} else {
16201620
// The single-argument form accepts exact dict and frozendict objects.
1621-
match PyAnyDict::from_object(&dict_or_str).filter(|_| {
1622-
dict_or_str.class().is(vm.ctx.types.dict_type)
1623-
|| dict_or_str.class().is(vm.ctx.types.frozendict_type)
1621+
match PyAnyDict::from_object(&x).filter(|_| {
1622+
x.class().is(vm.ctx.types.dict_type) || x.class().is(vm.ctx.types.frozendict_type)
16241623
}) {
16251624
Some(dict) => {
16261625
for (key, val) in dict {

‎crates/vm/src/sequence.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub struct OptionalRangeArgs {
161161
#[pyarg(positional, default = 0)]
162162
start: PyObjectRef,
163163
// Platform ssize maximum; a growing list may reach beyond its initial length.
164-
#[pyarg(positional, optional, py_default = "9223372036854775807")]
164+
#[pyarg(positional, optional, py_default = "sys.maxsize")]
165165
stop: OptionalArg<PyObjectRef>,
166166
}
167167

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ pub(super) mod _os {
19231923
#[derive(FromArgs)]
19241924
struct UtimeArgs<'fd> {
19251925
path: OsPath,
1926-
#[pyarg(any, default)]
1926+
#[pyarg(any, default, py_default = "None")]
19271927
times: Option<PyTupleRef>,
19281928
#[pyarg(named, default)]
19291929
ns: Option<PyTupleRef>,

‎extra_tests/snippets/builtin_signature.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,25 @@
7373
assert chmod_signature.startswith("($module, /, path, mode, *, dir_fd=None"), (
7474
chmod_signature
7575
)
76+
77+
# Clinic keeps platform-dependent defaults symbolic rather than hard-coding
78+
# the 64-bit value. inspect resolves the symbol for the running interpreter.
79+
import sys
80+
81+
for sequence_type in (list, tuple):
82+
assert sequence_type.index.__text_signature__ == (
83+
"($self, value, start=0, stop=sys.maxsize, /)"
84+
)
85+
index_signature = inspect.signature(sequence_type.index)
86+
assert index_signature.parameters["stop"].default == sys.maxsize
87+
88+
assert str.maketrans.__text_signature__ == (
89+
"(x, y=<unrepresentable>, z=<unrepresentable>, /)"
90+
)
91+
92+
if hasattr(os, "utime"):
93+
# ns is deliberately unrepresentable; only times has a None default.
94+
assert " ".join(os.utime.__text_signature__.split()) == (
95+
"($module, /, path, times=None, *, ns=<unrepresentable>, "
96+
"dir_fd=None, follow_symlinks=True)"
97+
)

0 commit comments

Comments
 (0)