-
Notifications
You must be signed in to change notification settings - Fork 30
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
Allow to stack decorators #19
Comments
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 The second part of our issue is that on the current master branch, all decorators are reloaded except the @decorator
@reloading
def func():
pass Then the This was the issue with our code. The I also think it logically makes more sense to only reload what comes after @julvo If you agree with these changes, I am happy to put up a PR. |
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 |
@julvo Great, thank you! I just made a PR that includes your suggestion. |
Thanks for building such awesome library but I wanted to see if I can use it within trame in a more streamline fashion.
Right now it is working if I create an indirection like in that working example but ideally I would like to be able to stack decorators like in the snippet below.
But when I do, I get the following exception
It is possible that the issue is on my side (@ctrl, @state) but any help will be greatly appreciated.
The text was updated successfully, but these errors were encountered: