Skip to content

Commit 45c1a00

Browse files
JamesClarke7283youknowone
authored andcommitted
Port the remaining runtime fixes from #7993
- bytearray: keep the buffer exported while converting the needle of find/count/index/rfind/rindex/__contains__/split/rsplit and the hex separator, so resizing from there raises BufferError - str(): report non-str encoding/errors as "str() argument 'X' must be str, not T", and check argument counts and name/position duplicates for keyword calls - hashlib/blake2: reject data given both by name and by position - _json.scanstring: take end as a signed integer and raise ValueError when it is out of bounds - _sre: take pos/endpos as signed integers, clamping negatives to 0 - lzma: reject filter specs with keys the filter does not take - mmap: raise ValueError when growing a shared anonymous mapping on Linux/NetBSD - _sqlite3: check that the backup progress argument is callable - Remove the expectedFailure markers of the tests these fix Assisted-by: Claude Code:claude-opus-5-5
1 parent a403341 commit 45c1a00

23 files changed

Lines changed: 353 additions & 104 deletions

‎Lib/test/test_bytes.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,6 @@ def __index__(self):
20132013
self.assertEqual(instance.ba[0], ord("?"), "Assigned bytearray not altered")
20142014
self.assertEqual(instance.new_ba, bytearray(0x180), "Wrong object altered")
20152015

2016-
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: unexpected type Evil
20172016
def test_search_methods_reentrancy_raises_buffererror(self):
20182017
# gh-142560: Raise BufferError if buffer mutates during search arg conversion.
20192018
class Evil:
@@ -2063,7 +2062,6 @@ def __length_hint__(self):
20632062

20642063
self.assertRaises(ValueError, float, bytearray())
20652064

2066-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: BufferError not raised by hex
20672065
def test_hex_use_after_free(self):
20682066
# Prevent UAF in bytearray.hex(sep) with re-entrant sep.__len__.
20692067
# Regression test for https://github.com/python/cpython/issues/143195.

‎Lib/test/test_enum.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3036,7 +3036,6 @@ class ThirdFailedStrEnum(StrEnum):
30363036
one = '1'
30373037
two = b'2', 'ascii', 9
30383038

3039-
@unittest.expectedFailure # TODO: RUSTPYTHON; fails on encoding testing : TypeError: Expected type 'str' but 'builtin_function_or_method' found
30403039
def test_custom_strenum(self):
30413040
class CustomStrEnum(str, Enum):
30423041
pass

‎Lib/test/test_hashlib.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ def test_clinic_signature(self):
275275
self._hashlib.new(digest_name, data=b'')
276276
self._hashlib.new(digest_name, string=b'')
277277

278-
@unittest.expectedFailure # TODO: RUSTPYTHON; duplicate positional/keyword arg error message differs
279278
@unittest.skipIf(get_fips_mode(), "skip in FIPS mode")
280279
def test_clinic_signature_errors(self):
281280
nomsg = b''

‎Lib/test/test_json/test_scanstring.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def test_bad_escapes(self):
144144
with self.assertRaises(self.JSONDecodeError, msg=s):
145145
scanstring(s, 1, True)
146146

147-
@unittest.expectedFailure # TODO: RUSTPYTHON
148147
def test_overflow(self):
149148
with self.assertRaises(OverflowError):
150149
self.json.decoder.scanstring("xxx", sys.maxsize+1)

‎Lib/test/test_lzma.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def test_simple_bad_args(self):
6363
lzd.decompress(empty)
6464
self.assertRaises(EOFError, lzd.decompress, b"quux")
6565

66-
@unittest.expectedFailure # TODO: RUSTPYTHON; lzma.LZMAError: Failed to initialize encoder
6766
def test_bad_filter_spec(self):
6867
self.assertRaises(TypeError, LZMACompressor, filters=[b"wobsite"])
6968
self.assertRaises(ValueError, LZMACompressor, filters=[{"xyzzy": 3}])
@@ -674,7 +673,6 @@ def test_init_bad_preset(self):
674673
with self.assertRaises(ValueError):
675674
LZMAFile(BytesIO(COMPRESSED_XZ), preset=3)
676675

677-
@unittest.expectedFailure # TODO: RUSTPYTHON; lzma.LZMAError: Failed to initialize encoder
678676
def test_init_bad_filter_spec(self):
679677
with self.assertRaises(TypeError):
680678
LZMAFile(BytesIO(), "w", filters=[b"wobsite"])

‎Lib/test/test_mmap.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,6 @@ def __index__(self):
925925
self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, Number()), None)
926926
self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, size), None)
927927

928-
@unittest.expectedFailureIf(sys.platform in ("linux", "win32"), "TODO: RUSTPYTHON")
929928
def test_resize_up_anonymous_mapping(self):
930929
"""If the mmap is backed by the pagefile ensure a resize up can happen
931930
and that the original data is still in place

‎Lib/test/test_sqlite3/test_backup.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def progress(status, remaining, total):
103103
self.assertEqual(len(journal), 1)
104104
self.assertEqual(journal[0], 0)
105105

106-
@unittest.expectedFailure # TODO: RUSTPYTHON
107106
def test_non_callable_progress(self):
108107
with self.assertRaises(TypeError) as cm:
109108
with memory_database() as bck:

‎Lib/test/test_str.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,6 @@ def test_check_encoding_errors(self):
26722672
proc = assert_python_failure('-X', 'dev', '-c', code)
26732673
self.assertEqual(proc.rc, 10, proc)
26742674

2675-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: "str expected at most 3 arguments, got 4" does not match "expected at most 3 arguments, got 4"
26762675
def test_str_invalid_call(self):
26772676
# too many args
26782677
with self.assertRaisesRegex(TypeError, r"str expected at most 3 arguments, got 4"):

‎crates/stdlib/src/_sqlite3.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ mod _sqlite3 {
397397
#[pyarg(named, default = -1)]
398398
pages: c_int,
399399
#[pyarg(named, optional)]
400-
progress: Option<ArgCallable>,
400+
progress: Option<PyObjectRef>,
401401
#[pyarg(named, optional)]
402402
name: Option<PyStrRef>,
403403
#[pyarg(named, default = 0.250)]
@@ -1253,6 +1253,12 @@ mod _sqlite3 {
12531253
return Err(vm.new_value_error("target cannot be the same connection instance"));
12541254
}
12551255

1256+
if let Some(progress) = &progress
1257+
&& !progress.is_callable()
1258+
{
1259+
return Err(vm.new_type_error("progress argument must be a callable"));
1260+
}
1261+
12561262
let pages = if pages == 0 { -1 } else { pages };
12571263

12581264
let name_cstring;
@@ -1284,7 +1290,7 @@ mod _sqlite3 {
12841290
if let Some(progress) = &progress {
12851291
let remaining = unsafe { sqlite3_backup_remaining(handle) };
12861292
let pagecount = unsafe { sqlite3_backup_pagecount(handle) };
1287-
if let Err(err) = progress.invoke((ret, remaining, pagecount), vm) {
1293+
if let Err(err) = progress.call((ret, remaining, pagecount), vm) {
12881294
unsafe { sqlite3_backup_finish(handle) };
12891295
return Err(err);
12901296
}

‎crates/stdlib/src/blake2.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ pub(crate) use _blake2::module_def;
44

55
#[pymodule]
66
mod _blake2 {
7-
use crate::hashlib::_hashlib::{Blake2Hash, BlakeHashArgs, local_blake2b, local_blake2s};
7+
use crate::hashlib::_hashlib::{
8+
Blake2Hash, BlakeHashArgs, bind_hash_args, local_blake2b, local_blake2s,
9+
};
810
use crate::vm::{
911
Context, Py, PyPayload, PyResult, VirtualMachine,
1012
builtins::{PyBytes, PyIntRef, PyModule, PyType, PyTypeRef},
@@ -149,7 +151,7 @@ mod _blake2 {
149151

150152
#[pyslot]
151153
fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
152-
let args: BlakeHashArgs = args.bind(vm)?;
154+
let args: BlakeHashArgs = bind_hash_args("blake2b", 1, args, vm)?;
153155
Ok(Self {
154156
inner: local_blake2b(args, vm)?,
155157
}
@@ -246,7 +248,7 @@ mod _blake2 {
246248

247249
#[pyslot]
248250
fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
249-
let args: BlakeHashArgs = args.bind(vm)?;
251+
let args: BlakeHashArgs = bind_hash_args("blake2s", 1, args, vm)?;
250252
Ok(Self {
251253
inner: local_blake2s(args, vm)?,
252254
}

0 commit comments

Comments
 (0)