Skip to content

Commit 3e8b9ea

Browse files
committed
fix Component.__repr__ bug
1 parent 8010e0d commit 3e8b9ea

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
hooks:
99
- id: flake8
1010
- repo: https://github.com/kynan/nbstripout
11-
rev: master
11+
rev: 0.3.9
1212
hooks:
1313
- id: nbstripout
1414
files: ".ipynb"

idom/core/component.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ def render(self) -> Any:
5959

6060
def __repr__(self) -> str:
6161
sig = inspect.signature(self._function)
62-
args = sig.bind(*self._args, **self._kwargs).arguments
63-
items = ", ".join(f"{k}={v!r}" for k, v in args.items())
64-
if items:
65-
return f"{self._function.__name__}({hex(id(self))}, {items})"
62+
try:
63+
args = sig.bind(*self._args, **self._kwargs).arguments
64+
except TypeError:
65+
return f"{self._function.__name__}(...)"
6666
else:
67-
return f"{self._function.__name__}({hex(id(self))})"
67+
items = ", ".join(f"{k}={v!r}" for k, v in args.items())
68+
if items:
69+
return f"{self._function.__name__}({hex(id(self))}, {items})"
70+
else:
71+
return f"{self._function.__name__}({hex(id(self))})"

tests/test_core/test_component.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ def test_component_repr():
66
def MyComponent(a, *b, **c):
77
pass
88

9-
m_e = MyComponent(1, 2, 3, x=4, y=5)
9+
mc1 = MyComponent(1, 2, 3, x=4, y=5)
1010

11-
expected = f"MyComponent({hex(id(m_e))}, a=1, b=(2, 3), c={{'x': 4, 'y': 5}})"
12-
assert repr(m_e) == expected
11+
expected = f"MyComponent({hex(id(mc1))}, a=1, b=(2, 3), c={{'x': 4, 'y': 5}})"
12+
assert repr(mc1) == expected
13+
14+
# not enough args supplied to function
15+
assert repr(MyComponent()) == "MyComponent(...)"
1316

1417

1518
async def test_simple_component():

0 commit comments

Comments
 (0)