Skip to content

Commit b452f41

Browse files
Issue python#21526: Fixed support of new boolean type in Tcl 8.5.
2 parents 1399a01 + f7de3dd commit b452f41

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

Lib/test/test_tcl.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,21 @@ def check(expr, expected):
378378
if tcl_version >= (8, 5):
379379
check('2**64', True)
380380

381+
def test_booleans(self):
382+
tcl = self.interp
383+
def check(expr, expected):
384+
result = tcl.call('expr', expr)
385+
self.assertEqual(result, expected)
386+
self.assertIsInstance(result, int)
387+
check('true', True)
388+
check('yes', True)
389+
check('on', True)
390+
check('false', False)
391+
check('no', False)
392+
check('off', False)
393+
check('1 < 2', True)
394+
check('1 > 2', False)
395+
381396
def test_passing_values(self):
382397
def passValue(value):
383398
return self.interp.call('set', '_', value)

Misc/NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Core and Builtins
1616
Library
1717
-------
1818

19+
- Issue #21526: Tkinter now supports new boolean type in Tcl 8.5.
20+
1921
- Issue #23836: Fix the faulthandler module to handle reentrant calls to
2022
its signal handlers.
2123

@@ -146,8 +148,6 @@ Library
146148

147149
- Issue #23252: Added support for writing ZIP files to unseekable streams.
148150

149-
- Issue #21526: Tkinter now supports new boolean type in Tcl 8.5.
150-
151151
- Issue #23647: Increase impalib's MAXLINE to accommodate modern mailbox sizes.
152152

153153
- Issue #23539: If body is None, http.client.HTTPConnection.request now sets

Modules/_tkinter.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,15 @@ AsObj(PyObject *value)
998998
}
999999
}
10001000

1001+
static PyObject *
1002+
fromBoolean(PyObject* tkapp, Tcl_Obj *value)
1003+
{
1004+
int boolValue;
1005+
if (Tcl_GetBooleanFromObj(Tkapp_Interp(tkapp), value, &boolValue) == TCL_ERROR)
1006+
return Tkinter_Error(tkapp);
1007+
return PyBool_FromLong(boolValue);
1008+
}
1009+
10011010
static PyObject*
10021011
FromObj(PyObject* tkapp, Tcl_Obj *value)
10031012
{
@@ -1011,10 +1020,7 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
10111020

10121021
if (value->typePtr == app->BooleanType ||
10131022
value->typePtr == app->OldBooleanType) {
1014-
int boolValue;
1015-
if (Tcl_GetBooleanFromObj(interp, value, &boolValue) == TCL_ERROR)
1016-
return Tkinter_Error(tkapp);
1017-
return PyBool_FromLong(boolValue);
1023+
return fromBoolean(tkapp, value);
10181024
}
10191025

10201026
if (value->typePtr == app->ByteArrayType) {
@@ -1069,6 +1075,15 @@ FromObj(PyObject* tkapp, Tcl_Obj *value)
10691075
Tcl_GetCharLength(value));
10701076
}
10711077

1078+
#if TK_VERSION_HEX >= 0x08050000
1079+
if (app->BooleanType == NULL &&
1080+
strcmp(value->typePtr->name, "booleanString") == 0) {
1081+
/* booleanString type is not registered in Tcl */
1082+
app->BooleanType = value->typePtr;
1083+
return fromBoolean(tkapp, value);
1084+
}
1085+
#endif
1086+
10721087
return newPyTclObject(value);
10731088
}
10741089

0 commit comments

Comments
 (0)