We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent db01a1d commit eafa0c0Copy full SHA for eafa0c0
crates/vm/src/builtins/int.rs
@@ -12,7 +12,8 @@ use crate::{
12
},
13
convert::{IntoPyException, ToPyObject, ToPyResult},
14
function::{
15
- ArgByteOrder, ArgIntoBool, FuncArgs, OptionalArg, PyArithmeticValue, PyComparisonValue,
+ ArgByteOrder, ArgIntoBool, FuncArgs, OptionalArg, OptionalOption, PyArithmeticValue,
16
+ PyComparisonValue,
17
18
protocol::{PyNumberMethods, handle_bytes_to_int_err},
19
types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
@@ -381,10 +382,10 @@ impl PyInt {
381
382
#[pymethod]
383
fn __round__(
384
zelf: PyRef<Self>,
- ndigits: OptionalArg<PyIntRef>,
385
+ ndigits: OptionalOption<PyIntRef>,
386
vm: &VirtualMachine,
387
) -> PyResult<PyRef<Self>> {
- if let OptionalArg::Present(ndigits) = ndigits {
388
+ if let Some(ndigits) = ndigits.flatten() {
389
let ndigits = ndigits.as_bigint();
390
// round(12345, -2) == 12300
391
// If precision >= 0, then any integer is already rounded correctly
extra_tests/snippets/builtin_int.py
@@ -318,8 +318,9 @@ def __int__(self):
318
assert isinstance((1).__round__(0), int)
319
assert (0).__round__(0) == 0
320
assert (1).__round__(0) == 1
321
-assert_raises(TypeError, lambda: (0).__round__(None))
322
-assert_raises(TypeError, lambda: (1).__round__(None))
+# Python 3.14+: __round__(None) is now allowed, same as __round__()
+assert (0).__round__(None) == 0
323
+assert (1).__round__(None) == 1
324
assert_raises(TypeError, lambda: (0).__round__(0.0))
325
assert_raises(TypeError, lambda: (1).__round__(0.0))
326
0 commit comments