Skip to content

Commit 588c3d1

Browse files
committed
fix(types): clear ty-check diagnostics on main paths
Three residual ``ty check`` diagnostics (pre-existing — not introduced by this branch, but worth clearing now that the workflow actually runs on a useful file set): - ``adidt/xsa/builders/adrv9009.py:680`` — ``render_dt(cs=trx2_cs)`` had ``trx2_cs: int | None`` at the call site. The caller is inside ``if is_fmcomms8:`` where ``trx2_cs`` is always an int, so narrow with an explicit ``assert is not None`` — documents the invariant the surrounding code already relies on. - ``adidt/xsa/builders/fmcdaq2.py:197`` — the AD9523 channel specs were a list of dicts with mixed ``int | str`` values, so ``_m1 // s["divider"]`` was ``int // (int | str)``. Replace with a list of typed 3-tuples ``(id: int, name: str, divider: int)`` and unpack at iteration. Same runtime behaviour, cleaner type. - ``adidt/devices/fpga_ip/adxcvr.py:62`` — the ``use_div40`` branch only guarded ``self.jesd_l is not None`` but also dereferenced ``self.jesd_m`` and ``self.jesd_s`` (both ``int | None``). Widen the guard to narrow all three. Fixes two of the three lines emitting ``adi,jesd-{l,m,s}``. Also update the ``Type Check (ty)`` workflow to target the actual typed surface: drop the stale ``adidt/boards/`` path (directory was removed during the re-arch) and add ``adidt/devices/``, ``adidt/system.py``, ``adidt/tools/``. ``ty check`` now finishes with "All checks passed!" on the main paths.
1 parent 1f8faea commit 588c3d1

4 files changed

Lines changed: 32 additions & 17 deletions

File tree

.github/workflows/type-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Run ty type checker
3535
continue-on-error: true
3636
run: |
37-
ty check adidt/model/ adidt/boards/ adidt/xsa/builders/ 2>&1 | tee ty_report.txt
37+
ty check adidt/model/ adidt/xsa/builders/ adidt/devices/ adidt/system.py adidt/tools/ 2>&1 | tee ty_report.txt
3838
echo "## Type Check Report (ty)" >> $GITHUB_STEP_SUMMARY
3939
echo '```' >> $GITHUB_STEP_SUMMARY
4040
tail -5 ty_report.txt >> $GITHUB_STEP_SUMMARY

adidt/devices/fpga_ip/adxcvr.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ def extra_dt_lines(self, context: dict | None = None) -> list[str]:
5959
lines.append('clock-names = "conv";')
6060
if self.clock_output_names_str:
6161
lines.append(f"clock-output-names = {self.clock_output_names_str};")
62-
if self.use_div40 and self.jesd_l is not None:
62+
if (
63+
self.use_div40
64+
and self.jesd_l is not None
65+
and self.jesd_m is not None
66+
and self.jesd_s is not None
67+
):
6368
lines.append(f"adi,jesd-l = <{int(self.jesd_l)}>;")
6469
lines.append(f"adi,jesd-m = <{int(self.jesd_m)}>;")
6570
lines.append(f"adi,jesd-s = <{int(self.jesd_s)}>;")

adidt/xsa/builders/adrv9009.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ def build_model(
666666

667667
if is_fmcomms8:
668668
# Second chip: its own clocks, cs, reset; no sysref-req-gpios.
669+
# ``trx2_cs`` is always an int on the is_fmcomms8 branch (see
670+
# the earlier ``trx2_cs = int(board_cfg.get(...))`` assignment);
671+
# narrow the type here so downstream callers of ``render_dt``
672+
# see a concrete ``int``.
673+
assert trx2_cs is not None
669674
phy2_dev = ADRV9009(
670675
label=f"trx1_{phy_family}",
671676
node_name_base=f"{phy_family}-phy",

adidt/xsa/builders/fmcdaq2.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,29 @@ def board_int(key: str, default: Any) -> int:
179179

180180
# --- Build devices ---
181181
_m1 = 1_000_000_000 # adi,pll2-m1-freq distribution frequency
182-
ad9523_channel_specs = [
183-
{"id": 1, "name": "DAC_CLK", "divider": 1},
184-
{"id": 4, "name": "ADC_CLK_FMC", "divider": 2},
185-
{"id": 5, "name": "ADC_SYSREF", "divider": 128},
186-
{"id": 6, "name": "CLKD_ADC_SYSREF", "divider": 128},
187-
{"id": 7, "name": "CLKD_DAC_SYSREF", "divider": 128},
188-
{"id": 8, "name": "DAC_SYSREF", "divider": 128},
189-
{"id": 9, "name": "FMC_DAC_REF_CLK", "divider": 2},
190-
{"id": 13, "name": "ADC_CLK", "divider": 1},
182+
# Each spec tuple is (id, name, divider). Using a typed tuple
183+
# here instead of a dict-of-mixed-types keeps the `int // int`
184+
# below type-checkable — a heterogeneous-value dict infers
185+
# ``int | str`` for lookups and the divider expression fails
186+
# ``ty check`` with ``unsupported-operator``.
187+
ad9523_channel_specs: list[tuple[int, str, int]] = [
188+
(1, "DAC_CLK", 1),
189+
(4, "ADC_CLK_FMC", 2),
190+
(5, "ADC_SYSREF", 128),
191+
(6, "CLKD_ADC_SYSREF", 128),
192+
(7, "CLKD_DAC_SYSREF", 128),
193+
(8, "DAC_SYSREF", 128),
194+
(9, "FMC_DAC_REF_CLK", 2),
195+
(13, "ADC_CLK", 1),
191196
]
192197
ad9523_channels = {
193-
s["id"]: AD9523Channel(
194-
id=s["id"],
195-
name=s["name"],
196-
divider=s["divider"],
197-
freq_str=fmt_hz(_m1 // s["divider"]),
198+
ch_id: AD9523Channel(
199+
id=ch_id,
200+
name=name,
201+
divider=divider,
202+
freq_str=fmt_hz(_m1 // divider),
198203
)
199-
for s in ad9523_channel_specs
204+
for ch_id, name, divider in ad9523_channel_specs
200205
}
201206
clock_gpio_lines = []
202207
for prop, val in (

0 commit comments

Comments
 (0)