tag:blogger.com,1999:blog-2363643920942057324.post7579850449762006304..comments2023-08-09T23:00:54.857+10:00Comments on Graham Dumpleton: The interaction between decorators and descriptors.Graham Dumpletonhttp://www.blogger.com/profile/13609779138164842374noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-2363643920942057324.post-32713693379651864292014-05-25T13:02:36.089+10:002014-05-25T13:02:36.089+10:00@Daniel You misunderstand. The function_wrapper cl...@Daniel You misunderstand. The function_wrapper class is still used to handle the case where the function is first bound by the descriptor protocol. The bound_function_wrapper is the result of the binding process and not the starting point. It is similar to how instance methods in Python 2 exist in unbound and bound forms. It also isn't true that the methods of each are the same. The __call__Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-61189341438003529362014-05-25T02:41:28.345+10:002014-05-25T02:41:28.345+10:00In the blog you propose two separate classes. You...In the blog you propose two separate classes. You have function_wrapper to be used as a decorator for both normal functions and methods, and you have bound_function_wrapper, which is invoked to handle cases where function_wrapper is accessed as a descriptor. Does bound_function_wrapper need to exist? It seems that every place it might be invoked could be replaced by function_wrapper, since Daniel Sankhttps://www.blogger.com/profile/15330591180633811520noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-67529338757559000622014-01-09T10:26:27.067+11:002014-01-09T10:26:27.067+11:00True. I wanted to make is explicit as later on tha...True. I wanted to make is explicit as later on that constructor has extra arguments added which will be stored on the wrapper itself and used by other methods.Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-88208688098561527992014-01-09T10:23:33.687+11:002014-01-09T10:23:33.687+11:00class bound_function_wrapper(object_proxy):
def ...class bound_function_wrapper(object_proxy):<br /> def __init__(self, wrapped):<br /> super(bound_function_wrapper, self).__init__(wrapped)<br /><br />I may be unaware of some nuance here, but isn't an __init__ that just calls super.__init__ the same as having no __init__ defined at all in the subclass?eternicodehttps://www.blogger.com/profile/06575536753116773887noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-57937840985195674582014-01-08T08:47:10.574+11:002014-01-08T08:47:10.574+11:00If that inner decorator is itself implemented as a...If that inner decorator is itself implemented as a descriptor, placing it inside of @classmethod will not strictly work properly. This is an issue with @classmethod and was one of the things I expected to cover in the next post.Graham Dumpletonhttps://www.blogger.com/profile/13609779138164842374noreply@blogger.comtag:blogger.com,1999:blog-2363643920942057324.post-16381329221073176462014-01-07T23:09:39.920+11:002014-01-07T23:09:39.920+11:00On mixing descriptors and decorators, I've oft...On mixing descriptors and decorators, I've often advised people that the descriptor part should wrap the decorator part. For example:<br /><br />@staticmethod<br />@decorator<br />def func():<br /> ...<br /><br />But not this:<br /><br />@decorator<br />@staticmethod<br />def func():<br /> ...<br /><br />Curious if you had any thoughts about this?Unknownhttps://www.blogger.com/profile/00436489017052168136noreply@blogger.com