diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 09eefd422..34ecb45f1 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -46,8 +46,6 @@ class BoolTest(unittest.TestCase): self.assertEqual(complex(True), 1+0j) self.assertEqual(complex(True), True) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_math(self): self.assertEqual(+False, 0) self.assertIsNot(+False, False) diff --git a/vm/src/vm/vm_ops.rs b/vm/src/vm/vm_ops.rs index 09f849a1a..5235393a6 100644 --- a/vm/src/vm/vm_ops.rs +++ b/vm/src/vm/vm_ops.rs @@ -1,4 +1,5 @@ use super::VirtualMachine; +use crate::stdlib::warnings; use crate::{ builtins::{PyInt, PyIntRef, PyStr, PyStrRef}, object::{AsObject, PyObject, PyObjectRef, PyResult}, @@ -469,6 +470,17 @@ impl VirtualMachine { } pub fn _invert(&self, a: &PyObject) -> PyResult { + const STR: &str = "Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. \ + This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. \ + Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int."; + if a.fast_isinstance(self.ctx.types.bool_type) { + warnings::warn( + self.ctx.exceptions.deprecation_warning, + STR.to_owned(), + 1, + self, + )?; + } self.get_special_method(a, identifier!(self, __invert__))? .ok_or_else(|| self.new_unsupported_unary_error(a, "unary ~"))? .invoke((), self)