How to find class of bound method during class construction in Python 3.1? -
I want to write a decorator that enables other parties to see the class; The problem I am describing is independent of that extension, however. The code looks roughly like this:
def CLASS_WHERE_METHOD_IS_DEFINED (method): ??? DF FOOBAR (PRINT): PRINT (CLASS_WHERE_METHOD_IS_DEFINED) SECTION X: @ FOBOR DEFF (self, X): return x ** 2
My problem is that very moment That decorator, forums ()
, to see the method, it is not yet callable; Instead, it can be found to see its unbound version, that it can be solved by using another decorator on that class, which should be taken care of what should be done for the bound method. The next thing I will try to do is to set the method of decoration with only one attribute when it goes through the decorator, and then use a metacalls to do a class decorator or post processing. If I find that work, then I do not have to solve this puzzle, which still makes the puzzle:
Anyone, in the above code, CLASS_WHERE_METHOD_IS_DEFINED
so that The decorator can actually print the class where f
is defined, the moment it is defined? Or is this unlikely in dragon 3?
When called decorator, it is called with the function, its argument, not < / Em> One method - therefore, it will not take advantage of the decorator to check and introspect its method as much as it wants, because it is only a function and there is no information about the attached class. I hope this solves your "puzzle", though in the negative sense!
Other methods can be tried, such as deep introspection on nested stack frames, but these hacks are not fragile and definite, for other implementation of Python 3 such as Pini; That's why I recommend to avoid them with heart, in favor of a class-decorator solution, which you are already thinking and very clear and more solid.
Comments
Post a Comment