From 9aa54a02b5551fc0384e4ade55a4a1c0211dfee6 Mon Sep 17 00:00:00 2001 From: b-long Date: Fri, 31 Jul 2026 16:28:07 -0400 Subject: [PATCH] Add regression test for map[string]interface{} int Reproduces issue #360: int values render as Go's "%!s(int=1)" error string --- _examples/maps/maps.go | 9 +++++++++ _examples/maps/test.py | 5 +++++ main_test.go | 1 + 3 files changed, 15 insertions(+) diff --git a/_examples/maps/maps.go b/_examples/maps/maps.go index 93bb6c8d..0abf040e 100644 --- a/_examples/maps/maps.go +++ b/_examples/maps/maps.go @@ -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, + } +} diff --git a/_examples/maps/test.py b/_examples/maps/test.py index 8f57bcf5..8d70c705 100644 --- a/_examples/maps/test.py +++ b/_examples/maps/test.py @@ -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") diff --git a/main_test.go b/main_test.go index 1127698c..ace504ae 100644 --- a/main_test.go +++ b/main_test.go @@ -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 `), })