-
Notifications
You must be signed in to change notification settings - Fork 55
WIP: pyscript decorators #122
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
Conversation
This code:
... shows that TestState is never initialized, let alone called. Which makes sense, now that I see it. Because I am evaluating the decorators when the function is CALLED and this function So, this shows that the code to evaluate decorators needs to go somewhere else. I'm just not sure where. |
This code now seems to work perfectly:
Trying to work out object based decorators now, though, I think it will require quite a bit of code to jump through all the pieces required. |
For reference, my goal in this is that I already have this:
But I want to do it this way instead:
Or even:
Syntax like that just looks better, reads better, and feels more "pyscripty" to me. |
@craigbarratt this seems to be the best I can get it. Thought I'm not really keen about the hacky bit here ( 907cc50#diff-733b200d9ce0361a3582c281043fd548b057e971f927f73aed75bfdc8422f06cR578-R587 ). If you have some time to look this over, maybe you can offer insight regarding a better approach or and easier, less hacky way, to do what I'm doing. This code seems to work fine, however, in my test environment. Though it could certainly use a lot more testing. I've yet to move this into "production" to really test it because it has the potential to blow up in a difficult to trace way since I have SO many pyscripts running. |
Great - I should have time to review it tomorrow. |
Thanks for pushing forward on this. I started with your code and tweaked it some. I'd recommend rebasing to get the latest version of Next, we need a good way to partition the hard-coded trigger decorators, so I added this near the top of the file:
and replaced the existing inline Next, I reverted the Finally, the
I tried testing with this decorator:
but that exposes a bug that closures don't resolve nonlocal variables if they aren't in the immediate outer scope. I need to fix that. So the workaround is this (just like you did in your example):
That seems to work correctly. I haven't tried object method decorators or your more complex example. Also, one of the tests in |
fc5b7ae
to
658a2a0
Compare
opening |
ah ha! using However, the problem that I created the hacky method for still exists.
Error:
The trouble is that the So, instead of passing I'll see if I can work out a cleaner way to do that starting with a much better base than I had before. THANK YOU! |
like the above
I think it would be best if There must be a better way to just not have ast_ctx there at all, I just can't seem to find it. |
Put another way to make sure I'm explaining it correctly, here's a use of your
Running the above without my hacky bit added in, you'll notice from the logs,
Ideally, |
Yes, it doesn't work without your function that strips off any leading ast context and ensures there is one when the function is called. I find it difficult to understand exactly why that's necessary. It seems vaguely like the movie Inception. I need to think about this some more... |
Yes, exactly! I've tried all manner of inspection inside of |
I think it will be cleaner to move the decorator calls up into I'll merge this PR and edit from there. |
I'm still looking over the code to figure out exactly what you did. But all of my tests are working. I've tested... a decorator function with no arguments. everything seems to work. now, to go figure out what you did and then start converting some of my "production" code to see if any bugs crop up. This is fantastic! Thank you! |
This PR allows for decorators from pyscript functions.