Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions reacton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ def __init__(self, f: Callable[[], Element], mime_bundle=mime_bundle_default, va
self.render_count = 0 # used for debugging, not thread safe, so count can be off
functools.update_wrapper(self, f)

def __get__(self, instance, owner=None):
# Python does the same without this method. Having it makes inspect.isroutine true,
# so Sphinx autodoc documents a component as a function or method, with its docstring.
return self

def widget(self, **kwargs):
_ensure_colab_fixes()
return self.widget_class()(**kwargs)
Expand Down
18 changes: 18 additions & 0 deletions reacton/core_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gc
import inspect
import sys
import threading
import time
Expand Down Expand Up @@ -346,6 +347,23 @@ def test_monkey_patch():
rc.close()


def test_component_function_is_routine():
# Sphinx autodoc only documents a member as a function or method when inspect.isroutine is true
class Holder:
@react.component
def method(self):
"""Method docstring."""
return w.Button()

component = Holder.__dict__["method"]
assert isinstance(component, reacton.core.ComponentFunction)
assert inspect.isroutine(component)
assert component.__doc__ == "Method docstring."
# reading it from the class or an instance gives the component itself, there is no binding
assert Holder.method is component
assert Holder().method is component


def test_component_function():
clear()
assert count() == 0
Expand Down
Loading