66from pvi .device import SignalR
77from pydantic import ValidationError
88
9- from fastcs .attributes import AttrR , AttrRW
9+ from fastcs .attributes import Attribute , AttrMode , AttrR , AttrRW
1010from fastcs .backend import Backend
1111from fastcs .controller import Controller , SubController
1212from fastcs .datatypes import Bool , Enum , Float , Int , String
@@ -125,6 +125,15 @@ class ControllerWrongEnumClass(Controller):
125125 "Expected 'MyEnum', got 'MyEnum2'."
126126 )
127127
128+ class ControllerUnspecifiedAccessMode (Controller ):
129+ hinted : Attribute [int ]
130+
131+ async def initialise (self ):
132+ self .hinted = Attribute (Int (), access_mode = AttrMode .READ )
133+
134+ # no assertion thrown
135+ Backend (ControllerUnspecifiedAccessMode (), loop )
136+
128137
129138def test_hinted_attributes_verified_on_subcontrollers ():
130139 loop = asyncio .get_event_loop ()
@@ -142,3 +151,25 @@ async def initialise(self):
142151
143152 with pytest .raises (RuntimeError , match = "failed to introspect hinted attribute" ):
144153 Backend (TopController (), loop )
154+
155+
156+ def test_hinted_attribute_types_verified ():
157+ # test verification works with non-GenericAlias type hints
158+ loop = asyncio .get_event_loop ()
159+
160+ class ControllerAttrWrongAccessMode (Controller ):
161+ read_attr : AttrR
162+
163+ async def initialise (self ):
164+ self .read_attr = AttrRW (Int ())
165+
166+ with pytest .raises (RuntimeError , match = "does not match defined access mode" ):
167+ Backend (ControllerAttrWrongAccessMode (), loop )
168+
169+ class ControllerUnspecifiedAccessMode (Controller ):
170+ unspecified_access_mode : Attribute
171+
172+ async def initialise (self ):
173+ self .unspecified_access_mode = AttrRW (Int ())
174+
175+ Backend (ControllerUnspecifiedAccessMode (), loop )
0 commit comments