[Python-checkins] cpython (merge 3.4 -> default): Issue #21526: Fixed support of new boolean type in Tcl 8.5.

serhiy.storchaka python-checkins at python.org
Thu Apr 2 10:03:07 CEST 2015


https://hg.python.org/cpython/rev/b2413da7516f
changeset:   95370:b2413da7516f
parent:      95368:cf0cac11813d
parent:      95369:de3496cd609e
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Apr 02 10:58:40 2015 +0300
summary:
  Issue #21526: Fixed support of new boolean type in Tcl 8.5.

files:
  Lib/test/test_tcl.py |  15 +++++++++++++++
  Misc/NEWS            |   4 ++--
  Modules/_tkinter.c   |  23 +++++++++++++++++++----
  3 files changed, 36 insertions(+), 6 deletions(-)


diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -378,6 +378,21 @@
         if tcl_version >= (8, 5):
             check('2**64', True)
 
+    def test_booleans(self):
+        tcl = self.interp
+        def check(expr, expected):
+            result = tcl.call('expr', expr)
+            self.assertEqual(result, expected)
+            self.assertIsInstance(result, int)
+        check('true', True)
+        check('yes', True)
+        check('on', True)
+        check('false', False)
+        check('no', False)
+        check('off', False)
+        check('1 < 2', True)
+        check('1 > 2', False)
+
     def test_passing_values(self):
         def passValue(value):
             return self.interp.call('set', '_', value)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,8 @@
 Library
 -------
 
+- Issue #21526: Tkinter now supports new boolean type in Tcl 8.5.
+
 - Issue #23836: Fix the faulthandler module to handle reentrant calls to
   its signal handlers.
 
@@ -146,8 +148,6 @@
 
 - Issue #23252:  Added support for writing ZIP files to unseekable streams.
 
-- Issue #21526: Tkinter now supports new boolean type in Tcl 8.5.
-
 - Issue #23647: Increase impalib's MAXLINE to accommodate modern mailbox sizes.
 
 - Issue #23539: If body is None, http.client.HTTPConnection.request now sets
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -998,6 +998,15 @@
     }
 }
 
+static PyObject *
+fromBoolean(PyObject* tkapp, Tcl_Obj *value)
+{
+    int boolValue;
+    if (Tcl_GetBooleanFromObj(Tkapp_Interp(tkapp), value, &boolValue) == TCL_ERROR)
+        return Tkinter_Error(tkapp);
+    return PyBool_FromLong(boolValue);
+}
+
 static PyObject*
 FromObj(PyObject* tkapp, Tcl_Obj *value)
 {
@@ -1011,10 +1020,7 @@
 
     if (value->typePtr == app->BooleanType ||
         value->typePtr == app->OldBooleanType) {
-        int boolValue;
-        if (Tcl_GetBooleanFromObj(interp, value, &boolValue) == TCL_ERROR)
-            return Tkinter_Error(tkapp);
-        return PyBool_FromLong(boolValue);
+        return fromBoolean(tkapp, value);
     }
 
     if (value->typePtr == app->ByteArrayType) {
@@ -1069,6 +1075,15 @@
             Tcl_GetCharLength(value));
     }
 
+#if TK_VERSION_HEX >= 0x08050000
+    if (app->BooleanType == NULL &&
+        strcmp(value->typePtr->name, "booleanString") == 0) {
+        /* booleanString type is not registered in Tcl */
+        app->BooleanType = value->typePtr;
+        return fromBoolean(tkapp, value);
+    }
+#endif
+
     return newPyTclObject(value);
 }
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list