fuzzingbook icon indicating copy to clipboard operation
fuzzingbook copied to clipboard

inspect.getsource() does not work for notebooks

Open andreas-zeller opened this issue 6 years ago • 0 comments

Using inspect.getsource() to retrieve the source code of functions does not work if

  • the function is defined in a notebook, and
  • we are calling inspect.getsource() from a notebook.

The reason is that inspect.getsource() looks for .py files, not .ipynb. We patch this for import of modules, but not for inspect.

Solution: Provide an alternative to inspect.getsource() (say, fuzzingbook_utils.getsource()) which looks for defs in .ipynb files (or creates a temporary .py file that getsource() could use). See the inspect source code for details.

andreas-zeller avatar Mar 25 '19 07:03 andreas-zeller