diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60f9486b9..e6dc568f7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/kynan/nbstripout - rev: master + rev: 0.3.9 hooks: - id: nbstripout files: ".ipynb" diff --git a/idom/core/component.py b/idom/core/component.py index 9c71d9f58..8a9416624 100644 --- a/idom/core/component.py +++ b/idom/core/component.py @@ -59,9 +59,13 @@ def render(self) -> Any: def __repr__(self) -> str: sig = inspect.signature(self._function) - args = sig.bind(*self._args, **self._kwargs).arguments - items = ", ".join(f"{k}={v!r}" for k, v in args.items()) - if items: - return f"{self._function.__name__}({hex(id(self))}, {items})" + try: + args = sig.bind(*self._args, **self._kwargs).arguments + except TypeError: + return f"{self._function.__name__}(...)" else: - return f"{self._function.__name__}({hex(id(self))})" + items = ", ".join(f"{k}={v!r}" for k, v in args.items()) + if items: + return f"{self._function.__name__}({hex(id(self))}, {items})" + else: + return f"{self._function.__name__}({hex(id(self))})" diff --git a/tests/test_core/test_component.py b/tests/test_core/test_component.py index e534c8a6b..a087f4e5f 100644 --- a/tests/test_core/test_component.py +++ b/tests/test_core/test_component.py @@ -6,10 +6,13 @@ def test_component_repr(): def MyComponent(a, *b, **c): pass - m_e = MyComponent(1, 2, 3, x=4, y=5) + mc1 = MyComponent(1, 2, 3, x=4, y=5) - expected = f"MyComponent({hex(id(m_e))}, a=1, b=(2, 3), c={{'x': 4, 'y': 5}})" - assert repr(m_e) == expected + expected = f"MyComponent({hex(id(mc1))}, a=1, b=(2, 3), c={{'x': 4, 'y': 5}})" + assert repr(mc1) == expected + + # not enough args supplied to function + assert repr(MyComponent()) == "MyComponent(...)" async def test_simple_component():