| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -4,6 +4,8 @@ | |
| from test.support import os_helper | ||
|
|
||
| import os | ||
| import re | ||
|
|
||
|
|
||
| class BoolTest(unittest.TestCase): | ||
|
|
||
| Expand Down Expand Up | @@ -58,22 +60,6 @@ def test_math(self): | |
| self.assertEqual(-True, -1) | ||
| self.assertEqual(abs(True), 1) | ||
| self.assertIsNot(abs(True), True) | ||
| with self.assertWarns(DeprecationWarning): | ||
| # We need to put the bool in a variable, because the constant | ||
| # ~False is evaluated at compile time due to constant folding; | ||
| # consequently the DeprecationWarning would be issued during | ||
| # module loading and not during test execution. | ||
| false = False | ||
| self.assertEqual(~false, -1) | ||
| with self.assertWarns(DeprecationWarning): | ||
| # also check that the warning is issued in case of constant | ||
| # folding at compile time | ||
| self.assertEqual(eval("~False"), -1) | ||
| with self.assertWarns(DeprecationWarning): | ||
| true = True | ||
| self.assertEqual(~true, -2) | ||
| with self.assertWarns(DeprecationWarning): | ||
| self.assertEqual(eval("~True"), -2) | ||
|
|
||
| self.assertEqual(False+2, 2) | ||
| self.assertEqual(True+2, 3) | ||
| Expand Down Expand Up | @@ -169,6 +155,25 @@ def test_math(self): | |
| self.assertIs(not True, False) | ||
| self.assertIs(not False, True) | ||
|
|
||
| def test_invert(self): | ||
| # See gh-149532 | ||
| msg = re.escape("bad operand type for unary ~: 'bool'") | ||
|
|
||
| # Check constants in case of a folding: | ||
| with self.assertRaisesRegex(TypeError, msg): | ||
| ~False | ||
| with self.assertRaisesRegex(TypeError, msg): | ||
| ~True | ||
|
|
||
| # Check variable: | ||
| for bool_val in [True, False]: | ||
| with self.subTest(bool_val), self.assertRaisesRegex(TypeError, msg): | ||
| ~bool_val | ||
|
|
||
| # Check `eval`: | ||
| with self.assertRaisesRegex(TypeError, msg): | ||
| eval("~False") | ||
|
Comment thread
Comment on lines
+160
to
+175
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCurious if those shouldn't be subtests
Sorry, something went wrong.
All reactions
|
||
|
|
||
| def test_convert(self): | ||
| self.assertRaises(TypeError, bool, 42, 42) | ||
| self.assertIs(bool(10), True) | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Remove :meth:`!bool.__invert__` magic method, which was deprecated since | ||
| 3.12. |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.