8000 Fixed an expected failure in the behavior of negating a bool argument · hbina/RustPython@14b9178 · GitHub
Skip to content

Commit 14b9178

Browse files
committed
Fixed an expected failure in the behavior of negating a bool argument
Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
1 parent 97853bf commit 14b9178

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Lib/test/test_bool.py

Lines changed: 0 additions & 2 deletions
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

Lines changed: 12 additions & 0 deletions
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: &'static 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)
0