@@ -77,11 +77,6 @@ def __init__(
7777 def showtraceback (self ):
7878 super ().showtraceback (colorize = self .can_colorize )
7979
80- def push (self , line , filename = None , symbol = "single" ):
81- if line .count ("\n " ) > 0 :
82- symbol = "exec"
83- return super ().push (line , filename = filename , _symbol = symbol )
84-
8580
8681def run_multiline_interactive_console (
8782 mainmodule : ModuleType | None = None , future_flags : int = 0
@@ -140,7 +135,7 @@ def more_lines(unicodetext: str) -> bool:
140135 ps1 = getattr (sys , "ps1" , ">>> " )
141136 ps2 = getattr (sys , "ps2" , "... " )
142137 try :
143- statement = multiline_input (more_lines , ps1 , ps2 )
138+ statement , contains_pasted_code = multiline_input (more_lines , ps1 , ps2 )
144139 except EOFError :
145140 break
146141
@@ -149,7 +144,10 @@ def more_lines(unicodetext: str) -> bool:
149144
150145 input_name = f"<python-input-{ input_n } >"
151146 linecache ._register_code (input_name , statement , "<stdin>" ) # type: ignore[attr-defined]
152- more = console .push (_strip_final_indent (statement ), filename = input_name )
147+ symbol = "single" if not contains_pasted_code else "exec"
148+ more = console .push (_strip_final_indent (statement ), filename = input_name , _symbol = symbol )
149+ if contains_pasted_code and more :
150+ more = console .push (_strip_final_indent (statement ), filename = input_name , _symbol = "single" )
153151 assert not more
154152 input_n += 1
155153 except KeyboardInterrupt :
0 commit comments