@@ -2450,24 +2450,10 @@ def builtin_len(self, val: Value, line: int, use_pyssize_t: bool = False) -> Val
24502450 if class_ir .has_method ("__len__" ) and class_ir .is_method_final ("__len__" ):
24512451 decl = class_ir .method_decl ("__len__" )
24522452 length = self .call (decl , [val ], [ARG_POS ], [None ], line )
2453-
2454- # Coerce/check result and error handling as before
2455- length = self .coerce (length , int_rprimitive , line )
2456- ok , fail = BasicBlock (), BasicBlock ()
2457- cond = self .binary_op (length , Integer (0 ), ">=" , line )
2458- self .add_bool_branch (cond , ok , fail )
2459- self .activate_block (fail )
2460- self .add (
2461- RaiseStandardError (
2462- RaiseStandardError .VALUE_ERROR , "__len__() should return >= 0" , line
2463- )
2464- )
2465- self .add (Unreachable ())
2466- self .activate_block (ok )
2467- return length
2468-
2469- # Fallback: generic method call for non-native or ambiguous cases
2470- length = self .gen_method_call (val , "__len__" , [], int_rprimitive , line )
2453+ else :
2454+ # Fallback: generic method call for non-native or ambiguous cases
2455+ length = self .gen_method_call (val , "__len__" , [], int_rprimitive , line )
2456+
24712457 length = self .coerce (length , int_rprimitive , line )
24722458 ok , fail = BasicBlock (), BasicBlock ()
24732459 cond = self .binary_op (length , Integer (0 ), ">=" , line )
0 commit comments