Add getter/setter decorators

オープン
#467 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
54/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Python
スター
6
フォーク
8
平均マージ
3日 22時間
マージ済み PR(30日)
3

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DiamondLightSource/fastcs のほかの issue

DiamondLightSource/fastcs の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。