[Python-Dev] update_wrapper should preserve staticmethod behavior (original) (raw)
Calvin Spealman ironfroggy at socialserve.com
Wed Jun 11 20:56:25 CEST 2008
- Previous message: [Python-Dev] update_wrapper should preserve staticmethod behavior
- Next message: [Python-Dev] update_wrapper should preserve staticmethod behavior
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
staticmethod doesn't wrap anything, it just creates a descriptor on
the class with a get that returns the original, untouched
callable. Doesn't even care what the thing you use it on is
(function, other callable, or something else entirely.)
This actually shouldn't be attempted on non-staticmethod descriptors,
after thinking about it. Can't be sure that desc.get(cls) is
usable to wrap when, at the end, you will be doing some_instance.a
and now had the wrong get() signature used. Oh, no!
class A(object): @d @some_decorator_returns_a_descriptor def a(): pass
What should probably happen here is that d needs to see its
decorating a descriptor and itself return a descriptor to pass along
the right behavior. So, when you do A().a() you should have d.get
(cls, inst) calling some_decorator_returns_a_descriptor.get(cls,
inst) and acting as if that was the thing it decorated.
Of course, this would have the probably unexpected behavior of
decorating such things at binding time (ie, when a classmethod is
bound) rather than after definition. Not good. They could be cached
and this used to implement new functionality that the decorator can
be applied to the class method once for each class its bound to
(interesting? useful?), but I can't think of a justification myself.
Unless any of this other behavior could be justified, I'll provide an
update_wrapper() patch to at least become staticmethod smart.
On Jun 11, 2008, at 1:48 PM, Antoine Pitrou wrote:
Calvin Spealman <ironfroggy socialserve.com> writes:
Traceback (most recent call last): File "", line 1, in File "", line 3, in A File "", line 5, in d File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/functools.py", line 33, in updatewrapper setattr(wrapper, attr, getattr(wrapped, attr)) AttributeError: 'staticmethod' object has no attribute 'module' Well, if staticmethod doesn't mirror the original function's module attribute, I'd say staticmethod is the culprit. Since Python grew the updatewrapper function, it seems reasonable to ask that all decorators (or decorator-alikes) provided with Python call updatewrapper. Of course staticmethod is written in C, so is there a C function somewhere providing the same functionality as updatewrapper does?
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/ ironfroggy%40socialserve.com
- Previous message: [Python-Dev] update_wrapper should preserve staticmethod behavior
- Next message: [Python-Dev] update_wrapper should preserve staticmethod behavior
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]