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

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

    I stumbled upon this and thought would mention my workaround for this.

    As rightly mentioned by @samy-vilar python3 doesn't have this issue. I have some code that uses functools.wrap and needs to run on python2 as well as python3.

    For python2 we use functools32 which is backport of python3's functools for python2. wraps implementation of this package works perfect. Additionally it provides lru_cache which is available only in python3 functools.

    import sys 
    
    if sys.version[0] == '2':
       from functools32 import wraps
    else:
       from functools import wraps
    

提交回复
热议问题