@@ -6740,18 +6740,18 @@ validate_kwd_attrs(struct compiler *c, asdl_identifier_seq *attrs, asdl_pattern_
6740
6740
identifier attr = ((identifier )asdl_seq_GET (attrs , i ));
6741
6741
location loc = LOC ((pattern_ty ) asdl_seq_GET (patterns , i ));
6742
6742
if (forbidden_name (c , loc , attr , Store )) {
6743
- return -1 ;
6743
+ return ERROR ;
6744
6744
}
6745
6745
for (Py_ssize_t j = i + 1 ; j < nattrs ; j ++ ) {
6746
6746
identifier other = ((identifier )asdl_seq_GET (attrs , j ));
6747
6747
if (!PyUnicode_Compare (attr , other )) {
6748
6748
location loc = LOC ((pattern_ty ) asdl_seq_GET (patterns , j ));
6749
6749
compiler_error (c , loc , "attribute name repeated in class pattern: %U" , attr );
6750
- return -1 ;
6750
+ return ERROR ;
6751
6751
}
6752
6752
}
6753
6753
}
6754
- return 0 ;
6754
+ return SUCCESS ;
6755
6755
}
6756
6756
6757
6757
static int
@@ -6768,34 +6768,36 @@ compiler_pattern_class(struct compiler *c, pattern_ty p, pattern_context *pc)
6768
6768
// AST validator shouldn't let this happen, but if it does,
6769
6769
// just fail, don't crash out of the interpreter
6770
6770
const char * e = "kwd_attrs (%d) / kwd_patterns (%d) length mismatch in class pattern" ;
6771
- return compiler_error (c , LOC (p ), e , nattrs , nkwd_patterns );
6771
+ compiler_error (c , LOC (p ), e , nattrs , nkwd_patterns );
6772
+ return ERROR ;
6772
6773
}
6773
6774
if (INT_MAX < nargs || INT_MAX < nargs + nattrs - 1 ) {
6774
6775
const char * e = "too many sub-patterns in class pattern %R" ;
6775
- return compiler_error (c , LOC (p ), e , p -> v .MatchClass .cls );
6776
+ compiler_error (c , LOC (p ), e , p -> v .MatchClass .cls );
6777
+ return ERROR ;
6776
6778
}
6777
6779
if (nattrs ) {
6778
- RETURN_IF_FALSE (!validate_kwd_attrs (c , kwd_attrs , kwd_patterns ));
6780
+ RETURN_IF_ERROR (validate_kwd_attrs (c , kwd_attrs , kwd_patterns ));
6781
+ }
6782
+ VISIT (c , expr , p -> v .MatchClass .cls );
6783
+ PyObject * attr_names = PyTuple_New (nattrs );
6784
+ if (!attr_names ) {
6785
+ return ERROR ;
6779
6786
}
6780
- _VISIT (c , expr , p -> v .MatchClass .cls );
6781
- PyObject * attr_names ;
6782
- RETURN_IF_FALSE (attr_names = PyTuple_New (nattrs ));
6783
6787
Py_ssize_t i ;
6784
6788
for (i = 0 ; i < nattrs ; i ++ ) {
6785
6789
PyObject * name = asdl_seq_GET (kwd_attrs , i );
6786
6790
PyTuple_SET_ITEM (attr_names , i , Py_NewRef (name ));
6787
6791
}
6788
- _ADDOP_LOAD_CONST_NEW (c , LOC (p ), attr_names );
6789
- _ADDOP_I (c , LOC (p ), MATCH_CLASS , nargs );
6790
- _ADDOP_I (c , LOC (p ), COPY , 1 );
6791
- _ADDOP_LOAD_CONST (c , LOC (p ), Py_None );
6792
- _ADDOP_I (c , LOC (p ), IS_OP , 1 );
6792
+ ADDOP_LOAD_CONST_NEW (c , LOC (p ), attr_names );
6793
+ ADDOP_I (c , LOC (p ), MATCH_CLASS , nargs );
6794
+ ADDOP_I (c , LOC (p ), COPY , 1 );
6795
+ ADDOP_LOAD_CONST (c , LOC (p ), Py_None );
6796
+ ADDOP_I (c , LOC (p ), IS_OP , 1 );
6793
6797
// TOS is now a tuple of (nargs + nattrs) attributes (or None):
6794
6798
pc -> on_top ++ ;
6795
- if (jump_to_fail_pop (c , LOC (p ), pc , POP_JUMP_IF_FALSE ) < 0 ) {
6796
- return 0 ;
6797
- }
6798
- _ADDOP_I (c , LOC (p ), UNPACK_SEQUENCE , nargs + nattrs );
6799
+ RETURN_IF_ERROR (jump_to_fail_pop (c , LOC (p ), pc , POP_JUMP_IF_FALSE ));
6800
+ ADDOP_I (c , LOC (p ), UNPACK_SEQUENCE , nargs + nattrs );
6799
6801
pc -> on_top += nargs + nattrs - 1 ;
6800
6802
for (i = 0 ; i < nargs + nattrs ; i ++ ) {
6801
6803
pc -> on_top -- ;
@@ -6809,15 +6811,13 @@ compiler_pattern_class(struct compiler *c, pattern_ty p, pattern_context *pc)
6809
6811
pattern = asdl_seq_GET (kwd_patterns , i - nargs );
6810
6812
}
6811
6813
if (WILDCARD_CHECK (pattern )) {
6812
- _ADDOP (c , LOC (p ), POP_TOP );
6814
+ ADDOP (c , LOC (p ), POP_TOP );
6813
6815
continue ;
6814
6816
}
6815
- if (compiler_pattern_subpattern (c , pattern , pc ) < 0 ) {
6816
- return 0 ;
6817
- }
6817
+ RETURN_IF_ERROR (compiler_pattern_subpattern (c , pattern , pc ));
6818
6818
}
6819
6819
// Success! Pop the tuple of attributes:
6820
- return 1 ;
6820
+ return SUCCESS ;
6821
6821
}
6822
6822
6823
6823
static int
@@ -7227,7 +7227,7 @@ compiler_pattern(struct compiler *c, pattern_ty p, pattern_context *pc)
7227
7227
case MatchMapping_kind :
7228
7228
return compiler_pattern_mapping (c , p , pc );
7229
7229
case MatchClass_kind :
7230
- return compiler_pattern_class (c , p , pc );
7230
+ return compiler_pattern_class (c , p , pc ) == SUCCESS ? 1 : 0 ;
7231
7231
case MatchStar_kind :
7232
7232
return compiler_pattern_star (c , p , pc ) == SUCCESS ? 1 : 0 ;
7233
7233
case MatchAs_kind :
0 commit comments