Skip to content

Commit fe721a4

Browse files
committed
Correct the type for RunMode.build_mode
This is a bit of an ugly dance, but checks the type properly at run-time and also convinces Pyright about the existence and type of RunMode.build_mode. Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
1 parent d01d4df commit fe721a4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/dvsim/modes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,21 @@ def __init__(self, rdict) -> None:
301301
self.run_opts = []
302302
self.uvm_test = ""
303303
self.uvm_test_seq = ""
304-
self.build_mode = ""
305304
self.run_timeout_mins = None
306305
self.run_timeout_multiplier = None
307306
self.sw_images = []
308307
self.sw_build_device = ""
309308
self.sw_build_opts = []
310309

311310
super().__init__("run mode", rdict)
311+
312+
# The base class constructor should have provided a BuildMode object in
313+
# self.build_mode. Check this at run-time. The odd
314+
# build_mode=build_mode line is to teach the pyright about the field.
315+
if not isinstance(self.build_mode, BuildMode):
316+
raise TypeError("build_mode not computed by constructor")
317+
self.build_mode: BuildMode = self.build_mode
318+
312319
self.en_run_modes = list(set(self.en_run_modes))
313320

314321
def get_sub_modes(self) -> list[str]:

0 commit comments

Comments
 (0)