-
Notifications
You must be signed in to change notification settings - Fork 39
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
Metaclass decoration breaks venusian scope/frame detection mechanism #32
Comments
This is probably a bit late, but for reference, it should be possible to achieve this by invoking the API slightly differently. Your example isn't working because of how Venusian introspects the stack frame to determine the calling context. I'll go through this. Venusian has two main functions:
The reason why
works is because it is an example of 1. In this case, Venusian "cheats" slightly and puts "venusian_callbacks" on Calling
doesn't work because it's no longer a case of 1. Case 1 only applies in the "top level" of a class declaration block. Right now, this scope is inside a function (inside a class declaration). Therefore, Venusian will simply put both A solution I came up with would be to modify
For reference, see the internal check for method vs. class/function scoping. https://github.com/Pylons/venusian/blob/e2d5d32ddbed62c7b4baaf1bd138cb85b0e4e4f4/venusian/__init__.py#L302-322 |
I am writing a somewhat complex application that uses metaclasses to decorate functions (specifically, add views for a pyramid web application). However, when decorating inside a metaclass, venusian breaks.
From looking at the source, the reason for this seems to be the detection of scope that assumes I must be in a function call (which is correct) and therefore am not decorating a class method (which is incorrect).
I have never worked with venusian before but I tried to figure out the source code anyway. However, at this point I had to give up: I don't exactly understand what's going on here, so I couldn't figure out a fix. Instead, I have created a small testcase that replicates this issue:
This is, in essence, the problem: The decoration happens during the
TestMeta.__init__
method (thus it is a function call) but the method being decorated is at the class scope.I have tried playing with the depth parameter but I cannot get it to a class level (likely because of the way metaclasses work). If this is not considered a bug, please let me know how to work around it.
Note: You can check the correct way by removing the comment for the decorator above
test
and commeting out the__metaclass__
attribute instead:The text was updated successfully, but these errors were encountered: