@@ -12,7 +12,7 @@ use crate::pyfunction::ConstructorAttribute;
1212use crate :: pyimpl:: { gen_py_const, PyClassMethodsType } ;
1313use crate :: pymethod:: {
1414 impl_py_getter_def, impl_py_setter_def, MethodAndMethodDef , MethodAndSlotDef , PropertyType ,
15- SlotDef , __INT__, __REPR__, __RICHCMP__,
15+ SlotDef , __GETITEM__ , __INT__, __LEN__ , __REPR__, __RICHCMP__,
1616} ;
1717use crate :: utils:: Ctx ;
1818use crate :: utils:: { self , apply_renaming_rule, PythonDoc } ;
@@ -1078,7 +1078,7 @@ fn impl_complex_enum_tuple_variant_field_getters(
10781078 let field_type = field. ty ;
10791079
10801080 let field_getter =
1081- complex_enum_variant_field_getter ( & variant_cls_type, & field_name, field. span , ctx) ?;
1081+ complex_enum_variant_field_getter ( variant_cls_type, & field_name, field. span , ctx) ?;
10821082
10831083 // Generate the match arms needed to destructure the tuple and access the specific field
10841084 let field_access_tokens: Vec < _ > = ( 0 ..variant. fields . len ( ) )
@@ -1124,7 +1124,7 @@ fn impl_complex_enum_tuple_variant_len(
11241124 } ;
11251125
11261126 let variant_len =
1127- crate :: pymethod :: impl_py_slot_def ( & variant_cls_type, ctx , & mut len_method_impl. sig ) ?;
1127+ generate_default_protocol_slot ( variant_cls_type, & mut len_method_impl, & __LEN__ , ctx ) ?;
11281128
11291129 Ok ( ( variant_len, len_method_impl) )
11301130}
@@ -1161,8 +1161,12 @@ fn impl_complex_enum_tuple_variant_getitem(
11611161 }
11621162 } ;
11631163
1164- let variant_getitem =
1165- crate :: pymethod:: impl_py_slot_def ( & variant_cls_type, ctx, & mut get_item_method_impl. sig ) ?;
1164+ let variant_getitem = generate_default_protocol_slot (
1165+ variant_cls_type,
1166+ & mut get_item_method_impl,
1167+ & __GETITEM__,
1168+ ctx,
1169+ ) ?;
11661170
11671171 Ok ( ( variant_getitem, get_item_method_impl) )
11681172}
@@ -1171,7 +1175,7 @@ fn impl_complex_enum_tuple_variant_match_args(
11711175 ctx : & Ctx ,
11721176 variant_cls_type : & syn:: Type ,
11731177 field_names : & mut Vec < Ident > ,
1174- ) -> Result < ( MethodAndMethodDef , syn:: ImplItemConst ) > {
1178+ ) -> ( MethodAndMethodDef , syn:: ImplItemConst ) {
11751179 let match_args_const_impl: syn:: ImplItemConst = match field_names. len ( ) {
11761180 // This covers the case where the tuple variant has no fields (valid Rust)
11771181 0 => parse_quote ! {
@@ -1210,7 +1214,7 @@ fn impl_complex_enum_tuple_variant_match_args(
12101214
12111215 let variant_match_args = gen_py_const ( variant_cls_type, & spec, ctx) ;
12121216
1213- Ok ( ( variant_match_args, match_args_const_impl) )
1217+ ( variant_match_args, match_args_const_impl)
12141218}
12151219
12161220fn impl_complex_enum_tuple_variant_cls (
@@ -1231,10 +1235,10 @@ fn impl_complex_enum_tuple_variant_cls(
12311235
12321236 let ( mut field_getters, field_getter_impls) = impl_complex_enum_tuple_variant_field_getters (
12331237 ctx,
1234- & variant,
1238+ variant,
12351239 enum_name,
12361240 & variant_cls_type,
1237- & variant_ident,
1241+ variant_ident,
12381242 & mut field_names,
12391243 & mut field_types,
12401244 ) ?;
@@ -1252,7 +1256,7 @@ fn impl_complex_enum_tuple_variant_cls(
12521256 slots. push ( variant_getitem) ;
12531257
12541258 let ( variant_match_args, match_args_method_impl) =
1255- impl_complex_enum_tuple_variant_match_args ( ctx, & variant_cls_type, & mut field_names) ? ;
1259+ impl_complex_enum_tuple_variant_match_args ( ctx, & variant_cls_type, & mut field_names) ;
12561260
12571261 field_getters. push ( variant_match_args) ;
12581262
0 commit comments