Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit091951a

Browse files
authored
bpo-40528: Improve and clear several aspects of the ASDL definition code for the AST (GH-19952)
1 parent2668a9a commit091951a

File tree

6 files changed

+75
-101
lines changed

6 files changed

+75
-101
lines changed

‎Include/asdl.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

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

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

‎Lib/test/test_ast.py‎

Lines 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
withself.assertRaises(ValueError)ascm:
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
deftest_issue31592(self):

‎Parser/Python.asdl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-- ASDL's5 builtin types are:
2-
-- identifier, int, string,object,constant
1+
-- ASDL's4 builtin types are:
2+
-- identifier, int, string, constant
33

44
module Python
55
{

‎Parser/asdl.py‎

Lines 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
classAST:
4039
def__repr__(self):

‎Parser/asdl_c.py‎

Lines 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
ifnotoptandargtype!="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
defvisitProduct(self,prod,name):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp