When using Python's REPL/interactive prompt, the objects returned by inspect.stack() always have .code_context set to None.
The same code executed from within a .py file returns the code line by line in a stack trace as expected.
>>> import inspect
>>> print(inspect.stack()[0].code_context)
None
same code executed within a .py file prints:
['print(inspect.stack()[0].code_context)\n']
inspectmodule can display source code is if the code came from a file that it can access. Source typed at an interactive prompt is discarded as soon as it is parsed, there's simply no way forinspectto access it.