-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Bind delayed task creating functions to the object instance. #307
Conversation
I'll be traveling for a week but would love to see this merged. Let me know if something needs work. |
Yes, your example should work... But your solution is not good. We should solve the problem of decorating a function that takes whatever parameters. Not solving only the specific case where there is only |
(I will push a rebase to master after this comment) I was not aware that a task building function would ever be called with parameters.
From loader.py Curious to know more I modified the task building function to have the following signature:
I then modified
Try it out:
This is followed, of course, by an error because the mandatory argument This leads me to believe that the bound task making function with the signature Perhaps I am confused? Is there another test case I should consider? |
0bff683
to
e00e273
Compare
Yes, currently not possible. But look at #311 I did not try your patch but i guess it is too fragile. It would not work if a Or how about a method with What i am saying is that solution would be better to change the decorator itself. something like "Decorating Functions With Arguments" https://realpython.com/primer-on-python-decorators/ . |
#311: That would be very nice. I have bent some of my tasks into knots working around the absence of task group parameters like this. I'll work out the details on my patch to modify the |
e00e273
to
a5b8f99
Compare
What I have pushed is just a simplified version of the prior work but I believe does everything you are interested in in the simplest way possible. As I understand the requirements:
The To reach the objective the loader is
Requirement 2 is supported because nothing about the task creating method's signature is modified by the decorator and the method is not wrapped. Requirement 3 is supported because nothing is modified that interferes with either function-based task definition or the The I'm attaching the function-based ( function:
class:
|
Thanks. My expectation was that the DelayedTask would save not only a reference to the function but also to its parameters.
So I guess there is no point in setting it in the first place. Sorry, I think I will merge this together with #311. I am hesitant to make a call without having the code for both. |
The @create_after decorator stashes a reference to the unbound method in a DelayedLoader instance. To work with tasks defined by methods the reference must be bound to the task creating class instance.
08c6a2a
to
5f80714
Compare
@schettino72 Any further work required for this PR? |
Bump.... would love to see this merged. Thanks. |
I tried to use
@create_after
with task definitions created from class methods and it didn't work. I thought this would work because nothing in the documentation implies that it doesn't. I dug into this and it seems to be a simple fix.The @create_after decorator stashes a reference to the unbound method in a DelayedLoader instance. To work with tasks defined by methods the reference must be bound to the task creating class instance.
Please let me know if you have any comments or suggested improvements.
Simple Example: