Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Include/asdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

typedef PyObject * identifier;
typedef PyObject * string;
typedef PyObject * bytes;
typedef PyObject * object;
typedef PyObject * singleton;
typedef PyObject * constant;

/* It would be nice if the code generated by asdl_c.py was completely
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def test_empty_yield_from(self):
empty_yield_from.body[0].body[0].value.value = None
with self.assertRaises(ValueError) as cm:
compile(empty_yield_from, "<test>", "exec")
self.assertIn("field value is required", str(cm.exception))
self.assertIn("field 'value' is required", str(cm.exception))

@support.cpython_only
def test_issue31592(self):
Expand Down
3 changes: 1 addition & 2 deletions Parser/asdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
# See the EBNF at the top of the file to understand the logical connection
# between the various node types.

builtin_types = {'identifier', 'string', 'bytes', 'int', 'object', 'singleton',
'constant'}
builtin_types = {'identifier', 'string', 'int', 'constant'}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update also a comment in Parser/Python.asdl.

I am wondering, should we keep constant or object?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neither of them are defined in ASDL spec, but I guess constant is more explicit about its job then object. So I'd go for keeping it as is, and using constant

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case we keep ast2obj_object() and obj2ast_object().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because others are a symlink to it. Do you want me to change constant with object, or is it OK this way?


class AST:
def __repr__(self):
Expand Down
9 changes: 2 additions & 7 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def emit(s, depth=0, reflow=True):
if not opt and argtype != "int":
emit("if (!%s) {" % argname, 1)
emit("PyErr_SetString(PyExc_ValueError,", 2)
msg = "field %s is required for %s" % (argname, name)
msg = "field '%s' is required for %s" % (argname, name)
emit(' "%s");' % msg,
2, reflow=False)
emit('return NULL;', 2)
Expand Down Expand Up @@ -853,11 +853,9 @@ def visitModule(self, mod):
Py_INCREF((PyObject*)o);
return (PyObject*)o;
}
#define ast2obj_singleton ast2obj_object
#define ast2obj_constant ast2obj_object
#define ast2obj_identifier ast2obj_object
#define ast2obj_string ast2obj_object
#define ast2obj_bytes ast2obj_object

static PyObject* ast2obj_int(long b)
{
Expand Down Expand Up @@ -1148,10 +1146,7 @@ def simpleSum(self, sum, name):
self.emit("Py_INCREF(astmodulestate_global->%s_singleton);" % t.name, 3)
self.emit("return astmodulestate_global->%s_singleton;" % t.name, 3)
self.emit("default:", 2)
self.emit('/* should never happen, but just in case ... */', 3)
code = "PyErr_Format(PyExc_SystemError, \"unknown %s found\");" % name
self.emit(code, 3, reflow=False)
self.emit("return NULL;", 3)
self.emit("Py_UNREACHABLE();", 3);
Comment thread
isidentical marked this conversation as resolved.
Outdated
self.emit("}", 1)
self.emit("}", 0)

Expand Down
Loading