Skip to content

Commit ea134da

Browse files
Issue python#16840: Tkinter now supports 64-bit integers added in Tcl 8.4 and
arbitrary precision integers added in Tcl 8.5.
1 parent 8e44aa5 commit ea134da

3 files changed

Lines changed: 248 additions & 23 deletions

File tree

‎Lib/test/test_tcl.py‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,22 @@ def testUnsetVarException(self):
133133
tcl = self.interp
134134
self.assertRaises(TclError,tcl.unsetvar,'a')
135135

136+
def get_integers(self):
137+
integers = (0, 1, -1, 2**31-1, -2**31)
138+
if tcl_version >= (8, 4): # wideInt was added in Tcl 8.4
139+
integers += (2**31, -2**31-1, 2**63-1, -2**63)
140+
if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
141+
integers += (2**63, -2**63-1, 2**1000, -2**1000)
142+
return integers
143+
136144
def test_getint(self):
137145
tcl = self.interp.tk
138-
self.assertEqual(tcl.getint(' 42 '), 42)
146+
for i in self.get_integers():
147+
self.assertEqual(tcl.getint(' %d ' % i), i)
148+
self.assertEqual(tcl.getint(' %#o ' % i), i)
149+
self.assertEqual(tcl.getint(' %#x ' % i), i)
150+
if tcl_version < (8, 5): # bignum was added in Tcl 8.5
151+
self.assertRaises(TclError, tcl.getint, str(2**1000))
139152
self.assertEqual(tcl.getint(42), 42)
140153
self.assertRaises(TypeError, tcl.getint)
141154
self.assertRaises(TypeError, tcl.getint, '42', '10')
@@ -270,7 +283,7 @@ def check(expr, expected):
270283
check('"a\xbd\u20ac"', 'a\xbd\u20ac')
271284
check(r'"a\xbd\u20ac"', 'a\xbd\u20ac')
272285
check(r'"a\0b"', 'a\x00b')
273-
if tcl_version >= (8, 5):
286+
if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
274287
check('2**64', str(2**64))
275288

276289
def test_exprdouble(self):
@@ -302,7 +315,7 @@ def check(expr, expected):
302315
check('[string length "a\xbd\u20ac"]', 3.0)
303316
check(r'[string length "a\xbd\u20ac"]', 3.0)
304317
self.assertRaises(TclError, tcl.exprdouble, '"abc"')
305-
if tcl_version >= (8, 5):
318+
if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
306319
check('2**64', float(2**64))
307320

308321
def test_exprlong(self):
@@ -334,7 +347,7 @@ def check(expr, expected):
334347
check('[string length "a\xbd\u20ac"]', 3)
335348
check(r'[string length "a\xbd\u20ac"]', 3)
336349
self.assertRaises(TclError, tcl.exprlong, '"abc"')
337-
if tcl_version >= (8, 5):
350+
if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
338351
self.assertRaises(TclError, tcl.exprlong, '2**64')
339352

340353
def test_exprboolean(self):
@@ -375,7 +388,7 @@ def check(expr, expected):
375388
check('[string length "a\xbd\u20ac"]', True)
376389
check(r'[string length "a\xbd\u20ac"]', True)
377390
self.assertRaises(TclError, tcl.exprboolean, '"abc"')
378-
if tcl_version >= (8, 5):
391+
if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
379392
check('2**64', True)
380393

381394
def test_booleans(self):
@@ -397,6 +410,21 @@ def check(expr, expected):
397410
check('1 < 2', True)
398411
check('1 > 2', False)
399412

413+
def test_expr_bignum(self):
414+
tcl = self.interp
415+
for i in self.get_integers():
416+
result = tcl.call('expr', str(i))
417+
if self.wantobjects:
418+
self.assertEqual(result, i)
419+
self.assertIsInstance(result, int)
420+
else:
421+
self.assertEqual(result, str(i))
422+
self.assertIsInstance(result, str)
423+
if tcl_version < (8, 5): # bignum was added in Tcl 8.5
424+
result = tcl.call('expr', str(2**1000))
425+
self.assertEqual(result, str(2**1000))
426+
self.assertIsInstance(result, str)
427+
400428
def test_passing_values(self):
401429
def passValue(value):
402430
return self.interp.call('set', '_', value)
@@ -414,8 +442,10 @@ def passValue(value):
414442
b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80ing')
415443
self.assertEqual(passValue(b'str\xbding'),
416444
b'str\xbding' if self.wantobjects else 'str\xbding')
417-
for i in (0, 1, -1, 2**31-1, -2**31):
445+
for i in self.get_integers():
418446
self.assertEqual(passValue(i), i if self.wantobjects else str(i))
447+
if tcl_version < (8, 5): # bignum was added in Tcl 8.5
448+
self.assertEqual(passValue(2**1000), str(2**1000))
419449
for f in (0.0, 1.0, -1.0, 1/3,
420450
sys.float_info.min, sys.float_info.max,
421451
-sys.float_info.min, -sys.float_info.max):
@@ -473,8 +503,10 @@ def float_eq(actual, expected):
473503
check(b'str\x00ing', 'str\x00ing')
474504
check(b'str\xc0\x80ing', 'str\xc0\x80ing')
475505
check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
476-
for i in (0, 1, -1, 2**31-1, -2**31):
506+
for i in self.get_integers():
477507
check(i, str(i))
508+
if tcl_version < (8, 5): # bignum was added in Tcl 8.5
509+
check(2**1000, str(2**1000))
478510
for f in (0.0, 1.0, -1.0):
479511
check(f, repr(f))
480512
for f in (1/3.0, sys.float_info.min, sys.float_info.max,

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #16840: Tkinter now supports 64-bit integers added in Tcl 8.4 and
28+
arbitrary precision integers added in Tcl 8.5.
29+
2730
- Issue #23834: Fix socket.sendto(), use the C Py_ssize_t type to store the
2831
result of sendto() instead of the C int type.
2932

0 commit comments

Comments
 (0)