[Python-checkins] cpython (3.2): accept bytes for the AST 'string' type

georg.brandl python-checkins at python.org
Sun Sep 4 08:42:33 CEST 2011


http://hg.python.org/cpython/rev/1ad7e71ebd5f
changeset:   72244:1ad7e71ebd5f
branch:      3.2
user:        Benjamin Peterson <benjamin at python.org>
date:        Wed Aug 31 22:13:03 2011 -0400
summary:
  accept bytes for the AST 'string' type

This is a temporary kludge and all is well in 3.3.

files:
  Misc/NEWS           |  3 +++
  Parser/asdl_c.py    |  2 +-
  Python/Python-ast.c |  2 +-
  3 files changed, 5 insertions(+), 2 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
 - Issue #12326: sys.platform is now always 'linux2' on Linux, even if Python
   is compiled on Linux 3.
 
+- Accept bytes for the AST string type. This is temporary until a proper fix in
+  3.3.
+
 Library
 -------
 
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -805,7 +805,7 @@
 
 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
 {
-    if (!PyUnicode_CheckExact(obj)) {
+    if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
         PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
         return 1;
     }
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -611,7 +611,7 @@
 
 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
 {
-    if (!PyUnicode_CheckExact(obj)) {
+    if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
         PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
         return 1;
     }

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


More information about the Python-checkins mailing list