Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading from Jupyter Notebooks is not supported #1

Open
nathanielobrown opened this issue May 30, 2017 · 2 comments
Open

Reloading from Jupyter Notebooks is not supported #1

nathanielobrown opened this issue May 30, 2017 · 2 comments

Comments

@nathanielobrown
Copy link

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
Copy link
Owner

hoh commented Jun 8, 2017

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
Copy link
Author

Great, thanks!

@hoh hoh changed the title Does not work if class is defined in interpreter (ie __main__) Reloading from Jupyter Notebooks is not supported Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants