Make all setter functions consistently return bytearray#585
Open
gijzelaerr wants to merge 1 commit intomasterfrom
Open
Make all setter functions consistently return bytearray#585gijzelaerr wants to merge 1 commit intomasterfrom
gijzelaerr wants to merge 1 commit intomasterfrom
Conversation
set_fstring, set_string, set_dword, set_dint, and set_udint now return the modified bytearray, matching the behavior of all other setters. Fixes #553 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #553
Five setter functions (
set_fstring,set_string,set_dword,set_dint,set_udint) returnedNonewhile all other setters (set_bool,set_byte,set_word,set_int,set_uint,set_real,set_usint,set_sint,set_lreal,set_char,set_date,set_time) returned the modifiedbytearray. This inconsistency prevented idiomatic chaining like:Root cause analysis
The setters were written at different times by different contributors. The earlier setters followed the pattern of returning the modified buffer, but the later additions (
set_dword,set_dint,set_udint) and the string setters (set_fstring,set_string) simply forgot thereturnstatement. Since Python functions implicitly returnNone, these silently broke concatenation-based patterns.Fix
Added
return bytearray_to all five functions and updated their type annotations from-> Noneto-> bytearray. This is a backwards-compatible change — existing code that ignores the return value continues to work identically, since the functions still modify the bytearray in-place.Test plan
set_udint(bytearray(4), 0, 123) + set_uint(bytearray(2), 0, 456)now works🤖 Generated with Claude Code