What's a good way to provide additional decoration/metadata for Python function parameters?

后端 未结 4 1541
生来不讨喜
生来不讨喜 2021-02-15 17:17

We\'re considering using Python (IronPython, but I don\'t think that\'s relevant) to provide a sort of \'macro\' support for another application, which controls a piece of equip

4条回答
  •  遇见更好的自我
    2021-02-15 18:05

    Decorators are a good way to add metadata to functions. Add one that takes a list of types to append to a .params property or something:

    def takes(*args):
        def _takes(fcn):
            fcn.params = args
            return fcn
        return _takes
    
    @takes("time", "temp", "time")
    def do_stuff(start_time, average_temp, stop_time):
        pass
    

提交回复
热议问题