10000 gh-122982: Prohibit bitwise inversion on bool type by Eclips4 · Pull Request #122983 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-122982: Prohibit bitwise inversion on bool type #122983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Add more test cases
  • Loading branch information
Eclips4 committed Aug 14, 2024
commit a8fdf662373b42a4b78bec7b1519b333332295fc
11 changes: 11 additions & 0 deletions Lib/test/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ def test_math(self):
self.assertEqual(abs(True), 1)
self.assertIsNot(abs(True), True)

# Bitwise inversion is prohibited on bool type.
with self.assertRaises(TypeError):
~True
with self.assertRaises(TypeError):
~False
with self.assertRaises(TypeError):
true = True
~true
with self.assertRaises(TypeError):
false = False
~false
with self.assertRaises(TypeError):
eval("~True")
with self.assertRaises(TypeError):
eval("~False")

self.assertEqual(False+2, 2)
self.assertEqual(True+2, 3)
Expand Down
Loading
0