hoh/reloadr

reload function which is inside another function

Opened this issue · 2 comments

Environment : Linux os
Hi am trying to reload the function which is present within another function like this:

async def run():
    print("RUN Component")
    @reloadr
     async def function2():
          print("Function 2")
          return 0
      while True:
          await function2()
          sleep(5)

and calling that in while loop.
The problem here is when i change the print statement in function2 and save it am getting the following error and the value printing is still the old one.

**Error**
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/pop/.local/lib/python3.6/site-packages/watchdog/observers/api.py", line 199, in run
    self.dispatch_events(self.event_queue, self.timeout)
  File "/home/pop/.local/lib/python3.6/site-packages/watchdog/observers/api.py", line 368, in dispatch_events
    handler.dispatch(event)
  File "/home/pop/.local/lib/python3.6/site-packages/watchdog/events.py", line 330, in dispatch
    _method_map[event_type](event)
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 89, in on_modified
    this._reload()
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 146, in _reload
    self._target = reload_function(self._target, self._filepath)
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 63, in reload_function
    return reload_target(target, 'def', filepath)
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 50, in reload_target
    exec(source, module.__dict__, locals_)
  File "<string>", line 2
    def function2():
    ^
IndentationError: unexpected indent

However my indentations are correct the same code will run perfectly when initialized as separate function i.e outside of the main function

hoh commented

This is not supported yet, and would be more complex to implement as it would require accessing the namespace of the other function.

Do you have a usecase for this ?