IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Juq Technical Documentation

    Inhzus发表于 2019-03-26 14:17:42
    love 0

    Some exellent technical practice in the development of Juq.

    Decorators for functions in a module

    def decarate_module(module, decorator: types.FunctionType):
     for name in dir(module):
     method = getattr(module, name)
     if isinstance(method, types.FunctionType):
     setattr(module, name, decorator(method))
     return module
    

    Usage: e.g. Serialize all return values for functions in a module

    dataclass

    Reason

    e.g.

    def Example(object):
     def __init__(self, a: int, b: str, c: str, d: str, e: str, f: str, g: str, ...):
     self.a = a
     self.b = b
     self.c = c
     ...
    

    Common method of constructor is a waste of time and code space.



沪ICP备19023445号-2号
友情链接