danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.47k stars 205 forks source link

Gracefully handle encoding of different number types #84

Open nat-n opened 4 years ago

nat-n commented 4 years ago

If a float is set on a Message field of type int then an exception is raised when serialising. Floats and ints are largely interchangeable in python3, so maybe betterproto should handle this more gracefully, by for example: casting to int or float as appropriate before encoding.

The resulting error message includes:

unsupported operand type(s) for &: 'float' and 'int'
boukeversteegh commented 4 years ago

Somewhat related: