@@ -486,6 +486,7 @@ def fix_function_overloads(self, stmts: List[Statement]) -> List[Statement]:
486486 ret : List [Statement ] = []
487487 current_overload : List [OverloadPart ] = []
488488 current_overload_name : Optional [str ] = None
489+ seen_unconditional_func_def = False
489490 last_if_stmt : Optional [IfStmt ] = None
490491 last_if_overload : Optional [Union [Decorator , FuncDef , OverloadedFuncDef ]] = None
491492 last_if_stmt_overload_name : Optional [str ] = None
@@ -498,6 +499,7 @@ def fix_function_overloads(self, stmts: List[Statement]) -> List[Statement]:
498499 if (
499500 isinstance (stmt , IfStmt )
500501 and len (stmt .body [0 ].body ) == 1
502+ and seen_unconditional_func_def is False
501503 and (
502504 isinstance (stmt .body [0 ].body [0 ], (Decorator , OverloadedFuncDef ))
503505 or current_overload_name is not None
@@ -527,6 +529,8 @@ def fix_function_overloads(self, stmts: List[Statement]) -> List[Statement]:
527529 self .fail_merge_overload (last_if_unknown_truth_value )
528530 last_if_unknown_truth_value = None
529531 current_overload .append (stmt )
532+ if isinstance (stmt , FuncDef ):
533+ seen_unconditional_func_def = True
530534 elif (
531535 current_overload_name is not None
532536 and isinstance (stmt , IfStmt )
@@ -583,6 +587,7 @@ def fix_function_overloads(self, stmts: List[Statement]) -> List[Statement]:
583587 # most of mypy/mypyc assumes that all the functions in an OverloadedFuncDef are
584588 # related, but multiple underscore functions next to each other aren't necessarily
585589 # related
590+ seen_unconditional_func_def = False
586591 if isinstance (stmt , Decorator ) and not unnamed_function (stmt .name ):
587592 current_overload = [stmt ]
588593 current_overload_name = stmt .name
0 commit comments