mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Drop int() delegation to __trunc__ (#7703)
CPython 3.14 fully removed the long-deprecated fallback from int() to __trunc__. Classes that want int(x) support must implement __int__ or __index__; math.trunc(x) continues to use __trunc__. Delete the __trunc__ branch in PyObject::try_int so a class with only __trunc__ now reaches the existing TypeError arm, matching CPython. Unmasks test_int.IntTestCases.test_intconversion.
This commit is contained in:
1 parent
656ff08420
commit
315284a726
2 files changed
-15
No files matched your search
Vendored
-1
@@ -380,7 +380,6 @@ class IntTestCases(unittest.TestCase):
|
||||
def test_string_float(self):
|
||||
self.assertRaises(ValueError, int, '1.2')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: TypeError not raised
|
||||
def test_intconversion(self):
|
||||
# Test __int__()
|
||||
class ClassicMissingMethods:
|
||||
|
||||
@@ -58,20 +58,6 @@ impl PyObject {
|
||||
Ok(i.to_owned())
|
||||
} else if let Some(i) = self.number().int(vm).or_else(|| self.try_index_opt(vm)) {
|
||||
i
|
||||
} else if let Ok(Some(f)) = vm.get_special_method(self, identifier!(vm, __trunc__)) {
|
||||
_warnings::warn(
|
||||
vm.ctx.exceptions.deprecation_warning,
|
||||
"The delegation of int() to __trunc__ is deprecated.".to_owned(),
|
||||
1,
|
||||
vm,
|
||||
)?;
|
||||
let ret = f.invoke((), vm)?;
|
||||
ret.try_index(vm).map_err(|_| {
|
||||
vm.new_type_error(format!(
|
||||
"__trunc__ returned non-Integral (type {})",
|
||||
ret.class()
|
||||
))
|
||||
})
|
||||
} else if let Some(s) = self.downcast_ref::<PyStr>() {
|
||||
try_convert(self, s.as_wtf8().trim().as_bytes(), vm)
|
||||
} else if let Some(bytes) = self.downcast_ref::<PyBytes>() {
|
||||
|
||||
Reference in new issue
Block a user