Skip to content

Commit afa0c4f

Browse files
committed
print should use __str__ or __repr__ when available
1 parent 6e7b5ec commit afa0c4f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

builtin/builtin.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Obje
189189
end := endObj.(py.String)
190190
// FIXME ignoring file and flush
191191
for i, v := range args {
192+
switch sv := v.(type) {
193+
case py.I__str__:
194+
v, _ = sv.M__str__()
195+
196+
case py.I__repr__:
197+
v, _ = sv.M__repr__()
198+
}
199+
192200
fmt.Printf("%v", v)
193201
if i != len(args)-1 {
194202
fmt.Print(sep)

0 commit comments

Comments
 (0)