@@ -2027,26 +2027,24 @@ compiler_visit_annexpr(struct compiler *c, expr_ty annotation)
20272027
20282028static int
20292029compiler_visit_argannotation (struct compiler * c , identifier id ,
2030- expr_ty annotation , PyObject * names )
2030+ expr_ty annotation , Py_ssize_t * annotations_len )
20312031{
20322032 if (annotation ) {
2033- PyObject * mangled ;
2034- VISIT (c , annexpr , annotation );
2035- mangled = _Py_Mangle (c -> u -> u_private , id );
2033+ PyObject * mangled = _Py_Mangle (c -> u -> u_private , id );
20362034 if (!mangled )
20372035 return 0 ;
2038- if (PyList_Append (names , mangled ) < 0 ) {
2039- Py_DECREF (mangled );
2040- return 0 ;
2041- }
2036+
2037+ ADDOP_LOAD_CONST (c , mangled );
20422038 Py_DECREF (mangled );
2039+ VISIT (c , annexpr , annotation );
2040+ * annotations_len += 2 ;
20432041 }
20442042 return 1 ;
20452043}
20462044
20472045static int
20482046compiler_visit_argannotations (struct compiler * c , asdl_arg_seq * args ,
2049- PyObject * names )
2047+ Py_ssize_t * annotations_len )
20502048{
20512049 int i ;
20522050 for (i = 0 ; i < asdl_seq_LEN (args ); i ++ ) {
@@ -2055,7 +2053,7 @@ compiler_visit_argannotations(struct compiler *c, asdl_arg_seq* args,
20552053 c ,
20562054 arg -> arg ,
20572055 arg -> annotation ,
2058- names ))
2056+ annotations_len ))
20592057 return 0 ;
20602058 }
20612059 return 1 ;
@@ -2065,58 +2063,44 @@ static int
20652063compiler_visit_annotations (struct compiler * c , arguments_ty args ,
20662064 expr_ty returns )
20672065{
2068- /* Push arg annotation dict .
2066+ /* Push arg annotation names and values .
20692067 The expressions are evaluated out-of-order wrt the source code.
20702068
2071- Return 0 on error, -1 if no dict pushed, 1 if a dict is pushed.
2069+ Return 0 on error, -1 if no annotations pushed, 1 if a annotations is pushed.
20722070 */
20732071 static identifier return_str ;
2074- PyObject * names ;
2075- Py_ssize_t len ;
2076- names = PyList_New (0 );
2077- if (!names )
2078- return 0 ;
2072+ Py_ssize_t annotations_len = 0 ;
20792073
2080- if (!compiler_visit_argannotations (c , args -> args , names ))
2081- goto error ;
2082- if (!compiler_visit_argannotations (c , args -> posonlyargs , names ))
2083- goto error ;
2074+ if (!compiler_visit_argannotations (c , args -> args , & annotations_len ))
2075+ return 0 ;
2076+ if (!compiler_visit_argannotations (c , args -> posonlyargs , & annotations_len ))
2077+ return 0 ;
20842078 if (args -> vararg && args -> vararg -> annotation &&
20852079 !compiler_visit_argannotation (c , args -> vararg -> arg ,
2086- args -> vararg -> annotation , names ))
2087- goto error ;
2088- if (!compiler_visit_argannotations (c , args -> kwonlyargs , names ))
2089- goto error ;
2080+ args -> vararg -> annotation , & annotations_len ))
2081+ return 0 ;
2082+ if (!compiler_visit_argannotations (c , args -> kwonlyargs , & annotations_len ))
2083+ return 0 ;
20902084 if (args -> kwarg && args -> kwarg -> annotation &&
20912085 !compiler_visit_argannotation (c , args -> kwarg -> arg ,
2092- args -> kwarg -> annotation , names ))
2093- goto error ;
2086+ args -> kwarg -> annotation , & annotations_len ))
2087+ return 0 ;
20942088
20952089 if (!return_str ) {
20962090 return_str = PyUnicode_InternFromString ("return" );
20972091 if (!return_str )
2098- goto error ;
2092+ return 0 ;
20992093 }
2100- if (!compiler_visit_argannotation (c , return_str , returns , names )) {
2101- goto error ;
2094+ if (!compiler_visit_argannotation (c , return_str , returns , & annotations_len )) {
2095+ return 0 ;
21022096 }
21032097
2104- len = PyList_GET_SIZE (names );
2105- if (len ) {
2106- PyObject * keytuple = PyList_AsTuple (names );
2107- Py_DECREF (names );
2108- ADDOP_LOAD_CONST_NEW (c , keytuple );
2109- ADDOP_I (c , BUILD_CONST_KEY_MAP , len );
2098+ if (annotations_len ) {
2099+ ADDOP_I (c , BUILD_TUPLE , annotations_len );
21102100 return 1 ;
21112101 }
2112- else {
2113- Py_DECREF (names );
2114- return -1 ;
2115- }
21162102
2117- error :
2118- Py_DECREF (names );
2119- return 0 ;
2103+ return -1 ;
21202104}
21212105
21222106static int
0 commit comments