Dynamically created method and decorator, got error 'functools.partial' object has no attribute '__module__'

前端 未结 7 640
面向向阳花
面向向阳花 2020-12-31 01:58

I am currently using EndpointsModel to create a RESTful API for all my models on AppEngine. Since it is RESTful, these api have a lot of repeat code which I want to avoid.

相关标签:
7条回答
  • 2020-12-31 02:49

    A pretty convenient solution for python 2.7 is described here: http://louistiao.me/posts/adding-name-and-doc-attributes-to-functoolspartial-objects/

    Namely:

    from functools import partial, update_wrapper
    
    def wrapped_partial(func, *args, **kwargs):
        partial_func = partial(func, *args, **kwargs)
        update_wrapper(partial_func, func)
    
        return partial_func
    
    0 讨论(0)
提交回复
热议问题