Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 091951a

Browse filesBrowse files
authored
bpo-40528: Improve and clear several aspects of the ASDL definition code for the AST (GH-19952)
1 parent 2668a9a commit 091951a
Copy full SHA for 091951a

File tree

6 files changed

+75
-101
lines changed
Filter options

6 files changed

+75
-101
lines changed

‎Include/asdl.h

Copy file name to clipboardExpand all lines: Include/asdl.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
typedef PyObject * identifier;
66
typedef PyObject * string;
7-
typedef PyObject * bytes;
87
typedef PyObject * object;
9-
typedef PyObject * singleton;
108
typedef PyObject * constant;
119

1210
/* It would be nice if the code generated by asdl_c.py was completely

‎Lib/test/test_ast.py

Copy file name to clipboardExpand all lines: Lib/test/test_ast.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def test_empty_yield_from(self):
597597
empty_yield_from.body[0].body[0].value.value = None
598598
with self.assertRaises(ValueError) as cm:
599599
compile(empty_yield_from, "<test>", "exec")
600-
self.assertIn("field value is required", str(cm.exception))
600+
self.assertIn("field 'value' is required", str(cm.exception))
601601

602602
@support.cpython_only
603603
def test_issue31592(self):

‎Parser/Python.asdl

Copy file name to clipboardExpand all lines: Parser/Python.asdl
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-- ASDL's 5 builtin types are:
2-
-- identifier, int, string, object, constant
1+
-- ASDL's 4 builtin types are:
2+
-- identifier, int, string, constant
33

44
module Python
55
{

‎Parser/asdl.py

Copy file name to clipboardExpand all lines: Parser/asdl.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
# See the EBNF at the top of the file to understand the logical connection
3434
# between the various node types.
3535

36-
builtin_types = {'identifier', 'string', 'bytes', 'int', 'object', 'singleton',
37-
'constant'}
36+
builtin_types = {'identifier', 'string', 'int', 'constant'}
3837

3938
class AST:
4039
def __repr__(self):

‎Parser/asdl_c.py

Copy file name to clipboardExpand all lines: Parser/asdl_c.py
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def emit(s, depth=0, reflow=True):
323323
if not opt and argtype != "int":
324324
emit("if (!%s) {" % argname, 1)
325325
emit("PyErr_SetString(PyExc_ValueError,", 2)
326-
msg = "field %s is required for %s" % (argname, name)
326+
msg = "field '%s' is required for %s" % (argname, name)
327327
emit(' "%s");' % msg,
328328
2, reflow=False)
329329
emit('return NULL;', 2)
@@ -853,11 +853,9 @@ def visitModule(self, mod):
853853
Py_INCREF((PyObject*)o);
854854
return (PyObject*)o;
855855
}
856-
#define ast2obj_singleton ast2obj_object
857856
#define ast2obj_constant ast2obj_object
858857
#define ast2obj_identifier ast2obj_object
859858
#define ast2obj_string ast2obj_object
860-
#define ast2obj_bytes ast2obj_object
861859
862860
static PyObject* ast2obj_int(long b)
863861
{
@@ -1147,12 +1145,8 @@ def simpleSum(self, sum, name):
11471145
self.emit("case %s:" % t.name, 2)
11481146
self.emit("Py_INCREF(astmodulestate_global->%s_singleton);" % t.name, 3)
11491147
self.emit("return astmodulestate_global->%s_singleton;" % t.name, 3)
1150-
self.emit("default:", 2)
1151-
self.emit('/* should never happen, but just in case ... */', 3)
1152-
code = "PyErr_Format(PyExc_SystemError, \"unknown %s found\");" % name
1153-
self.emit(code, 3, reflow=False)
1154-
self.emit("return NULL;", 3)
11551148
self.emit("}", 1)
1149+
self.emit("Py_UNREACHABLE();", 1);
11561150
self.emit("}", 0)
11571151

11581152
def visitProduct(self, prod, name):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.