From user input to code object in IDLE's shell. Terry Jan Reedy, 2020 June 30. In idlelib.pyshell: User hitting invokes PyShell.enter_callback. When in code entry area and otherwise appropriate, clean trailing whitespace, insert '\n' and 'smart indent', and call PyShell.runit. PyShell.runit(self), code unchanged from original 2000 IDLE commit. Strip [ \t], '\n', [ \t]. The last removes IDLE's smart indent when nothing is entered. Result is no final '\n' until user hit twice. Call self.interp.runsource. ModifiedInterpreter(code.InterativeInterpreter).runsource(self, source). Stuff source in cache with filename and call parent method with source and filename. The result is 'returned' but the only apparent caller, runit, ignores it. code.InteractiveInterpreter.runsource(self, source, filename, symbol='single'). Call self.compile(source, filename, symbol). The instance self.compile = codeop.CommandCompiler(), set in II.__init__. code.II.runsource returns True if self.compile returns None, False otherwise after calling a function to run the code or print the exception. pyshell.MI.runsource passes the return on, but the only caller, runit, ignores it, and enter_callback exits. MI's overrides of .runcode and .showsyntaxerror reset PyShell for a new code entry. Otherwise, the user continues editing until hitting again. (With some changes, users could be allowed to edit after a SyntaxError, just as after running from an editor.) codeop defines flag PyCF_DONT_IMPLY_DEDENT = 0x200 from Include/compile.h. It attributes it to Include/pythonrun.h, but it is not there now. A CommandCompiler instance has compiler = Compile(). When called, it returns _maybe_compile(self.compiler, source, filename, symbol). A Compile instance has flags = PyCF_DONT_IMPLY_DEDENT. When called, it returns compile(source, filename, symbol, self.flags, True) after saving and future imports. _maybe_compile(compiler, source, filename, symbol) calls compiler(source, filename, symbol) 3 times, adding '\n' to source. This, and the return logic go back to 1998 with little change since. (If the first compile returns a code object, it is returned after doing two more compiles, whose results are ignored.) The end result is that user input is compiled with compile(trimmed_input, '', 'single, 0x200, True).