Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 46193:b0bf06d49647 legacy-trunk
Properly check for consistency with the third argument of
compile() when compiling an AST node.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sat, 29 Mar 2008 13:24:23 +0000 |
| parents | 1b5b6abb1f2e |
| children | 2ff88ae9850c |
comparison
equal
deleted
inserted
replaced
| 46192:6e02ff0bd6f8 | 46193:b0bf06d49647 |
|---|---|
| 5942 { | 5942 { |
| 5943 init_types(); | 5943 init_types(); |
| 5944 return ast2obj_mod(t); | 5944 return ast2obj_mod(t); |
| 5945 } | 5945 } |
| 5946 | 5946 |
| 5947 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena) | 5947 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 5948 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) | |
| 5948 { | 5949 { |
| 5949 mod_ty res; | 5950 mod_ty res; |
| 5951 PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, | |
| 5952 (PyObject*)Interactive_type}; | |
| 5953 char *req_name[] = {"Module", "Expression", "Interactive"}; | |
| 5954 assert(0 <= mode && mode <= 2); | |
| 5955 | |
| 5950 init_types(); | 5956 init_types(); |
| 5951 if (!PyObject_IsInstance(ast, (PyObject*)mod_type)) { | 5957 |
| 5952 PyErr_SetString(PyExc_TypeError, "expected either Module, Interactive " | 5958 if (!PyObject_IsInstance(ast, req_type[mode])) { |
| 5953 "or Expression node"); | 5959 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
| 5960 req_name[mode], Py_TYPE(ast)->tp_name); | |
| 5954 return NULL; | 5961 return NULL; |
| 5955 } | 5962 } |
| 5956 if (obj2ast_mod(ast, &res, arena) != 0) | 5963 if (obj2ast_mod(ast, &res, arena) != 0) |
| 5957 return NULL; | 5964 return NULL; |
| 5958 else | 5965 else |
