fix(sdk): coerce bytearray to bytes in process_request payload#1081
Merged
Conversation
mypy 2.0 (newly installed in CI) flagged that the bytes|bytearray branch assigned a bytearray into a payload typed dict[str, bytes]. Coerce with bytes(raw) — type-correct, and downstream urllib.request.Request wants bytes anyway.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
sdk-testsCI job is failing on every new PR after mypy 2.0 was picked up by the runner:```
modules/sdk/karrio/core/utils/helpers.py:177: error: Dict entry 0 has incompatible type "str": "bytes | bytearray"; expected "str": "bytes" [dict-item]
```
Root Cause
payloadis annotateddict[str, bytes](line 171), but theisinstance(raw, (bytes, bytearray))branch assigns the narrowedbytes | bytearray:```python
payload: dict[str, bytes] = {}
...
elif isinstance(raw, (bytes, bytearray)):
payload = dict(data=raw) # bytearray is not bytes
```
mypy 1.x accepted this; mypy 2.0 (now installed by
bin/setup-sdk-env) does not.Fix
One-line coercion to satisfy the declared type:
```python
payload = dict(data=bytes(raw))
```
bytes(bytes_instance)is a cheap no-op-equivalent andbytes(bytearray)produces equivalent bytes. Downstreamurllib.request.Requestrequires bytes-like data anyway, so behavior is unchanged.Tests
sdk-tests (3.12)job 75188611968).Why a separate PR
Spotted while CI was failing on an unrelated docs PR (#1080). Splitting this out so it can land independently and unblock all open PRs.