Add getter/setter decorators

Abierto
#467 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
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
54/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

Read the getter/setter constructors from #466 and typed metadata work in #442, along with the migration decisions linked in the description. Trace how controller attributes are created and bound to each instance, then add coverage for bare and parameterised @attr, setter behavior, annotations, metadata, and polling defaults. Update the docs for the decorator form; done when the acceptance criteria pass.

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

Descripción

As part of migrating changes from #402 (see #388, decision 14, and #423), attributes should be declarable by decorating the controller method that reads them. Even with getters/setters (#466), the simplest case still needs the attribute wired up by hand in __init__. Using decorators, we can have:

class PowerSupply(Controller):
    @attr(Polled(period=0.5), units="V")
    async def voltage(self) -> float:
        """Output voltage."""
        return float(await self._conn.query("V?"))

    @voltage.setter
    async def voltage(self, value: float) -> None:
        await self._conn.send(f"V={value}")

which is shorthand built on the getter=/setter= constructors, and thus depends on that work being done.

Depends on #466 (getter/setter) and #442 (typed metadata keyword arguments).

Acceptance Criteria

  • @attr (bare or parameterised) on a getter creates an AttrR; adding
    @x.setter makes it an AttrRW
  • The datatype comes from the getter's return annotation, and the description
    from its docstring
  • Decorator keyword arguments are the attribute's metadata; an optional schedule
    (Polled/NotPolled) controls polling, with the same defaults as getter=
  • Each controller instance gets its own attribute, bound to that instance
  • Docs cover the decorator form
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.