Skip to content

fix(colors): str2bgra() silently ignored its alpha argument#316

Open
ywatanabe1989 wants to merge 1 commit into
developfrom
fix/str2bgra-alpha
Open

fix(colors): str2bgra() silently ignored its alpha argument#316
ywatanabe1989 wants to merge 1 commit into
developfrom
fix/str2bgra-alpha

Conversation

@ywatanabe1989

Copy link
Copy Markdown
Collaborator

The bug

str2bgra() accepted an alpha argument and then discarded it, so the returned alpha channel was always 1.0 regardless of what the caller passed.

def str2bgra(c, alpha=1.0):
    return rgba2bgra(str2rgba(c))   # alpha never forwarded

Why this looks unintended rather than deliberate

  • str2rgba(c, alpha=1.0) (same file, L21-24) does honour the parameter.
  • The deprecated wrapper to_rgba (L177) calls str2rgba(c, alpha=alpha) — the intended shape.

The fix

One line: forward alpha through. Blast radius is zero — str2bgra is referenced only at its own definition and is not re-exported from colors/__init__.py.

Verification (run in both directions)

  • Before the fix: 2 failed, 5 passed — assert 1.0 == 0.3
  • After the fix: 7 passed; the whole tests/figrecipe/colors/ suite is green

Three regression tests added: alpha is honoured, the default stays opaque, and channel order is pinned against str2rgba so a later change cannot silently swap B and R.

Note for maintainers

This repo's .venv is broken inside the agent container (bin/python3.11 is a dangling symlink; only 3.12 is present), so the tests had to be run through a throwaway 3.12 venv. Reported separately — it is independent of this change.

Found while surveying the codebase for newcomer-friendly issues.

str2bgra(c, alpha=...) accepted alpha but called str2rgba(c) without
it, so every BGRA colour came back fully opaque no matter what the
caller asked for. str2rgba already honours the parameter, and the
deprecated to_rgba wrapper shows the intended call shape
(str2rgba(c, alpha=alpha)).

Pass alpha through, and add regression tests covering the explicit
alpha, the opaque default, and the channel order against str2rgba.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant