@@ -2862,9 +2862,7 @@ compiler_class(struct compiler *c, stmt_ty s)
2862
2862
int i , firstlineno ;
2863
2863
asdl_expr_seq * decos = s -> v .ClassDef .decorator_list ;
2864
2864
2865
- if (compiler_decorators (c , decos ) < 0 ) {
2866
- return 0 ;
2867
- }
2865
+ RETURN_IF_ERROR (compiler_decorators (c , decos ));
2868
2866
2869
2867
firstlineno = s -> lineno ;
2870
2868
if (asdl_seq_LEN (decos )) {
@@ -2882,10 +2880,10 @@ compiler_class(struct compiler *c, stmt_ty s)
2882
2880
This borrows from compiler_call.
2883
2881
*/
2884
2882
/* 1. compile the class body into a code object */
2885
- if ( compiler_enter_scope ( c , s -> v . ClassDef . name ,
2886
- COMPILER_SCOPE_CLASS , ( void * ) s , firstlineno ) < 0 ) {
2887
- return 0 ;
2888
- }
2883
+ RETURN_IF_ERROR (
2884
+ compiler_enter_scope ( c , s -> v . ClassDef . name ,
2885
+ COMPILER_SCOPE_CLASS , ( void * ) s , firstlineno )) ;
2886
+
2889
2887
/* this block represents what we do in the new scope */
2890
2888
{
2891
2889
location loc = LOCATION (firstlineno , firstlineno , 0 , 0 );
@@ -2894,23 +2892,23 @@ compiler_class(struct compiler *c, stmt_ty s)
2894
2892
/* load (global) __name__ ... */
2895
2893
if (!compiler_nameop (c , loc , & _Py_ID (__name__ ), Load )) {
2896
2894
compiler_exit_scope (c );
2897
- return 0 ;
2895
+ return ERROR ;
2898
2896
}
2899
2897
/* ... and store it as __module__ */
2900
2898
if (!compiler_nameop (c , loc , & _Py_ID (__module__ ), Store )) {
2901
2899
compiler_exit_scope (c );
2902
- return 0 ;
2900
+ return ERROR ;
2903
2901
}
2904
2902
assert (c -> u -> u_qualname );
2905
- _ADDOP_LOAD_CONST (c , loc , c -> u -> u_qualname );
2903
+ ADDOP_LOAD_CONST (c , loc , c -> u -> u_qualname );
2906
2904
if (!compiler_nameop (c , loc , & _Py_ID (__qualname__ ), Store )) {
2907
2905
compiler_exit_scope (c );
2908
- return 0 ;
2906
+ return ERROR ;
2909
2907
}
2910
2908
/* compile the body proper */
2911
2909
if (compiler_body (c , loc , s -> v .ClassDef .body ) < 0 ) {
2912
2910
compiler_exit_scope (c );
2913
- return 0 ;
2911
+ return ERROR ;
2914
2912
}
2915
2913
/* The following code is artificial */
2916
2914
/* Return __classcell__ if it is referenced, otherwise return None */
@@ -2919,59 +2917,60 @@ compiler_class(struct compiler *c, stmt_ty s)
2919
2917
i = compiler_lookup_arg (c -> u -> u_cellvars , & _Py_ID (__class__ ));
2920
2918
if (i < 0 ) {
2921
2919
compiler_exit_scope (c );
2922
- return 0 ;
2920
+ return ERROR ;
2923
2921
}
2924
2922
assert (i == 0 );
2925
- _ADDOP_I (c , NO_LOCATION , LOAD_CLOSURE , i );
2926
- _ADDOP_I (c , NO_LOCATION , COPY , 1 );
2923
+ ADDOP_I (c , NO_LOCATION , LOAD_CLOSURE , i );
2924
+ ADDOP_I (c , NO_LOCATION , COPY , 1 );
2927
2925
if (!compiler_nameop (c , NO_LOCATION , & _Py_ID (__classcell__ ), Store )) {
2928
2926
compiler_exit_scope (c );
2929
- return 0 ;
2927
+ return ERROR ;
2930
2928
}
2931
2929
}
2932
2930
else {
2933
2931
/* No methods referenced __class__, so just return None */
2934
2932
assert (PyDict_GET_SIZE (c -> u -> u_cellvars ) == 0 );
2935
- _ADDOP_LOAD_CONST (c , NO_LOCATION , Py_None );
2933
+ ADDOP_LOAD_CONST (c , NO_LOCATION , Py_None );
2936
2934
}
2937
- _ADDOP_IN_SCOPE (c , NO_LOCATION , RETURN_VALUE );
2935
+ ADDOP_IN_SCOPE (c , NO_LOCATION , RETURN_VALUE );
2938
2936
/* create the code object */
2939
2937
co = assemble (c , 1 );
2940
2938
}
2941
2939
/* leave the new scope */
2942
2940
compiler_exit_scope (c );
2943
- if (co == NULL )
2944
- return 0 ;
2941
+ if (co == NULL ) {
2942
+ return ERROR ;
2943
+ }
2945
2944
2946
2945
location loc = LOC (s );
2947
2946
/* 2. load the 'build_class' function */
2948
- _ADDOP (c , loc , PUSH_NULL );
2949
- _ADDOP (c , loc , LOAD_BUILD_CLASS );
2947
+ ADDOP (c , loc , PUSH_NULL );
2948
+ ADDOP (c , loc , LOAD_BUILD_CLASS );
2950
2949
2951
2950
/* 3. load a function (or closure) made from the code object */
2952
2951
if (compiler_make_closure (c , loc , co , 0 , NULL ) < 0 ) {
2953
2952
Py_DECREF (co );
2954
- return 0 ;
2953
+ return ERROR ;
2955
2954
}
2956
2955
Py_DECREF (co );
2957
2956
2958
2957
/* 4. load class name */
2959
- _ADDOP_LOAD_CONST (c , loc , s -> v .ClassDef .name );
2958
+ ADDOP_LOAD_CONST (c , loc , s -> v .ClassDef .name );
2960
2959
2961
2960
/* 5. generate the rest of the code for the call */
2962
2961
if (!compiler_call_helper (c , loc , 2 ,
2963
2962
s -> v .ClassDef .bases ,
2964
- s -> v .ClassDef .keywords ))
2965
- return 0 ;
2966
- /* 6. apply decorators */
2967
- if (compiler_apply_decorators (c , decos ) < 0 ) {
2968
- return 0 ;
2963
+ s -> v .ClassDef .keywords )) {
2964
+ return ERROR ;
2969
2965
}
2966
+ /* 6. apply decorators */
2967
+ RETURN_IF_ERROR (compiler_apply_decorators (c , decos ));
2970
2968
2971
2969
/* 7. store into <name> */
2972
- if (!compiler_nameop (c , loc , s -> v .ClassDef .name , Store ))
2973
- return 0 ;
2974
- return 1 ;
2970
+ if (!compiler_nameop (c , loc , s -> v .ClassDef .name , Store )) {
2971
+ return ERROR ;
2972
+ }
2973
+ return SUCCESS ;
2975
2974
}
2976
2975
2977
2976
/* Return 0 if the expression is a constant value except named singletons.
@@ -4202,7 +4201,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
4202
4201
case FunctionDef_kind :
4203
4202
return compiler_function (c , s , 0 );
4204
4203
case ClassDef_kind :
4205
- return compiler_class (c , s );
4204
+ return compiler_class (c , s ) == SUCCESS ? 1 : 0 ;
4206
4205
case Return_kind :
4207
4206
return compiler_return (c , s );
4208
4207
case Delete_kind :
0 commit comments