@@ -631,9 +631,10 @@ def parse_arg_list(self, allow_signature: bool = True,
631631 elif self .current_str () == '(' :
632632 arg , extra_stmt , names = self .parse_tuple_arg (len (args ))
633633 args .append (arg )
634- extra_stmts .append (extra_stmt )
634+ if extra_stmt is not None :
635+ extra_stmts .append (extra_stmt )
636+ has_tuple_arg = True
635637 arg_names .extend (names )
636- has_tuple_arg = True
637638 else :
638639 arg , require_named = self .parse_normal_arg (
639640 require_named ,
@@ -691,6 +692,10 @@ def parse_tuple_arg(self, index: int) -> Tuple[Argument, AssignmentStmt, List[st
691692 function body (the second return value).
692693
693694 Return tuple (argument, decomposing assignment, list of names defined).
695+
696+ Special case: if the argument is just (x) then it's not a tuple;
697+ we indicate this by returning (argument, None, ['x']).
698+ However, if the argument is (x,) then it *is* a (singleton) tuple.
694699 """
695700 line = self .current ().line
696701 # Generate a new argument name that is very unlikely to clash with anything.
@@ -700,13 +705,14 @@ def parse_tuple_arg(self, index: int) -> Tuple[Argument, AssignmentStmt, List[st
700705 paren_arg = self .parse_parentheses ()
701706 self .verify_tuple_arg (paren_arg )
702707 if isinstance (paren_arg , NameExpr ):
703- # This isn't a tuple. Revert to a normal argument. We'll still get a no-op
704- # assignment below but that's benign.
708+ # This isn't a tuple. Revert to a normal argument.
705709 arg_name = paren_arg .name
706- rvalue = NameExpr (arg_name )
707- rvalue .set_line (line )
708- decompose = AssignmentStmt ([paren_arg ], rvalue )
709- decompose .set_line (line )
710+ decompose = None
711+ else :
712+ rvalue = NameExpr (arg_name )
713+ rvalue .set_line (line )
714+ decompose = AssignmentStmt ([paren_arg ], rvalue )
715+ decompose .set_line (line )
710716 kind = nodes .ARG_POS
711717 initializer = None
712718 if self .current_str () == '=' :
0 commit comments