-
Notifications
You must be signed in to change notification settings - Fork 230
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
Subclassing proxied classes fails #21
Comments
What exactly are you trying to do? The CallableObjectProxy class wouldn't be used in that way. If that was just a bad example and what you are wanting to do was have a decorator on a base class which was then derived from, you need to use:
If the decorator has to also apply to the derived class, then you should add it to the base class. If you somehow want that to happen automatically, you probably should be using meta classes and not decorators. |
I'm working on a lazy import hook, and am using object proxies to lazily evaluate `from foo import bar`` statements (using caching), although it is still very much a work in progress. The point is when I hand off my proxied objects, I don't know how they are going to be used. In particular, it would be nice if inner defined derived classes could be lazily evaluated, such as in
where Like I said, I don't really see a fix, and regardless I think that it should be documented (e.g. "an P.S. I'm not actually using your |
For intercepting attribute access on a module, to either change what is returned, or to generate an attribute on demand, then you need to wrap the target module itself and replace the module in sys.modules.
With this we then get:
If the names of attributes isn't fixed list and so using a property like this cannot be done, you can override The general case of generating the object to be wrapped lazily on demand the first time only is something have been thinking about. The issue is how to do it without having to duplicate all the existing proxy code again for that case. If can be done, idea would be that you could have:
So when the first requirement exists to need the wrapped object it is created by calling the supplied 'wrapped' function and then caching the result and using it there after. Is doable, but suspect I need a complete separate LazyObjectProxy implementation and cannot have the existing ObjectProxy class do double duty or even harness what is done already by deriving from ObjectProxy. Even then, I don't think you could make it a proper object proxy and there would be various issues with it. For example, you can't intercept access to certain Anyway, try that LazyModule example and see if that will work for what you are doing and if you think it doesn't then explain the problem and will see what else you may need to do. |
@ohanar Did you try the suggestion I made for a lazy module proxy object? I will leave this issue here for the moment to remind me to document the issue about how to derive a class from a decorated one:
but when that is done will close the issue. |
Sorry, busy week. What you suggest is more or less what I was already doing. However, I'm looking at implementing an import hook, so I really have no idea what the attributes of the module are (and hence doing things with I think that with a little re-writing of your ObjectProxy class, it would be pretty trivial to add a LazyObjectProxy derivative. I'm pretty busy at the moment, but once I have a bit of time (probably in a couple of weeks) I could see about putting this together and making a pull request. |
Closing as nothing specific to wrapt that has to be changed. |
In python 3.4 (and probably other versions, just didn't test against them), if you try the following:
You will get a
TypeError
complaining about the number of arguments you are passing to theObjectProxy
constructor (at least with the c-extension version).I tried fiddling with this a little, but I couldn't really think of any way to fix this. At the very least, if this is not fixable, this behavior should be documented.
The text was updated successfully, but these errors were encountered: