Skip to content

Commit 552df49

Browse files
Fork declare (#3)
1 parent 6f7e313 commit 552df49

File tree

8 files changed

+311
-311
lines changed

8 files changed

+311
-311
lines changed

Diff for: .github/workflows/test.yml

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Test
22

33
on:
44
push:
@@ -14,29 +14,30 @@ concurrency:
1414

1515
jobs:
1616
test:
17-
name: Test
1817
runs-on: ${{ matrix.os }}
1918
strategy:
2019
fail-fast: false
2120
matrix:
2221
os: [ubuntu-latest, macos-latest, windows-latest]
23-
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
22+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
2423

2524
steps:
2625
- name: Checkout
27-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2827

29-
- uses: actions/setup-python@v4
28+
- uses: actions/setup-python@v5
3029
with:
3130
python-version: ${{ matrix.python-version }}
3231

33-
- name: Upgrade pip
34-
run: python3 -m pip install --upgrade pip
35-
36-
- name: Install ypywidgets in dev mode
32+
- name: Install reacttrs
3733
run: |
3834
pip install .[test]
3935
36+
- name: Check types
37+
run: |
38+
mypy ./reacttrs
39+
mypy ./tests
40+
4041
- name: Run tests
4142
run: |
42-
pytest ./tests -v
43+
pytest ./tests -v --color=yes

Diff for: README.md

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
# reacttrs
22

3-
Reactive attributes extracted out from [Textual](https://textual.textualize.io/guide/reactivity).
3+
Reactive attributes, initially extracted out from [Textual](https://textual.textualize.io/guide/reactivity), now a fork of [Declare](https://github.com/willmcgugan/declare).
44

55
```py
6-
from reacttrs import reactive
6+
from reacttrs import Int, Str
77

88

99
class Foo:
1010

11-
name = reactive("Paul")
12-
age = reactive(33)
13-
birth = reactive(1990)
11+
name = Str("Paul")
12+
age = Int(34)
13+
birth = Int(1990)
1414

15-
def watch_name(self, old, new):
15+
@name.watch
16+
def _watch_name(self, old: str, new: str):
1617
print(f"{old=}, {new=}")
1718

18-
def validate_name(self, name):
19-
if name == "John":
20-
print("Hey John!")
21-
return name
22-
23-
def compute_age(self) -> int:
24-
age = 2023 - self.birth
25-
print(f"{age=}")
26-
return age
19+
@age.validate
20+
def _validate_age(self, value: int) -> int:
21+
return 2024 - self.birth
2722

2823
foo = Foo()
29-
foo.name = "John"
30-
foo.name = "Steve"
24+
foo.name = "John" # old='Paul', new='John'
25+
foo.name = "Steve" # old='John', new='Steve'
3126

32-
foo.age
27+
print(foo.age) # 34
3328
foo.birth = 1991
34-
foo.age
29+
foo.age = 34
30+
print(foo.age) # 33
3531
```

Diff for: pyproject.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ license = "MIT"
1111
requires-python = ">=3.8"
1212
authors = [
1313
{ name = "David Brochart", email = "[email protected]" },
14-
]
15-
keywords = [
16-
"textual",
14+
{ name = "Will McGugan", email = "[email protected]" },
1715
]
1816

1917
[project.urls]
2018
Homepage = "https://github.com/davidbrochart/reacttrs"
2119

2220
[project.optional-dependencies]
2321
test = [
24-
"pytest",
22+
"pytest >=8.1.1",
23+
"mypy >=1.9.0",
2524
]
2625

2726
[tool.hatch.version]

Diff for: reacttrs/__init__.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1-
from .reactive import reactive # noqa
1+
from __future__ import annotations
2+
3+
from .reactive import Reactive as Reactive
4+
from .reactive import watch as watch
25

36
__version__ = "0.1.4"
7+
8+
__all__ = [
9+
"Reactive",
10+
"Int",
11+
"Float",
12+
"Bool",
13+
"Str",
14+
"Bytes",
15+
"watch",
16+
]
17+
18+
Int: type[Reactive[int]] = Reactive
19+
Float: type[Reactive[float]] = Reactive
20+
Bool: type[Reactive[bool]] = Reactive
21+
Str: type[Reactive[str]] = Reactive
22+
Bytes: type[Reactive[bytes]] = Reactive

Diff for: reacttrs/_callback.py

-12
This file was deleted.

Diff for: reacttrs/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)