fix(blocks): Dict block exposes N inputs and returns list#35
Open
PhotonicVelocity wants to merge 1 commit into
Open
fix(blocks): Dict block exposes N inputs and returns list#35PhotonicVelocity wants to merge 1 commit into
PhotonicVelocity wants to merge 1 commit into
Conversation
The Dict block class declares `nin = 1` and its __init__ never tells the base block how many ports the instance actually has, so `bd.DICT(["a", "b", "c"])` only exposes input 0 — wiring to dict[1] or dict[2] fails at compile with "list index out of range". The block's `output()` also returns a bare dict, but bdsim expects `list[Any]` (one entry per output port). Even after fixing nin the diagram errors with "block ... output ... must be a list: <class 'dict'>". Both issues are leftovers from the 2021-era refactor that split Item out of an Item-masquerading-as-Dict class. The neighboring Mux block already shows the correct variable-input pattern (`super().__init__( nin=nin, ...)` + list-wrapped `output()` return).
Not up to standards ⛔
|
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
Two bugs in
bdsim.blocks.connections.Dict. Together they makebd.DICT([...])unusable for any keys list longer than 1 (and brokeneven then, since the output isn't list-wrapped).
Bug 1 —
ninnot propagatedbd.DICT(["a", "b", "c"])exposes only input 0. Wiring todict_blk[1]ordict_blk[2]fails at compile with:Bug 2 —
output()returns bare dictbdsim expects
output()to returnlist[Any](one entry per outputport). Even after fixing bug 1, running a diagram with a Dict block
fails:
Fix
Mirrors the variable-input pattern in
Mux(~30 lines below in thesame file), which is correct:
nin: int = -1+super().__init__( nin=nin, ...)+ list-wrapped output.History
The original
class Dictintroduced in5b2bc33(May 2021) wasactually an Item-extractor (1 dict input → 1 value out). A later
refactor (
f7ba8b4) splitIteminto its own class and rewroteDict.output()to do the correct N→dict pack, but kept thenin = 1from the original Item-as-Dict implementation and forgotthe list-wrap.
Base
This PR is against
12b26c2("add the tagline") rather than currentmainHEAD because of #34 (current main can'timport bdsim— amissing
graphics_block.pyfrom a recent move). The fix is inconnections.pyand is orthogonal to the graphics breakage, so itshould rebase cleanly onto fixed-main.
Test plan
bd.DICT(["a", "b", "c"])reportsnin == 3.and runs.
No tests added to the bdsim test suite — leaving that to a broader
testing pass.