8000 gh-109218: Deprecate weird cases in the complex() constructor by serhiy-storchaka · Pull Request #119620 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-109218: Deprecate weird cases in the complex() constructor #119620

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

Merged
merged 13 commits into from
May 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more tests.
  • Loading branch information
serhiy-storchaka committed May 28, 2024
commit e8b6ba9a94fa521b395cfcf9ad476e366de24a22
14 changes: 12 additions & 2 deletions Lib/test/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ def check(z, x, y):
check(complex(0j, 4.25j), -4.25, 0.0)

check(complex(real=4.25), 4.25, 0.0)
check(complex(real=4.25+0j), 4.25, 0.0)
check(complex(real=4.25+1.5j), 4.25, 1.5)
check(complex(imag=1.5), 0.0, 1.5)
check(complex(real=4.25, imag=1.5), 4.25, 1.5)
check(complex(4.25, imag=1.5), 4.25, 1.5)
Expand All @@ -413,8 +415,13 @@ def check(z, x, y):

c = complex(4.25, 1.5)
self.assertIs(complex(c), c)
self.assertIsNot(ComplexSubclass(c), c)
del c
c2 = ComplexSubclass(c)
self.assertEqual(c2, c)
self.assertIs(type(c2), ComplexSubclass)
c2 = ComplexSubclass(real=c)
self.assertEqual(c2, c)
self.assertIs(type(c2), ComplexSubclass)
del c, c2

self.assertRaisesRegex(TypeError,
"first argument must be a string or a number, not 'dict'",
Expand All @@ -439,6 +446,9 @@ def check(z, x, y):
self.assertRaises(TypeError, complex, MockComplex(1))
self.assertRaises(TypeError, complex, MockComplex(None))
self.assertRaises(TypeError, complex, MockComplex(4.25+0j), object())
self.assertRaises(TypeError, complex, MockComplex(1.5), object())
self.assertRaises(TypeError, complex, MockComplex(1), object())
self.assertRaises(TypeError, complex, MockComplex(None), object())

class EvilExc(Exception):
pass
Expand Down
Loading
0