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

前端 未结 7 638
面向向阳花
面向向阳花 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
    

提交回复
热议问题