Repository navigation
Fix i2c_msg.__bytes__ return type in the type stub - #148
Open
abdurrahman-nexthop wants to merge 1 commit into
Open
abdurrahman-nexthop wants to merge 1 commit into
abdurrahman-nexthop wants to merge 1 commit into
Conversation
i2c_msg.__bytes__ is declared as returning str, but it returns
ctypes.string_at(self.buf, self.len)
which is bytes. The class's own __str__ relies on that -- it calls
self.__bytes__().decode(errors="ignore"), which is only valid on bytes.
Because the package is py.typed, this propagates to callers: bytes(msg)
is inferred as str, so passing the result anywhere expecting bytes is
reported as an error by a type checker.
Same class of issue as kplindegaard#142 / kplindegaard#143, which corrected __iter__ on the
neighbouring line.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
kplindegaard
approved these changes
Sep 28, 2026
Owner
|
Thanks :) |
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.



i2c_msg.__bytes__is declared insmbus2.pyias returningstr, but the implementation returnsctypes.string_at(self.buf, self.len), which isbytes:https://github.com/kplindegaard/smbus2/blob/master/smbus2/smbus2.py#L181-L182
The class's own
__str__depends on that — it callsself.__bytes__().decode(errors="ignore"), which is only valid onbytes.Since the package is
py.typed, the wrong annotation propagates to callers:bytes(msg)is inferred asstr, so passing the result anywhere that expectsbytesis reported as an error.Same class of issue as #142 / #143, which corrected
__iter__on the neighbouring line.🤖 Generated with Claude Code