Skip to content

Commit

Permalink
Merge pull request #89 from hnez/ruff-2025-01-29
Browse files Browse the repository at this point in the history
usbsdmux: sd_regs: Fix ruff error regarding the use of percent formatting
  • Loading branch information
SmithChart authored Jan 30, 2025
2 parents 051f381 + 8b8c730 commit a90da1e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions usbsdmux/sd_regs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ def decoded_to_text(decoded):
text.append(f" {f['field']}: {f['name']}")
else:
text.append(f" {f['field']}")
raw = f["raw"]
text.append(f" raw: 0b{format(raw[0], '0%db' % raw[1])} == 0x{raw[0]:0x} == {int(raw[0])}")

(raw_value, raw_width) = f["raw"]

# Pad the binary representation of `raw_value` to the number of bits of the field.
bits_str = format(raw_value, f"0{raw_width}b")
text.append(f" raw: 0b{bits_str} == 0x{raw_value:0x} == {int(raw_value)}")

if "enum" in f:
text.append(f" enum: {f['enum']} {f.get('unit', '')}".rstrip())
if "bits" in f:
Expand Down

0 comments on commit a90da1e

Please sign in to comment.