跳转到主要内容

具有超能力的属性

项目描述

reacttrs

reacttrs,最初从 Textual 中提取出来,现在是 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

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

reacttrs-0.2.1.tar.gz (3.5 kB 查看哈希值)

上传时间:

构建分布

reacttrs-0.2.1-py3-none-any.whl (4.4 kB 查看哈希值)

上传时间: Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面