-
Notifications
You must be signed in to change notification settings - Fork 233
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
__doc__ property #249
Comments
Not sure. There has to be special code for certain dunder attributes in the pure Python implementation because of how the Python object model works.
The line:
should only be copying the function definition from the class type, not an instance, so the property shouldn't I don't think be dereferenced at that point. So would need to work if this is working as intended and where |
This may have more to do with strange Python rules about lookup order for |
Python implementation works fine and metaclass takes care of things for all inherited classes, C implementation is where things "malfunction". And I like C for obvious reasons. I found that what solves it is: class MyCustomProxy(wrapt.ObjectProxy):
@property
def __doc__(self):
return self.__wrapped__.__doc__ However, if I inherit from it, then I need to do the same for sub-class again... Another solution is to mix & match: class MyCustomProxy(wrapt.ObjectProxy, metaclass=_ObjectProxyMetaType):
pass
class MyCustomProxy2(MyCustomProxy):
pass This way, python's meta implementation will take care of things on top of C implementation, even if inherited from it again. I would look at it, but I am quite basic at C, so all I can do now is to point it out and give couple of hacks for it. |
The disparity with the C object proxy base class will be because it uses a C level getter/setter function slot for handling access to |
Just for curiosity, which functionality of ProxyObject benefits most from C's implementation over python's? Construction seems to be about 5x, however attribute access, such as doc look similar. Also, |
Wasn't a case of choosing one over the other for a reason. When doing C based Python objects you just use the most obvious mechanism it provides for it. These strange situations like overriding |
If the question was more around why bother with C implementation at all, was because back in Python 2.X days when machines were slower, any pure Python overhead could be noticeable, especially with the original use for wrapt, which was in New Relic Python web application performance monitoring instrumentation. So much was being instrumented and being continually exercised, pure Python variant had a noticeable overhead, which is last thing you want when instrumenting production systems. |
Thank you, that answered it. |
Do I leave this so that someone can take a look, or do I close this? |
Hello
I have a code:
Result:
Python implementation of the proxy object calls doc from its ProxyObject.@Propert(doc).
However, C implementation hard-copies doc value to the proxy if inheriting from it.
Is this expected?
The text was updated successfully, but these errors were encountered: