danielgtaylor / danielgtaylor/python-betterproto

Gracefully handle encoding of different number types

Open
#84 1 comment 0 reactions 0 assignees View on GitHub
bug good first issue high priority small
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

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'
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue by assigning a float to an int-typed Message field and serialising it, then inspect the encoding path that raises the reported operand-type error. The payload names no files or tests; done means the value serialises without that exception and follows the intended numeric representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.