You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, betterproto encodes protobuf oneOfs as a attributes of the enclosing class with one attribute per oneOf alternative. This leads to an akward runtime-encoding, where all attributes get an object with dummy data and the actual oneOf has non-dummy data. To distinguish those cases we need helper functions like serialized_on_wire() or which_on_of(), and the mypy type checker can't help us to ensure we've covered all alternatives. A better encoding would be Python unions (a.k.a Choice types), which get full exhaustiveness-support mypy support with Python 3.11 (https://docs.python.org/3.11/library/typing.html#typing.assert_never) and backwards compatible workaround for older Python versions (https://hakibenita.com/python-mypy-exhaustive-checking)
Would this other union encoding be suitable for betterproto?
The text was updated successfully, but these errors were encountered:
Currently, betterproto encodes protobuf oneOfs as a attributes of the enclosing class with one attribute per oneOf alternative. This leads to an akward runtime-encoding, where all attributes get an object with dummy data and the actual oneOf has non-dummy data. To distinguish those cases we need helper functions like
serialized_on_wire()
orwhich_on_of()
, and the mypy type checker can't help us to ensure we've covered all alternatives. A better encoding would be Python unions (a.k.a Choice types), which get full exhaustiveness-support mypy support with Python 3.11 (https://docs.python.org/3.11/library/typing.html#typing.assert_never) and backwards compatible workaround for older Python versions (https://hakibenita.com/python-mypy-exhaustive-checking)Would this other union encoding be suitable for betterproto?
The text was updated successfully, but these errors were encountered: