mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
type check AST strings and identifiers
This is related to a21829180423 as well as #12609 and #12610.
This commit is contained in:
parent
996f606787
commit
2193d2b72b
4 changed files with 57 additions and 6 deletions
|
@ -794,8 +794,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define obj2ast_identifier obj2ast_object
|
||||
#define obj2ast_string obj2ast_object
|
||||
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
|
||||
const char *name)
|
||||
{
|
||||
if (!PyUnicode_CheckExact(name)) {
|
||||
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
|
||||
return 1;
|
||||
}
|
||||
return obj2ast_object(obj, out, arena);
|
||||
}
|
||||
|
||||
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
return obj2ast_stringlike(obj, out, arena, "identifier");
|
||||
}
|
||||
|
||||
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
return obj2ast_stringlike(obj, out, arena, "string");
|
||||
}
|
||||
|
||||
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue