mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #5635 from hbina/hbina-fix-py313-test-bool
Fixed an expected failure in the behavior of negating a bool argument
This commit is contained in:
2 files changed
+12
-2
No files matched your search
Vendored
-2
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user