fuzzingbook
fuzzingbook copied to clipboard
inspect.getsource() does not work for notebooks
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.