reacton 1.2.0__tar.gz → 1.2.2__tar.gz

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.
Files changed (30) hide show
  1. {reacton-1.2.0 → reacton-1.2.2}/PKG-INFO +1 -1
  2. reacton-1.2.2/reacton/_version.py +1 -0
  3. {reacton-1.2.0 → reacton-1.2.2}/reacton/core.py +10 -3
  4. {reacton-1.2.0 → reacton-1.2.2}/reacton/core_test.py +6 -2
  5. {reacton-1.2.0 → reacton-1.2.2}/reacton/find.py +1 -1
  6. {reacton-1.2.0 → reacton-1.2.2}/reacton/utils.py +9 -5
  7. {reacton-1.2.0 → reacton-1.2.2}/reacton/utils_test.py +25 -1
  8. reacton-1.2.0/reacton/_version.py +0 -1
  9. {reacton-1.2.0 → reacton-1.2.2}/.gitignore +0 -0
  10. {reacton-1.2.0 → reacton-1.2.2}/LICENSE +0 -0
  11. {reacton-1.2.0 → reacton-1.2.2}/pyproject.toml +0 -0
  12. {reacton-1.2.0 → reacton-1.2.2}/react_ipywidgets/__init__.py +0 -0
  13. {reacton-1.2.0 → reacton-1.2.2}/react_ipywidgets/core.py +0 -0
  14. {reacton-1.2.0 → reacton-1.2.2}/reacton/__init__.py +0 -0
  15. {reacton-1.2.0 → reacton-1.2.2}/reacton/bqplot.py +0 -0
  16. {reacton-1.2.0 → reacton-1.2.2}/reacton/find_test.py +0 -0
  17. {reacton-1.2.0 → reacton-1.2.2}/reacton/generate.py +0 -0
  18. {reacton-1.2.0 → reacton-1.2.2}/reacton/generate_test.py +0 -0
  19. {reacton-1.2.0 → reacton-1.2.2}/reacton/ipycanvas.py +0 -0
  20. {reacton-1.2.0 → reacton-1.2.2}/reacton/ipyvue.py +0 -0
  21. {reacton-1.2.0 → reacton-1.2.2}/reacton/ipyvuetify.py +0 -0
  22. {reacton-1.2.0 → reacton-1.2.2}/reacton/ipywidgets.py +0 -0
  23. {reacton-1.2.0 → reacton-1.2.2}/reacton/logging.py +0 -0
  24. {reacton-1.2.0 → reacton-1.2.2}/reacton/patch.py +0 -0
  25. {reacton-1.2.0 → reacton-1.2.2}/reacton/patch_display.py +0 -0
  26. {reacton-1.2.0 → reacton-1.2.2}/reacton/py.typed +0 -0
  27. {reacton-1.2.0 → reacton-1.2.2}/reacton/rx.py +0 -0
  28. {reacton-1.2.0 → reacton-1.2.2}/reacton/test.vue +0 -0
  29. {reacton-1.2.0 → reacton-1.2.2}/reacton/test_rx.py +0 -0
  30. {reacton-1.2.0 → reacton-1.2.2}/reacton/work.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: reacton
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Project-URL: Home, https://www.github.com/widgetti/reacton
5
5
  Project-URL: Documentation, https://reacton.solara.dev
6
6
  Project-URL: Source code, https://www.github.com/widgetti/reacton
@@ -0,0 +1 @@
1
+ __version__ = "1.2.2"
@@ -535,7 +535,8 @@ class ComponentFunction(Component):
535
535
  return self.widget_class()(**kwargs)
536
536
 
537
537
  def widget_class(self):
538
- args = list(inspect.signature(self.f).parameters.keys())
538
+ parameters = inspect.signature(self.f).parameters
539
+ args = list(parameters.keys())
539
540
  listeners = set()
540
541
  normal_kwargs = set()
541
542
  for name in args:
@@ -554,7 +555,12 @@ class ComponentFunction(Component):
554
555
  traits = {}
555
556
 
556
557
  for name in normal_kwargs:
557
- traits[name] = traitlets.Any()
558
+ if name != "children": # children is a special trait we keep
559
+ if name in normal_kwargs:
560
+ trait = traitlets.Any(default_value=parameters[name].default)
561
+ else:
562
+ trait = traitlets.Any()
563
+ traits[name] = trait
558
564
  Container.add_traits(self, **traits)
559
565
  for name, value in kwargs.items():
560
566
  if name in normal_kwargs:
@@ -568,7 +574,8 @@ class ComponentFunction(Component):
568
574
  def _create_el(self):
569
575
  kwargs = {}
570
576
  for name in normal_kwargs:
571
- kwargs[name] = getattr(self, name)
577
+ if name != "children":
578
+ kwargs[name] = getattr(self, name)
572
579
  for name in listeners:
573
580
  propname = name[3:]
574
581
 
@@ -2724,13 +2724,17 @@ def test_implicit_component():
2724
2724
 
2725
2725
  def test_create_widget():
2726
2726
  @react.component
2727
- def Test(a: int = 1, label="lala", on_a=None):
2727
+ def Test(a: int = 1, label="lala", on_a=None, children=[]):
2728
+ # adding children shouldn't change the children trait
2729
+ assert children == []
2728
2730
  return w.IntSlider(value=a, on_value=on_a, description=label)
2729
2731
 
2730
- widget: widgets.Widget = Test.widget(a=1, label="lala") # type: ignore
2732
+ widget: widgets.Widget = Test.widget(a=1) # type: ignore
2733
+ assert widget.trait_metadata("children", "to_json") is not None
2731
2734
  mock = unittest.mock.Mock()
2732
2735
  widget.trait_names() == ["a", "label"]
2733
2736
  widget.observe(mock, "a")
2737
+ assert widget.label == "lala"
2734
2738
  widget.a = 2
2735
2739
  mock.assert_called_once_with({"name": "a", "old": 1, "new": 2, "owner": widget, "type": "change"})
2736
2740
  slider = widget.children[0]
@@ -51,7 +51,7 @@ class Finder(collections.abc.Sequence, Generic[W]):
51
51
  return parent
52
52
 
53
53
  def __repr__(self):
54
- return "Finder structure:\n%r" % self._current_structure()
54
+ return "Finder structure:\n%s" % self._current_structure()
55
55
 
56
56
  def _reexecute_find(self):
57
57
  finder = self._root()
@@ -1,5 +1,6 @@
1
1
  import functools
2
2
  import inspect
3
+ import sys
3
4
  import types
4
5
  from typing import Callable, TypeVar, cast
5
6
 
@@ -71,12 +72,14 @@ def equals(a, b):
71
72
 
72
73
 
73
74
  def import_item(name: str):
74
- """Import an object by name like pandas.DataFrame"""
75
- parts = name.rsplit(".", 2)
75
+ """Import an object by name like pandas.DataFrame if the module is imported, else return None"""
76
+ parts = name.rsplit(".", 1)
76
77
  if len(parts) == 1:
77
- return __import__(name)
78
+ return sys.modules.get(name)
78
79
  else:
79
- module = __import__(".".join(parts[:-1]), fromlist=[parts[-1]])
80
+ module = sys.modules.get(parts[0])
81
+ if module is None:
82
+ return None
80
83
  return getattr(module, parts[-1])
81
84
 
82
85
 
@@ -85,8 +88,9 @@ def isinstance_lazy(value, types):
85
88
  types = [types]
86
89
  types = [import_item(t) if isinstance(t, str) else t for t in types]
87
90
  for type in types:
88
- if isinstance(value, type):
91
+ if type is not None and isinstance(value, type):
89
92
  return True
93
+ return False
90
94
 
91
95
 
92
96
  def dataframe_fingerprint(df):
@@ -1,8 +1,10 @@
1
+ import sys
2
+
1
3
  import pytest
2
4
 
3
5
  import reacton.ipywidgets as w
4
6
 
5
- from .utils import equals
7
+ from .utils import equals, import_item, isinstance_lazy
6
8
 
7
9
 
8
10
  class NeverEquals:
@@ -82,3 +84,25 @@ def test_equals():
82
84
  assert equals(el1.kwargs, el2.kwargs)
83
85
  assert equals(el1, el2)
84
86
  assert not equals(el1, el3)
87
+
88
+
89
+ def test_import_item():
90
+ assert import_item("sys.modules") is sys.modules
91
+ assert import_item("sys") is sys
92
+ assert import_item("doesnotexist") is None
93
+ assert import_item("doesnotexist.a") is None
94
+ assert import_item("doesnotexist.a.b") is None
95
+
96
+
97
+ def test_isinstance_lazy():
98
+ assert isinstance_lazy(1, int)
99
+ assert isinstance_lazy(1, (int, "does.not.exist"))
100
+ assert not isinstance_lazy(1, "does.not.exist")
101
+ import pandas
102
+
103
+ sys.modules.pop("pandas", None)
104
+ assert not isinstance_lazy(1, "pandas.DataFrame")
105
+ import pandas as pd
106
+
107
+ df = pd.DataFrame()
108
+ assert isinstance_lazy(df, "pandas.DataFrame")
@@ -1 +0,0 @@
1
- __version__ = "1.2.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes