Aiven-Open / Aiven-Open/karapace

`karapace.protobuf.encoding_variants.write_varint` is broken

Open
#651 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
634
Forks
110
Avg merge
4d 7h
Merged PRs (30d)
4

Description

### What happened?

Another bug found while adding type-hints. `BytesIO.write()` does not accept an int, which is always the result of subscripting a `bytearray`. There does not seem to be any unit test coverage here.

https://github.com/aiven/karapace/blob/0d0ede8edbba65cc944bb5fbc5df28fdfcdd3bd3/karapace/protobuf/encoding_variants.py#L48

```pycon
>>> from karapace.protobuf.encoding_variants import *
>>> b = BytesIO()
>>> write_varint(b, 123)
Traceback (most recent call last):
File "", line 1, in
File "/Users/anton/aiven/karapace/karapace/protobuf/encoding_variants.py", line 65, in write_varint
bio.write(bytearray(to_write)[0])
TypeError: a bytes-like object is required, not 'int'
```

Not entirely clear what to do about this as it indicates that quite a lot of code is unused, i.e. if this breakage isn't affecting functionality.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.