From db564d797704b4d16542871a41694f17b71182a6 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 30 Jul 2022 14:27:50 -0400 Subject: [PATCH] Add casting method to our struct variant --- piker/data/types.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/piker/data/types.py b/piker/data/types.py index c6cba61d..d8926610 100644 --- a/piker/data/types.py +++ b/piker/data/types.py @@ -66,3 +66,10 @@ class Struct( ).decode( msgspec.msgpack.Encoder().encode(self) ) + + def typecast( + self, + # fields: Optional[list[str]] = None, + ) -> None: + for fname, ftype in self.__annotations__.items(): + setattr(self, fname, ftype(getattr(self, fname)))