From 315284a726d4fd58ea003164d3ff8327477d94a1 Mon Sep 17 00:00:00 2001 From: Changjoon Date: Tue, 28 Apr 2026 21:10:42 +0900 Subject: [PATCH] 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. --- Lib/test/test_int.py | 1 - crates/vm/src/protocol/number.rs | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index e61b1c657..a18683098 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -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: diff --git a/crates/vm/src/protocol/number.rs b/crates/vm/src/protocol/number.rs index eaf04d9a0..a5b35d88c 100644 --- a/crates/vm/src/protocol/number.rs +++ b/crates/vm/src/protocol/number.rs @@ -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::() { try_convert(self, s.as_wtf8().trim().as_bytes(), vm) } else if let Some(bytes) = self.downcast_ref::() {