@@ -85,10 +85,12 @@ static char *Delete_fields[]={
8585 "targets" ,
8686};
8787static PyTypeObject * Assign_type ;
88+ _Py_IDENTIFIER (annotation );
8889static char * Assign_fields []= {
8990 "targets" ,
9091 "value" ,
9192 "type_comment" ,
93+ "annotation" ,
9294};
9395static PyTypeObject * AugAssign_type ;
9496_Py_IDENTIFIER (target );
@@ -464,7 +466,6 @@ static char *arg_attributes[] = {
464466 "col_offset" ,
465467};
466468_Py_IDENTIFIER (arg );
467- _Py_IDENTIFIER (annotation );
468469static char * arg_fields []= {
469470 "arg" ,
470471 "annotation" ,
@@ -862,7 +863,7 @@ static int init_types(void)
862863 if (!Return_type ) return 0 ;
863864 Delete_type = make_type ("Delete" , stmt_type , Delete_fields , 1 );
864865 if (!Delete_type ) return 0 ;
865- Assign_type = make_type ("Assign" , stmt_type , Assign_fields , 3 );
866+ Assign_type = make_type ("Assign" , stmt_type , Assign_fields , 4 );
866867 if (!Assign_type ) return 0 ;
867868 AugAssign_type = make_type ("AugAssign" , stmt_type , AugAssign_fields , 3 );
868869 if (!AugAssign_type ) return 0 ;
@@ -1369,22 +1370,18 @@ Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)
13691370}
13701371
13711372stmt_ty
1372- Assign (asdl_seq * targets , expr_ty value , string type_comment , int lineno , int
1373- col_offset , PyArena * arena )
1373+ Assign (asdl_seq * targets , expr_ty value , string type_comment , expr_ty
1374+ annotation , int lineno , int col_offset , PyArena * arena )
13741375{
13751376 stmt_ty p ;
1376- if (!value ) {
1377- PyErr_SetString (PyExc_ValueError ,
1378- "field value is required for Assign" );
1379- return NULL ;
1380- }
13811377 p = (stmt_ty )PyArena_Malloc (arena , sizeof (* p ));
13821378 if (!p )
13831379 return NULL ;
13841380 p -> kind = Assign_kind ;
13851381 p -> v .Assign .targets = targets ;
13861382 p -> v .Assign .value = value ;
13871383 p -> v .Assign .type_comment = type_comment ;
1384+ p -> v .Assign .annotation = annotation ;
13881385 p -> lineno = lineno ;
13891386 p -> col_offset = col_offset ;
13901387 return p ;
@@ -2729,6 +2726,11 @@ ast2obj_stmt(void* _o)
27292726 if (_PyObject_SetAttrId (result , & PyId_type_comment , value ) == -1 )
27302727 goto failed ;
27312728 Py_DECREF (value );
2729+ value = ast2obj_expr (o -> v .Assign .annotation );
2730+ if (!value ) goto failed ;
2731+ if (_PyObject_SetAttrId (result , & PyId_annotation , value ) == -1 )
2732+ goto failed ;
2733+ Py_DECREF (value );
27322734 break ;
27332735 case AugAssign_kind :
27342736 result = PyType_GenericNew (AugAssign_type , NULL , NULL );
@@ -4554,6 +4556,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
45544556 asdl_seq * targets ;
45554557 expr_ty value ;
45564558 string type_comment ;
4559+ expr_ty annotation ;
45574560
45584561 if (_PyObject_HasAttrId (obj , & PyId_targets )) {
45594562 int res ;
@@ -4579,16 +4582,15 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
45794582 PyErr_SetString (PyExc_TypeError , "required field \"targets\" missing from Assign" );
45804583 return 1 ;
45814584 }
4582- if (_PyObject_HasAttrId (obj , & PyId_value )) {
4585+ if (exists_not_none (obj , & PyId_value )) {
45834586 int res ;
45844587 tmp = _PyObject_GetAttrId (obj , & PyId_value );
45854588 if (tmp == NULL ) goto failed ;
45864589 res = obj2ast_expr (tmp , & value , arena );
45874590 if (res != 0 ) goto failed ;
45884591 Py_CLEAR (tmp );
45894592 } else {
4590- PyErr_SetString (PyExc_TypeError , "required field \"value\" missing from Assign" );
4591- return 1 ;
4593+ value = NULL ;
45924594 }
45934595 if (exists_not_none (obj , & PyId_type_comment )) {
45944596 int res ;
@@ -4600,7 +4602,18 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
46004602 } else {
46014603 type_comment = NULL ;
46024604 }
4603- * out = Assign (targets , value , type_comment , lineno , col_offset , arena );
4605+ if (exists_not_none (obj , & PyId_annotation )) {
4606+ int res ;
4607+ tmp = _PyObject_GetAttrId (obj , & PyId_annotation );
4608+ if (tmp == NULL ) goto failed ;
4609+ res = obj2ast_expr (tmp , & annotation , arena );
4610+ if (res != 0 ) goto failed ;
4611+ Py_CLEAR (tmp );
4612+ } else {
4613+ annotation = NULL ;
4614+ }
4615+ * out = Assign (targets , value , type_comment , annotation , lineno ,
4616+ col_offset , arena );
46044617 if (* out == NULL ) goto failed ;
46054618 return 0 ;
46064619 }
0 commit comments