Skip to content

Commit 8a4b42b

Browse files
committed
merge 3.2
2 parents 51a6b37 + 180e635 commit 8a4b42b

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

Parser/asdl_c.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -795,24 +795,22 @@ def visitModule(self, mod):
795795
return 0;
796796
}
797797
798-
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
799-
const char *name)
798+
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
800799
{
801-
if (!PyUnicode_CheckExact(name)) {
802-
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
800+
if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
801+
PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
803802
return 1;
804803
}
805804
return obj2ast_object(obj, out, arena);
806805
}
807806
808-
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
809-
{
810-
return obj2ast_stringlike(obj, out, arena, "identifier");
811-
}
812-
813807
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
814808
{
815-
return obj2ast_stringlike(obj, out, arena, "string");
809+
if (!PyUnicode_CheckExact(obj)) {
810+
PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
811+
return 1;
812+
}
813+
return obj2ast_object(obj, out, arena);
816814
}
817815
818816
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)

Python/Python-ast.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,24 +592,22 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
592592
return 0;
593593
}
594594

595-
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
596-
const char *name)
595+
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
597596
{
598-
if (!PyUnicode_CheckExact(name)) {
599-
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
597+
if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
598+
PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
600599
return 1;
601600
}
602601
return obj2ast_object(obj, out, arena);
603602
}
604603

605-
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
606-
{
607-
return obj2ast_stringlike(obj, out, arena, "identifier");
608-
}
609-
610604
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
611605
{
612-
return obj2ast_stringlike(obj, out, arena, "string");
606+
if (!PyUnicode_CheckExact(obj)) {
607+
PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
608+
return 1;
609+
}
610+
return obj2ast_object(obj, out, arena);
613611
}
614612

615613
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)

0 commit comments

Comments
 (0)