Skip to content

Commit e21a04c

Browse files
authored
Merge pull request RustPython#5635 from hbina/hbina-fix-py313-test-bool
Fixed an expected failure in the behavior of negating a bool argument
2 parents f0bcad7 + 8e70394 commit e21a04c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Lib/test/test_bool.py

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ def test_complex(self):
4646
self.assertEqual(complex(True), 1+0j)
4747
self.assertEqual(complex(True), True)
4848

49-
# TODO: RUSTPYTHON
50-
@unittest.expectedFailure
5149
def test_math(self):
5250
self.assertEqual(+False, 0)
5351
self.assertIsNot(+False, False)

vm/src/vm/vm_ops.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::VirtualMachine;
2+
use crate::stdlib::warnings;
23
use crate::{
34
builtins::{PyInt, PyIntRef, PyStr, PyStrRef},
45
object::{AsObject, PyObject, PyObjectRef, PyResult},
@@ -469,6 +470,17 @@ impl VirtualMachine {
469470
}
470471

471472
pub fn _invert(&self, a: &PyObject) -> PyResult {
473+
const STR: &str = "Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. \
474+
This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. \
475+
Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.";
476+
if a.fast_isinstance(self.ctx.types.bool_type) {
477+
warnings::warn(
478+
self.ctx.exceptions.deprecation_warning,
479+
STR.to_owned(),
480+
1,
481+
self,
482+
)?;
483+
}
472484
self.get_special_method(a, identifier!(self, __invert__))?
473485
.ok_or_else(|| self.new_unsupported_unary_error(a, "unary ~"))?
474486
.invoke((), self)

0 commit comments

Comments
 (0)