Reloading from Jupyter Notebooks is not supported
Opened this issue · 2 comments
nathanielobrown commented
Seeing as this is a super early stage project, I assume you just haven't got to this yet and this exception will demonstrate the issue. I was trying to use reloadr on a class I defined in a JupyterNotebook.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-ba3cff0dfb1e> in <module>()
----> 1 TDAmeritradeScraper._reload()
/usr/local/lib/python3.6/site-packages/reloadr.py in _reload(self)
116 "Manually reload the class with its new code."
117 try:
--> 118 self._target = reload_class(self._target)
119 # Replace the class reference of all instances with the new class
120 for ref in self._instances:
/usr/local/lib/python3.6/site-packages/reloadr.py in reload_class(target)
56 def reload_class(target):
57 "Get the new class object corresponding to the target class."
---> 58 return reload_target(target, 'class')
59
60
/usr/local/lib/python3.6/site-packages/reloadr.py in reload_target(target, kind, filepath)
43 assert kind in ('class', 'def')
44
---> 45 source = get_new_source(target, kind, filepath)
46 module = inspect.getmodule(target)
47 # We will populate these locals using exec()
/usr/local/lib/python3.6/site-packages/reloadr.py in get_new_source(target, kind, filepath)
28 assert kind in ('class', 'def')
29
---> 30 filepath = filepath or inspect.getsourcefile(target)
31 red = redbaron.RedBaron(open(filepath).read())
32 # dumps() returns Python code as a string
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/inspect.py in getsourcefile(object)
652 Return None if no way can be identified to get the source.
653 """
--> 654 filename = getfile(object)
655 all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]
656 all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/inspect.py in getfile(object)
622 if hasattr(object, '__file__'):
623 return object.__file__
--> 624 raise TypeError('{!r} is a built-in class'.format(object))
625 if ismethod(object):
626 object = object.__func__
TypeError: <module '__main__'> is a built-in class
hoh commented
Hello,
I did not design this tool with Notebooks in mind — I usually re-run the cell in notebooks to reload their code — but it should be possible to add support for notebooks as well. I'll have a look at it.
nathanielobrown commented
Great, thanks!