allow repr to be a callable

This commit is contained in:
Will McGugan 2021-05-07 17:47:03 +01:00
parent 75d6658f8d
commit f0b16ba2c2
2 changed files with 13 additions and 7 deletions

View file

@ -197,11 +197,12 @@ def test_attrs():
class Point:
x: int
y: int
foo: str = attr.field(repr=str.upper)
z: int = 0
result = pretty_repr(Point(1, 2))
result = pretty_repr(Point(1, 2, foo="bar"))
print(repr(result))
expected = "Point(x=1, y=2, z=0)"
expected = "Point(x=1, y=2, foo=BAR, z=0)"
assert result == expected