Skip to content Skip to sidebar Skip to footer

Python Object Wrapper

I am trying to create a wrapper class that behaves almost like the wrapped object. So far, I have come up with the following code: import functools import types method_wrapper =

Solution 1:

The problem is here:

for ...:
    attr = ...
    ...
    defwrapped_attr(...):
        ..attr..

This doesn't work as expected, because attr is rebound to various values by the for loop. All subfunctions will see the last value bound, not the value it had in that iteration of the loop. In this case, the last value bound, in alphabetical order, is __subclasshook__, which tends to return NotImplemented when called with random arguments.

Post a Comment for "Python Object Wrapper"