@@ -4581,11 +4581,21 @@ impl Compiler {
45814581 _ => continue ,
45824582 } ;
45834583 // Skip @staticmethod and @classmethod decorated functions
4584- let dominated_by_special = f. decorator_list . iter ( ) . any ( |d| {
4584+ let has_special_decorator = f. decorator_list . iter ( ) . any ( |d| {
45854585 matches ! ( & d. expression, ast:: Expr :: Name ( n)
45864586 if n. id. as_str( ) == "staticmethod" || n. id. as_str( ) == "classmethod" )
45874587 } ) ;
4588- if dominated_by_special {
4588+ if has_special_decorator {
4589+ continue ;
4590+ }
4591+ // Skip implicit classmethods (__init_subclass__, __class_getitem__)
4592+ let fname = f. name . as_str ( ) ;
4593+ if fname == "__init_subclass__" || fname == "__class_getitem__" {
4594+ continue ;
4595+ }
4596+ // For __new__, scan for "self" (not the first param "cls")
4597+ if fname == "__new__" {
4598+ Self :: scan_store_attrs ( & f. body , "self" , attrs) ;
45894599 continue ;
45904600 }
45914601 let first_param = f
@@ -5458,8 +5468,7 @@ impl Compiler {
54585468
54595469 // The thing iterated:
54605470 // Optimize: `for x in [a, b, c]` → use tuple instead of list
5461- // (list creation is wasteful for iteration)
5462- // Skip optimization if any element is starred (e.g., `[a, *b, c]`)
5471+ // Skip for async-for (GET_AITER expects the original type)
54635472 if !is_async
54645473 && let ast:: Expr :: List ( ast:: ExprList { elts, .. } ) = iter
54655474 && !elts. iter ( ) . any ( |e| matches ! ( e, ast:: Expr :: Starred ( _) ) )
@@ -7369,6 +7378,14 @@ impl Compiler {
73697378 Some ( expression) => self . compile_expression ( expression) ?,
73707379 Option :: None => self . emit_load_const ( ConstantData :: None ) ,
73717380 } ;
7381+ if self . ctx . func == FunctionContext :: AsyncFunction {
7382+ emit ! (
7383+ self ,
7384+ Instruction :: CallIntrinsic1 {
7385+ func: bytecode:: IntrinsicFunction1 :: AsyncGenWrap
7386+ }
7387+ ) ;
7388+ }
73727389 // arg=0: direct yield (wrapped for async generators)
73737390 emit ! ( self , Instruction :: YieldValue { arg: 0 } ) ;
73747391 emit ! (
@@ -7591,6 +7608,14 @@ impl Compiler {
75917608 compiler. compile_comprehension_element ( elt) ?;
75927609
75937610 compiler. mark_generator ( ) ;
7611+ if compiler. ctx . func == FunctionContext :: AsyncFunction {
7612+ emit ! (
7613+ compiler,
7614+ Instruction :: CallIntrinsic1 {
7615+ func: bytecode:: IntrinsicFunction1 :: AsyncGenWrap
7616+ }
7617+ ) ;
7618+ }
75947619 // arg=0: direct yield (wrapped for async generators)
75957620 emit ! ( compiler, Instruction :: YieldValue { arg: 0 } ) ;
75967621 emit ! (
@@ -7891,6 +7916,22 @@ impl Compiler {
78917916 if let ast:: Expr :: Starred ( ast:: ExprStarred { value, .. } ) = & arguments. args [ 0 ] {
78927917 self . compile_expression ( value) ?;
78937918 }
7919+ } else if !has_starred {
7920+ for arg in & arguments. args {
7921+ self . compile_expression ( arg) ?;
7922+ }
7923+ self . set_source_range ( call_range) ;
7924+ let positional_count = additional_positional + nelts. to_u32 ( ) ;
7925+ if positional_count == 0 {
7926+ self . emit_load_const ( ConstantData :: Tuple { elements : vec ! [ ] } ) ;
7927+ } else {
7928+ emit ! (
7929+ self ,
7930+ Instruction :: BuildTuple {
7931+ count: positional_count
7932+ }
7933+ ) ;
7934+ }
78947935 } else {
78957936 // Use starunpack_helper to build a list, then convert to tuple
78967937 self . starunpack_helper (
@@ -8236,7 +8277,6 @@ impl Compiler {
82368277
82378278 // Create comprehension function with closure
82388279 self . make_closure ( code, bytecode:: MakeFunctionFlags :: new ( ) ) ?;
8239- emit ! ( self , Instruction :: PushNull ) ;
82408280
82418281 // Evaluate iterated item:
82428282 self . compile_expression ( & generators[ 0 ] . iter ) ?;
@@ -8250,7 +8290,7 @@ impl Compiler {
82508290 } ;
82518291
82528292 // Call just created <listcomp> function:
8253- emit ! ( self , Instruction :: Call { argc: 1 } ) ;
8293+ emit ! ( self , Instruction :: Call { argc: 0 } ) ;
82548294 if is_async_list_set_dict_comprehension {
82558295 emit ! ( self , Instruction :: GetAwaitable { r#where: 0 } ) ;
82568296 self . emit_load_const ( ConstantData :: None ) ;
0 commit comments