diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-06-02 00:05:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-02 00:05:48 +0300 |
commit | bdbad71b9def0b86433de12cecca022eee91bd9f (patch) | |
tree | 147c8a3e08454a95e0e4900388d88f7b65430f63 /Lib/test/test_float.py | |
parent | 1a4d9ffa1aecd7e750195f2be06d3d16c7a3a88f (diff) | |
download | cpython-git-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.gz |
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r-- | Lib/test/test_float.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 5278d716de..b656582538 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -223,6 +223,21 @@ class GeneralFloatCases(unittest.TestCase): with self.assertWarns(DeprecationWarning): self.assertIs(type(FloatSubclass(F())), FloatSubclass) + class MyIndex: + def __init__(self, value): + self.value = value + def __index__(self): + return self.value + + self.assertEqual(float(MyIndex(42)), 42.0) + self.assertRaises(OverflowError, float, MyIndex(2**2000)) + + class MyInt: + def __int__(self): + return 42 + + self.assertRaises(TypeError, float, MyInt()) + def test_keyword_args(self): with self.assertRaisesRegex(TypeError, 'keyword argument'): float(x='3.14') |