Skip to content

Commit 2eea557

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 the argument count for keyword calls - FuncArgs::bind_for: report a keyword that fills a parameter already given by position before other binding errors; getargs shares the message - blake2b/blake2s: name the constructor in argument errors - _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 f9ebb23 commit 2eea557

20 files changed

Lines changed: 283 additions & 70 deletions

File tree

‎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
@@ -924,7 +924,6 @@ def __index__(self):
924924
self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, Number()), None)
925925
self.assertEqual(m.madvise(mmap.MADV_NORMAL, 0, size), None)
926926

927-
@unittest.expectedFailureIf(sys.platform in ("linux", "win32"), "TODO: RUSTPYTHON")
928927
def test_resize_up_anonymous_mapping(self):
929928
"""If the mmap is backed by the pagefile ensure a resize up can happen
930929
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod _blake2 {
149149

150150
#[pyslot]
151151
fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
152-
let args: BlakeHashArgs = args.bind(vm)?;
152+
let args: BlakeHashArgs = args.bind_for(vm, "blake2b")?;
153153
Ok(Self {
154154
inner: local_blake2b(args, vm)?,
155155
}
@@ -246,7 +246,7 @@ mod _blake2 {
246246

247247
#[pyslot]
248248
fn slot_new(_cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
249-
let args: BlakeHashArgs = args.bind(vm)?;
249+
let args: BlakeHashArgs = args.bind_for(vm, "blake2s")?;
250250
Ok(Self {
251251
inner: local_blake2s(args, vm)?,
252252
}

0 commit comments

Comments
 (0)