44from collections .abc import Callable
55from typing import Generic
66
7- from typing_extensions import TypeVar
8-
97import fastcs
10- from fastcs .attribute_io_ref import AttributeIORef
118
9+ from .attribute_io_ref import AttributeIORefT
1210from .datatypes import ATTRIBUTE_TYPES , AttrSetCallback , AttrUpdateCallback , DataType , T
1311
14- # TODO rename this: typevar with default
15- AttributeIORefTD = TypeVar (
16- "AttributeIORefTD" , bound = AttributeIORef , default = AttributeIORef , covariant = True
17- )
18-
1912ONCE = float ("inf" )
2013"""Special value to indicate that an attribute should be updated once on start up."""
2114
2215
23- class Attribute (Generic [T , AttributeIORefTD ]):
16+ class Attribute (Generic [T , AttributeIORefT ]):
2417 """Base FastCS attribute.
2518
2619 Instances of this class added to a ``Controller`` will be used by the backend.
@@ -29,7 +22,7 @@ class Attribute(Generic[T, AttributeIORefTD]):
2922 def __init__ (
3023 self ,
3124 datatype : DataType [T ],
32- io_ref : AttributeIORefTD | None = None ,
25+ io_ref : AttributeIORefT | None = None ,
3326 group : str | None = None ,
3427 description : str | None = None ,
3528 ) -> None :
@@ -48,7 +41,7 @@ def __init__(
4841 self ._update_datatype_callbacks : list [Callable [[DataType [T ]], None ]] = []
4942
5043 @property
51- def io_ref (self ) -> AttributeIORefTD :
44+ def io_ref (self ) -> AttributeIORefT :
5245 if self ._io_ref is None :
5346 raise RuntimeError (f"{ self } has no AttributeIORef" )
5447 return self ._io_ref
@@ -86,13 +79,13 @@ def update_datatype(self, datatype: DataType[T]) -> None:
8679 callback (datatype )
8780
8881
89- class AttrR (Attribute [T , AttributeIORefTD ]):
82+ class AttrR (Attribute [T , AttributeIORefT ]):
9083 """A read-only ``Attribute``."""
9184
9285 def __init__ (
9386 self ,
9487 datatype : DataType [T ],
95- io_ref : AttributeIORefTD | None = None ,
88+ io_ref : AttributeIORefT | None = None ,
9689 group : str | None = None ,
9790 initial_value : T | None = None ,
9891 description : str | None = None ,
@@ -133,13 +126,13 @@ async def update(self):
133126 await asyncio .gather (* [cb () for cb in self ._on_update_callbacks ])
134127
135128
136- class AttrW (Attribute [T , AttributeIORefTD ]):
129+ class AttrW (Attribute [T , AttributeIORefT ]):
137130 """A write-only ``Attribute``."""
138131
139132 def __init__ (
140133 self ,
141134 datatype : DataType [T ],
142- io_ref : AttributeIORefTD | None = None ,
135+ io_ref : AttributeIORefT | None = None ,
143136 group : str | None = None ,
144137 description : str | None = None ,
145138 ) -> None :
@@ -180,7 +173,7 @@ def add_write_display_callback(self, callback: AttrSetCallback[T]) -> None:
180173 self ._write_display_callbacks .append (callback )
181174
182175
183- class AttrRW (AttrR [T , AttributeIORefTD ], AttrW [T , AttributeIORefTD ]):
176+ class AttrRW (AttrR [T , AttributeIORefT ], AttrW [T , AttributeIORefT ]):
184177 """A read-write ``Attribute``."""
185178
186179 async def process (self , value : T ) -> None :
0 commit comments