Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e21a04c

Browse filesBrowse files
authored
Merge pull request #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
Copy full SHA for e21a04c

File tree

Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed

‎Lib/test/test_bool.py

Copy file name to clipboardExpand all lines: Lib/test/test_bool.py
-2Lines 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

Copy file name to clipboardExpand all lines: vm/src/vm/vm_ops.rs
+12Lines 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: &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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.