Repository navigation
Simplify convert_from/to_registers (remove noqa: C901). - #3098
Merged
janiversen merged 5 commits intoNov 25, 2026
Merged
janiversen merged 5 commits into
janiversen merged 5 commits into
Conversation
data_len held the number of registers per value, not a data length, and data_type_len held the same quantity under a different name. Both are now regs_per_value; reg_len -> registers_count and the loop index x -> start.
data_type.value[0] is an anonymous tuple index; name it struct_format (the struct format character of the data type). In convert_to_registers it is also computed once instead of once per value.
The word-order handling and register -> bytes loop was written twice (once for STRING/BITS, once per numeric value). Extract it into _registers_to_bytes(). This brings convert_from_registers under the ruff C901 limit, so the "# noqa: C901" suppression is removed.
Each branch of the BITS / STRING / numeric if-elif-else validated and packed the value inline. Move each branch body into an intention revealing helper (_bits_to_bytes, _string_to_bytes, _values_to_bytes) so convert_to_registers reads as a dispatch on data type.
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.
convert_from_registerscarries the last# noqa: C901in the library. This PR does for it what #3082 did forexecute, without changing behaviour:_registers_to_bytes(). The word-order handling and register -> bytes loop was written twice inconvert_from_registers. The method is now under the C901 limit, so thenoqais removed.convert_to_registersinto_bits_to_bytes(),_string_to_bytes()and_values_to_bytes().data_len/data_type_lentoregs_per_value, the number of registers per value (it was not a data length).data_type.value[0]asstruct_formatinstead of indexing the tuple inline.Public API, error messages and results are unchanged. The existing converter tests pass unmodified, and
check_ci.shpasses locally with coverage at 100%. This does not overlap with #3068.