Replace IO and IORefs with getters/setters

Abierto
#466 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 6 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Start by reading the existing AttributeIO and AttributeIORef implementations and controller attribute APIs; this issue does not name their file paths or tests. Review the linked prerequisite issue #442 and trace how attributes are read, written, polled, and mirrored to transports. Done means replacing IO and IORef usage with per attribute getters and setters and meeting the acceptance criteria.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

IOs and IORefs make writing simple controllers verbose:

@dataclass
class HelloIORef(AttributeIORef):
    key: str
    _: KW_ONLY
    update_period: float | None = 0.5

class HelloIO(AttributeIO[Any, HelloIORef]):
    def __init__(self, device): super().__init__(); self._device = device
    async def update(self, attr): 
        await attr.update(await self._device.get(attr.io_ref.key))
    async def send(self, attr, value):
        await self._device.set(attr.io_ref.key, value)

class HelloController(Controller):
    message = AttrR(String(),  io_ref=HelloIORef("message"))
    def __init__(self):
        self._device = HelloDevice()
        super().__init__(ios=[HelloIO(self._device)])

We should replace AttributeIO/AttributeIORef with per-attribute getter/setter callables:

class HelloController(Controller):
    def __init__(self, device):
        self._device = device
        super().__init__()

        self.message = AttrRW(
            String(),  # optional: would be inferred from `-> str`
            getter=Polled(self._get_message, period=1.0),
            setter=self._set_message,
        )

    async def _get_message(self) -> str:
        return await self._device.get("message")

    async def _set_message(self, message: str) -> None:
        await self._device.set("message", message)
  • Scheduling: bare getter → read once on connect; Polled(fn, period=...) → polled;
    NotPolled(fn) → only on await attr.poll()
  • Datatype inferred from getter return / setter parameter (int, float, bool, str, Enum)
  • Getters/setters may return Update(readback, setpoint=...); a setter's bare return
    value is the device-accepted value
  • Attribute owns the setpoint; all transports mirror it via add_setpoint_callback
    (removes per-transport seeding)

Breaking changes

  • ios= removed from controllers; AttributeIO, AttributeIORef removed
  • Attribute[T, Ref] → Attribute[T], as no reference required
  • get()→.readback, put()→set(), callback renames, removed methods (list)
  • update_period=None refs should migrate to NotPolled

Depends on https://github.com/DiamondLightSource/fastcs/issues/442.

Acceptance Criteria

  • IOs and IORefs are replaced with getter/setter
Lenguaje dominante
Python
Estrellas
6
Forks
8
Merge medio
3 d 22 h
PR fusionados (30 d)
3

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DiamondLightSource/fastcs

Todos los issues de DiamondLightSource/fastcs

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.