console.py

Adaptation of Python’s console found in code.py so that it can be used with import hooks.

class ideas.console.IdeasConsole(source_init=None, transform_ast=None, transform_bytecode=None, transform_source=None, callback_params=None, console_dict=None, locals=None)[source]

An interactive console that works with source transformations, AST transformations and Bytecode transformations.

It should not need to be instantiated directly.

push(line)[source]

Push a line to the interpreter.

The line should not have a trailing newline; it may have internal newlines. The line is appended to a buffer and the interpreter’s runsource() method is called with the concatenated contents of the buffer as the source. If this indicates that the command was executed or invalid, the buffer is reset; otherwise, the command is incomplete, and the buffer is left as it was after the line was appended. The return value is True if more input is required, False if the line was dealt with in some way (this is the same as runsource()).

runcode(code_obj)[source]

Execute a code object.

A note about KeyboardInterrupt: this exception may occur elsewhere in this code, and may not always be caught. The caller should be prepared to deal with it.

runsource(source, filename='Ideas Console', symbol='single')[source]

Compile and run some source in the interpreter.

Arguments are as for compile_command().

One several things can happen:

1) The input is incorrect; compile_command() raised an exception (SyntaxError or OverflowError). A syntax traceback will be printed .

2) The input is incomplete, and more input is required; compile_command() returned None. Nothing happens.

3) The input is complete; compile_command() returned a code object. The code is executed by calling self.runcode() (which also handles run-time exceptions, except for SystemExit). However, if an AST transformation is performed, we go back to the source and recompile in two steps so that we can perform an AST transformation.

The return value is True in case 2, False in the other cases (unless an exception is raised). The return value can be used to decide whether to use sys.ps1 or sys.ps2 to prompt the next line.

ideas.console.configure(**kwargs)[source]

Configures various defaults to be used by the console

ideas.console.start(banner='Ideas Console version 0.0.38. [Python version: 3.10.2]', show_config=False, prompt='ideas> ', locals=None)[source]

Starts a special console that works with import hooks.