python - Unable to decorate a class method using Pint units -


here's simple example in effort decorate class method using pint,

from pint import unitregistry  ureg = unitregistry() q_ = ureg.quantity  class simple:     def __init__(self):     pass  @ureg.wraps('m/s', (none, 'm/s'), true) def calculate(self, a, b):     return a*b  if __name__ == "__main__":     c = simple().calculate(1, q_(10, 'm/s'))     print c 

this code results in below valueerror.

traceback (most recent call last):    c = simple().calculate(1, q_(10, 'm/s'))    file "build/bdist.macosx-10.11-intel/egg/pint/registry_helpers.py",   line 167, in wrapper    file "build/bdist.macosx-10.11-intel/egg/pint/registry_helpers.py", line 118, in _converter    valueerror: wrapped function using strict=true requires quantity arguments not none units. (error found m / s, 1) 

it seems me issue here may class instances being passed pint decorator. have solution fixing this?

i think error message pretty clear. in strict mode arguments have given quantity yet give second argument such.

you either give first argument quantity too

if __name__ == "__main__":     c = simple().calculate(q_(1, 'm/s'), q_(10, 'm/s'))     print c 

or disable strict mode, believe looking for.

    ...     @ureg.wraps('m/s', (none, 'm/s'), false)     def calculate(self, a, b):         return a*b  if __name__ == "__main__":     c = simple().calculate(1, q_(10, 'm/s'))     print c 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -