python-library-reactive-model 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-library-reactive-model
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Requires-Python: >=3.10
@@ -0,0 +1,11 @@
1
+ reactive_model/__init__.py,sha256=PcNCcQTNcJ14XTjh6gVlaNdXP_gi0YEirGckQAK9Rb8,333
2
+ reactive_model/computed_model.py,sha256=Y9XL0GXxOm_h98koDB-cr9CmWrzsGuowlIEQz50E4zw,1859
3
+ reactive_model/computed_property.py,sha256=r3gqUhBwwUk4Jhn1LGfcLwQKvheaGqMoD3VxDzTsRCM,695
4
+ reactive_model/dict_ref_model.py,sha256=d7P_9P2-D107vTUNV5SIpJqNAvIgEkwmwOIATT5MKAw,2863
5
+ reactive_model/list_ref_model.py,sha256=5Q2-_HTGexKZFlAjdjCwmSKoxGc_rCMt-lislxUW5fM,2884
6
+ reactive_model/reactive_model.py,sha256=2yWu7LewtlkbVmwGA3LDDuqbHla8PI9OiiEkkK9inKk,561
7
+ reactive_model/ref_model.py,sha256=HuG800z0A4PDcrFQqkpXZdPgkclEMkMARRwS103HDLE,608
8
+ reactive_model/track.py,sha256=DD_cG5o2-amnBNtfw8wCNZizY9rc_6eaootGfWlN0R0,2198
9
+ python_library_reactive_model-0.1.3.dist-info/METADATA,sha256=JA4Lxch3TeRd1fsgZwYiW35Axd7T4rvNJyxkvmkbsKY,97
10
+ python_library_reactive_model-0.1.3.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
11
+ python_library_reactive_model-0.1.3.dist-info/RECORD,,
@@ -1,11 +1,13 @@
1
- from .computed import ComputedModel
2
- from .ref import RefModel
3
- from .dict_ref import DictRefModel
4
- from .list_ref import ListRefModel
1
+ from .computed_model import ComputedModel
2
+ from .ref_model import RefModel
3
+ from .dict_ref_model import DictRefModel
4
+ from .list_ref_model import ListRefModel
5
+ from .computed_property import computed_property
5
6
 
6
7
  __all__ = [
7
8
  "RefModel",
8
9
  "ComputedModel",
9
10
  "DictRefModel",
10
11
  "ListRefModel",
12
+ "computed_property",
11
13
  ]
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Callable, TypeVar, cast
4
4
 
5
- from .reactive import ReactiveModel
5
+ from .reactive_model import ReactiveModel
6
6
  from .track import Collector, Trackable, compute_context, track
7
7
 
8
8
  T = TypeVar("T")
@@ -0,0 +1,24 @@
1
+ from typing import Callable, Generic, TypeVar
2
+
3
+ from reactive_model.computed_model import ComputedModel
4
+
5
+ T = TypeVar("T")
6
+
7
+ class computed_property(Generic[T]):
8
+ def __init__(self, func: Callable[..., T]) -> None:
9
+ self.func = func
10
+ self.storage_name = ""
11
+
12
+ def __set_name__(self, owner, name):
13
+ self.storage_name = f"__computed_{name}"
14
+
15
+ def __get__(self, obj, owner=None) -> T:
16
+ if obj is None:
17
+ return self
18
+
19
+ model = obj.__dict__.get(self.storage_name)
20
+ if model is None:
21
+ model = ComputedModel(lambda: self.func(obj))
22
+ obj.__dict__[self.storage_name] = model
23
+
24
+ return model.value
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from collections.abc import Iterable, Iterator, MutableMapping
4
4
  from typing import Generic, TypeVar
5
5
 
6
- from .ref import RefModel
6
+ from .ref_model import RefModel
7
7
  from .track import track
8
8
 
9
9
  K = TypeVar("K")
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from collections.abc import Iterable, MutableSequence
4
4
  from typing import Generic, TypeVar, overload
5
5
 
6
- from .ref import RefModel
6
+ from .ref_model import RefModel
7
7
  from .track import track
8
8
 
9
9
  T = TypeVar("T")
@@ -18,6 +18,7 @@ class ListProxy(MutableSequence[T], Generic[T]):
18
18
 
19
19
  @overload
20
20
  def __getitem__(self, index: int) -> T: ...
21
+
21
22
  @overload
22
23
  def __getitem__(self, index: slice) -> list[T]: ...
23
24
 
@@ -26,6 +27,7 @@ class ListProxy(MutableSequence[T], Generic[T]):
26
27
 
27
28
  @overload
28
29
  def __setitem__(self, index: int, value: T) -> None: ...
30
+
29
31
  @overload
30
32
  def __setitem__(self, index: slice, value: Iterable[T]) -> None: ...
31
33
 
@@ -41,25 +43,41 @@ class ListProxy(MutableSequence[T], Generic[T]):
41
43
  self._owner._value.insert(index, value)
42
44
  self._owner.touch()
43
45
 
46
+ def append(self, value: T) -> None:
47
+ self._owner._value.append(value)
48
+ self._owner.touch()
49
+
50
+ def extend(self, values: Iterable[T]) -> None:
51
+ self._owner._value.extend(values)
52
+ self._owner.touch()
53
+
44
54
  def clear(self) -> None:
45
55
  if self._owner._value:
46
56
  self._owner._value.clear()
47
57
  self._owner.touch()
48
58
 
49
- def extend(self, values: Iterable[T]) -> None:
50
- data = list(values)
51
- if data:
52
- self._owner._value.extend(data)
53
- self._owner.touch()
59
+ def pop(self, index: int = -1) -> T:
60
+ item = self._owner._value.pop(index)
61
+ self._owner.touch()
62
+ return item
54
63
 
55
- def sort(self, *, key=None, reverse: bool = False) -> None:
56
- self._owner._value.sort(key=key, reverse=reverse)
64
+ def remove(self, value: T) -> None:
65
+ self._owner._value.remove(value)
57
66
  self._owner.touch()
58
67
 
59
68
  def reverse(self) -> None:
60
69
  self._owner._value.reverse()
61
70
  self._owner.touch()
62
71
 
72
+ def sort(self, *args: object, **kwargs: object) -> None:
73
+ self._owner._value.sort(*args, **kwargs) # type: ignore[arg-type]
74
+ self._owner.touch()
75
+
76
+ def __iadd__(self, other: Iterable[T]) -> ListProxy[T]:
77
+ self._owner._value += list(other)
78
+ self._owner.touch()
79
+ return self
80
+
63
81
  def __repr__(self) -> str:
64
82
  return repr(self._owner._value)
65
83
 
@@ -79,4 +97,4 @@ class ListRefModel(RefModel[list[T]]):
79
97
  @value.setter
80
98
  def value(self, value: list[T]) -> None:
81
99
  self._value = value
82
- self.touch()
100
+ self.touch()
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
  from typing import TypeVar
3
3
 
4
- from .reactive import ReactiveModel
4
+ from .reactive_model import ReactiveModel
5
5
  from .track import track
6
6
 
7
7
  T = TypeVar("T")
@@ -1,10 +0,0 @@
1
- reactive_model/__init__.py,sha256=b9WfP5vPniCJd9s27ZnUByFKdA-srLKEq7WNEcoDr6A,233
2
- reactive_model/computed.py,sha256=zePvNRRtb11n0O2EmiFczoOOm1Fz-o1Uum-hz8jbE_Y,1853
3
- reactive_model/dict_ref.py,sha256=j_blxT1p-ELVFhaVxQ4biE8TV_AsP42oIRDv03Muvn8,2857
4
- reactive_model/list_ref.py,sha256=QQn9sciMHSUZl_07sCF-xzXNKp0xi0-vysFj8E2H8Ho,2387
5
- reactive_model/reactive.py,sha256=2yWu7LewtlkbVmwGA3LDDuqbHla8PI9OiiEkkK9inKk,561
6
- reactive_model/ref.py,sha256=2rajYPElAnHQwBx9n_wtpaJuTNvLGXKWhwx6ipWMhVU,602
7
- reactive_model/track.py,sha256=DD_cG5o2-amnBNtfw8wCNZizY9rc_6eaootGfWlN0R0,2198
8
- python_library_reactive_model-0.1.2.dist-info/METADATA,sha256=6lxgO-zXxfRlaNDemD83Ks-i1o-pUssjQV1KdCz8fYc,97
9
- python_library_reactive_model-0.1.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
10
- python_library_reactive_model-0.1.2.dist-info/RECORD,,
File without changes