Skip to content

Commit bc535dd

Browse files
committed
Fix string repr in int invalid literal error
1 parent 27d7472 commit bc535dd

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/test/test_int.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,6 @@ def __trunc__(self):
479479
self.assertEqual(n, 1)
480480
self.assertIs(type(n), IntSubclass)
481481

482-
# TODO: RUSTPYTHON
483-
@unittest.expectedFailure
484482
def test_error_message(self):
485483
def check(s, base=None):
486484
with self.assertRaises(ValueError,

vm/src/obj/objint.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::objbyteinner::PyByteInner;
1111
use super::objbytes::PyBytes;
1212
use super::objfloat;
1313
use super::objmemory::PyMemoryView;
14-
use super::objstr::{PyString, PyStringRef};
14+
use super::objstr::{PyString, PyStringRef, PyStringRepr};
1515
use super::objtype::{self, PyClassRef};
1616
use crate::exceptions::PyBaseExceptionRef;
1717
use crate::format::FormatSpec;
@@ -864,8 +864,12 @@ fn detect_base(literal: &str) -> Option<u32> {
864864
}
865865

866866
fn invalid_literal(vm: &VirtualMachine, literal: &str, base: &BigInt) -> PyBaseExceptionRef {
867+
let literal = match PyStringRepr::try_from_str(literal, vm) {
868+
Ok(r) => r,
869+
Err(e) => return e,
870+
};
867871
vm.new_value_error(format!(
868-
"invalid literal for int() with base {}: '{}'",
872+
"invalid literal for int() with base {}: {}",
869873
base, literal
870874
))
871875
}

0 commit comments

Comments
 (0)