Giter Club home page Giter Club logo

Comments (3)

psavery avatar psavery commented on May 17, 2024

To follow up, there were only a few things that I needed to modify to get this to work for me and @jourdain. Here's a diff:

diff --git a/reloading/reloading.py b/reloading/reloading.py
index aef1353..8401a81 100644
--- a/reloading/reloading.py
+++ b/reloading/reloading.py
@@ -181,14 +181,17 @@ def _reloading_loop(seq, every=1):
 def get_decorator_name(dec_node):
     if hasattr(dec_node, "id"):
         return dec_node.id
-    return dec_node.func.id
+    elif hasattr(dec_node.func, "id"):
+        return dec_node.func.id
+    return dec_node.func.value.id

 def strip_reloading_decorator(func):
-    """Remove the reloading decorator in-place"""
-    func.decorator_list = [
-        dec for dec in func.decorator_list if get_decorator_name(dec) != "reloading"
-    ]
+    """Remove the 'reloading' decorator and all decorators before it"""
+    decorator_names = [get_decorator_name(dec) for dec in func.decorator_list]
+    reloading_idx = decorator_names.index("reloading")
+    func.decorator_list = func.decorator_list[reloading_idx + 1:]

Basically, the method to get the decorator name for @ctrl.set("update_message") was not working for some reason. But adding a check for "id" on the func object, and then trying dec_node.func.value.id, worked for us (this returns ctrl).

The second part of our issue is that on the current master branch, all decorators are reloaded except the @reloading decorator. I believe, however, it may make more sense to only reload decorators after the @reloading decorator. This is because if we set up decorators like this:

@decorator
@reloading
def func():
    pass

Then the @decorator there is going to be taking the reloading-wrapped function at first, but the first time it is called, this reloading-wrapper gets removed since it is reloaded without the @reloading.

This was the issue with our code. The @ctrl.set("update_message") decorator is setting the function to a global object, and when it is first defined, the function is the reloading-wrapped function. But as soon as it gets called for the first time, the @ctrl.set("update_message") is executed again, and it replaces the reloading-wrapped function with a static, non-reloading function. So the reloading would no longer work after the first time.

I also think it logically makes more sense to only reload what comes after @reloading.

@julvo If you agree with these changes, I am happy to put up a PR.

from reloading.

julvo avatar julvo commented on May 17, 2024

Thank you both for reporting and looking into this.

Both suggested changes make sense to me and I'd be happy to merge a PR with these.

For the decorator name lookup in the first change: I guess we could be even more defensive here, name the function get_decorator_name_or_none and check that any attribute exists before we access it and return None otherwise instead of crashing.

from reloading.

psavery avatar psavery commented on May 17, 2024

@julvo Great, thank you! I just made a PR that includes your suggestion.

from reloading.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.