Skip to content

@attr decorator sugar over getter/setter constructors #397

Description

@coretl

Adds the @attr decorator sugar over the getter=/setter= constructors from #392 (ADR 0018, 0014 review update).

Scope

  • @attr is a decorator only, two forms: bare @attr and parameterised @attr(precision=3, units="V", update_period=0.5) on an async getter, plus property-style @my_attr.setter on the writer.
    • getter only → AttrR; getter + .setterAttrRW (deferred creation). There is no @attr_r/@attr_rw.
    • No free-function attr() factory — the procedural spelling is AttrR(getter=…) / AttrRW(getter=…, setter=…) (from getter/setter IO rework; remove AttributeIORef and AttributeIO #392); @attr is pure sugar over it.
    • AttrW-only (write, no getter) is rare → written longhand as AttrW(setter=…), no decorator.
  • Datatype inferred from the getter's return annotation (unwrapping Update[T]); decorator kwargs typed Unpack[*Meta], validated against it. Getter docstring → attribute description.
  • Introspected vs decorated attrs: don't shadow already-defined ones; raise on name clash.
  • Built on the existing Unbound* bind machinery (fresh objects per instance, no prototype/deepcopy). Include the "FastCS for PyTango users" docs page.
  • Unblocks Example 1 — hello-world: pure-soft @attr decorator device #398 (hello-world uses @attr); Example 2 — attr getter/setter via __init__ (temperature backend) #404's __init__ getter/setter can also be shown in @attr form for contrast.

Key files (§9)

src/fastcs/methods/ (Unbound* bind machinery), attributes/.

Acceptance

uv run --locked tox -e pre-commit,type-checking,tests green; #398 (hello-world) green against @attr.

ADR: 0018, 0014
Parent: #388
Blocked by: #392, #413

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions