Skip to content

Commit 61d97d8

Browse files
youknowdotcodex
andauthored
Match sequence and timestamp signature metadata to Python 3.15 (#9742)
* 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 * Simplify utime default declaration Use the typed None default to generate the same Clinic signature without a redundant metadata override. Assisted-by: OpenAI Codex: model version not exposed --------- Co-authored-by: Codex <[email protected]>
1 parent d71d8e2 commit 61d97d8

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
@@ -1554,29 +1554,29 @@ impl Py<PyStr> {
15541554

15551555
#[pystaticmethod]
15561556
fn maketrans(
1557-
dict_or_str: PyObjectRef,
1558-
to_str: OptionalArg<PyStrRef>,
1559-
none_str: OptionalArg<PyStrRef>,
1557+
x: PyObjectRef,
1558+
y: OptionalArg<PyStrRef>,
1559+
z: OptionalArg<PyStrRef>,
15601560
vm: &VirtualMachine,
15611561
) -> PyResult {
15621562
let new_dict = vm.ctx.new_dict();
1563-
if let OptionalArg::Present(to_str) = to_str {
1564-
match dict_or_str.downcast::<PyStr>() {
1563+
if let OptionalArg::Present(y) = y {
1564+
match x.downcast::<PyStr>() {
15651565
Ok(from_str) => {
1566-
if to_str.len() == from_str.len() {
1566+
if y.len() == from_str.len() {
15671567
for (c1, c2) in from_str
15681568
.as_wtf8()
15691569
.code_points()
1570-
.zip(to_str.as_wtf8().code_points())
1570+
.zip(y.as_wtf8().code_points())
15711571
{
15721572
new_dict.set_item(
15731573
&*vm.new_pyobj(c1.to_u32()),
15741574
vm.new_pyobj(c2.to_u32()),
15751575
vm,
15761576
)?;
15771577
}
1578-
if let OptionalArg::Present(none_str) = none_str {
1579-
for c in none_str.as_wtf8().code_points() {
1578+
if let OptionalArg::Present(z) = z {
1579+
for c in z.as_wtf8().code_points() {
15801580
new_dict.set_item(&*vm.new_pyobj(c.to_u32()), vm.ctx.none(), vm)?;
15811581
}
15821582
}
@@ -1593,9 +1593,8 @@ impl Py<PyStr> {
15931593
}
15941594
} else {
15951595
// The single-argument form accepts exact dict and frozendict objects.
1596-
match PyAnyDict::from_object(&dict_or_str).filter(|_| {
1597-
dict_or_str.class().is(vm.ctx.types.dict_type)
1598-
|| dict_or_str.class().is(vm.ctx.types.frozendict_type)
1596+
match PyAnyDict::from_object(&x).filter(|_| {
1597+
x.class().is(vm.ctx.types.dict_type) || x.class().is(vm.ctx.types.frozendict_type)
15991598
}) {
16001599
Some(dict) => {
16011600
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 = 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
@@ -112,3 +112,25 @@
112112
assert zlib._ZlibDecompressor().decompress(zlib.compress(b"signature defaults")) == (
113113
b"signature defaults"
114114
)
115+
116+
# Clinic keeps platform-dependent defaults symbolic rather than hard-coding
117+
# the 64-bit value. inspect resolves the symbol for the running interpreter.
118+
import sys
119+
120+
for sequence_type in (list, tuple):
121+
assert sequence_type.index.__text_signature__ == (
122+
"($self, value, start=0, stop=sys.maxsize, /)"
123+
)
124+
index_signature = inspect.signature(sequence_type.index)
125+
assert index_signature.parameters["stop"].default == sys.maxsize
126+
127+
assert str.maketrans.__text_signature__ == (
128+
"(x, y=<unrepresentable>, z=<unrepresentable>, /)"
129+
)
130+
131+
if hasattr(os, "utime"):
132+
# ns is deliberately unrepresentable; only times has a None default.
133+
assert " ".join(os.utime.__text_signature__.split()) == (
134+
"($module, /, path, times=None, *, ns=<unrepresentable>, "
135+
"dir_fd=None, follow_symlinks=True)"
136+
)

0 commit comments

Comments
 (0)