Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0224d4e

Browse files
committed
accept bytes for the AST 'string' type
This is a temporary kludge and all is well in 3.3.
1 parent 48e484f commit 0224d4e

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Accept bytes for the AST string type. This is temporary until a proper fix in
14+
3.3.
15+
1316
- Issue #9200: The str.is* methods now work with strings that contain non-BMP
1417
characters even in narrow Unicode builds.
1518

Parser/asdl_c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def visitModule(self, mod):
805805
806806
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
807807
{
808-
if (!PyUnicode_CheckExact(obj)) {
808+
if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
809809
PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
810810
return 1;
811811
}

Python/Python-ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
611611

612612
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
613613
{
614-
if (!PyUnicode_CheckExact(obj)) {
614+
if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
615615
PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
616616
return 1;
617617
}

0 commit comments

Comments
 (0)