summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-12 07:37:58 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-12 07:37:58 (GMT)
commitea36c941a1b2ad6582a35bc42aa70da9600d2841 (patch)
treee915477a42189e490044a15d786a18382064bc1f /Lib/test/test_long.py
parent9de7efe5ab40c19775dcc9ca88adf58d906fc53d (diff)
downloadcpython-ea36c941a1b2ad6582a35bc42aa70da9600d2841.zip
cpython-ea36c941a1b2ad6582a35bc42aa70da9600d2841.tar.gz
cpython-ea36c941a1b2ad6582a35bc42aa70da9600d2841.tar.bz2
Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r--Lib/test/test_long.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 62e69a9..b2d008b 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1203,6 +1203,23 @@ class LongTest(unittest.TestCase):
self.assertRaises(TypeError, myint.from_bytes, 0, 'big')
self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
+ class myint2(int):
+ def __new__(cls, value):
+ return int.__new__(cls, value + 1)
+
+ i = myint2.from_bytes(b'\x01', 'big')
+ self.assertIs(type(i), myint2)
+ self.assertEqual(i, 2)
+
+ class myint3(int):
+ def __init__(self, value):
+ self.foo = 'bar'
+
+ i = myint3.from_bytes(b'\x01', 'big')
+ self.assertIs(type(i), myint3)
+ self.assertEqual(i, 1)
+ self.assertEqual(getattr(i, 'foo', 'none'), 'bar')
+
def test_access_to_nonexistent_digit_0(self):
# http://bugs.python.org/issue14630: A bug in _PyLong_Copy meant that
# ob_digit[0] was being incorrectly accessed for instances of a