Skip to main content

Attributes with superpowers

Project description

reacttrs

Reactive attributes, initially extracted out from Textual, now a fork of Declare.

from reacttrs import Int, Str


class Foo:

    name = Str("Paul")
    age = Int(34)
    birth = Int(1990)

    @name.watch
    def _watch_name(self, old: str, new: str):
        print(f"{old=}, {new=}")

    @age.validate
    def _validate_age(self, value: int) -> int:
        return 2024 - self.birth

foo = Foo()
foo.name = "John"  # old='Paul', new='John'
foo.name = "Steve"  # old='John', new='Steve'

print(foo.age)  # 34
foo.birth = 1991
foo.age = 34
print(foo.age)  # 33

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reacttrs-0.2.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reacttrs-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file reacttrs-0.2.0.tar.gz.

File metadata

  • Download URL: reacttrs-0.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for reacttrs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 478f83e35f0d3649d1b1c3059aa07dfde9291f865fcc576277e8f4d8b2d882f2
MD5 f4804b9e43ee182ed26e01dc834f7baa
BLAKE2b-256 31ed0c8fb3df5ec74040c2449469d25fe3feedfde631e32b9f7018e4a0b4fb4b

See more details on using hashes here.

File details

Details for the file reacttrs-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: reacttrs-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for reacttrs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91a07d0cf1798b9b09513fbe00986d2aa31c3e06fee49ff3e2dbc71255c81d11
MD5 ed32a140409bf517005a3f985ec5b8d4
BLAKE2b-256 cc5b47748c1df04494c83a43cbc2b98001f1ee5f738ac01c03ae043e721f884f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page