Skip to content
Draft
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
9 changes: 9 additions & 0 deletions _examples/maps/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ func Values(t map[int]float64) []float64 {
sort.Float64s(values)
return values
}

// StringInterfaceMap reproduces issue #360: a map[string]interface{} whose
// values are non-string types (e.g. int) was rendered using Go's fmt "%s"
// verb, producing "%!s(int=1)" instead of the actual value "1".
func StringInterfaceMap() map[string]interface{} {
return map[string]interface{}{
"id": 1,
}
}
5 changes: 5 additions & 0 deletions _examples/maps/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@
del a[1]
print('deleted 1 from a:', a)

# regression test for issue #360: int values inside a map[string]interface{}
# must come back as the actual int, not Go's "%!s(int=1)" error string.
c = maps.StringInterfaceMap()
print('maps.StringInterfaceMap()["id"]:', c['id'])

print("OK")
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ maps.Values from Go map: go.Slice_float64 len: 2 handle: 4 [3.0, 5.0]
maps.Keys from Python dictionary: go.Slice_int len: 2 handle: 6 [1, 2]
maps.Values from Python dictionary: go.Slice_float64 len: 2 handle: 8 [3.0, 5.0]
deleted 1 from a: maps.Map_int_float64 len: 1 handle: 1 {2=5.0, }
maps.StringInterfaceMap()["id"]: 1
OK
`),
})
Expand Down
Loading