From bda1956ef48ab67dc9ffb144616d95443c9029a5 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sat, 7 Dec 2024 17:50:58 +0100 Subject: [PATCH] fix: Transmute error type in validation Allowing pydantic to properly handle it > validators should either return the parsed value or raise a ValueError or AssertionError https://docs.pydantic.dev/latest/concepts/validators/#field-validators --- src/qibolab/_core/instruments/qblox/ast_.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qibolab/_core/instruments/qblox/ast_.py b/src/qibolab/_core/instruments/qblox/ast_.py index 915d6b1e0..29081305b 100644 --- a/src/qibolab/_core/instruments/qblox/ast_.py +++ b/src/qibolab/_core/instruments/qblox/ast_.py @@ -22,7 +22,10 @@ class Register(Model): @model_validator(mode="before") @classmethod def load(cls, data: Any) -> Any: - assert data[0] == "R" + try: + assert data[0] == "R" + except TypeError: + raise ValueError("Register representation is not a string") num = int(data[1:]) assert 0 <= num < 64 return {"number": num}