Add getter/setter decorators

Aperta
#467 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
54/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
6
Fork
8
Merge medio
3g 22h
PR unite (30g)
3

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DiamondLightSource/fastcs

Tutte le issue di DiamondLightSource/fastcs

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.