Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 71458:c9ebae3285e3 3.2
None is ok for identifiers but not strings
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 22 Jul 2011 11:09:07 -0500 |
| parents | 08932ec9ddb1 |
| children | c8b6d4417274 d3f0f72c31f8 |
comparison
equal
deleted
inserted
replaced
| 71455:08932ec9ddb1 | 71458:c9ebae3285e3 |
|---|---|
| 598 Py_XINCREF(obj); | 598 Py_XINCREF(obj); |
| 599 *out = obj; | 599 *out = obj; |
| 600 return 0; | 600 return 0; |
| 601 } | 601 } |
| 602 | 602 |
| 603 static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, | 603 static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
| 604 const char *name) | 604 { |
| 605 { | 605 if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 606 if (!PyUnicode_CheckExact(name)) { | 606 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
| 607 PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); | |
| 608 return 1; | 607 return 1; |
| 609 } | 608 } |
| 610 return obj2ast_object(obj, out, arena); | 609 return obj2ast_object(obj, out, arena); |
| 611 } | 610 } |
| 612 | 611 |
| 613 static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) | |
| 614 { | |
| 615 return obj2ast_stringlike(obj, out, arena, "identifier"); | |
| 616 } | |
| 617 | |
| 618 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) | 612 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 619 { | 613 { |
| 620 return obj2ast_stringlike(obj, out, arena, "string"); | 614 if (!PyUnicode_CheckExact(obj)) { |
| 615 PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); | |
| 616 return 1; | |
| 617 } | |
| 618 return obj2ast_object(obj, out, arena); | |
| 621 } | 619 } |
| 622 | 620 |
| 623 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) | 621 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 624 { | 622 { |
| 625 int i; | 623 int i; |
