From 9dde3761d503cd869dd0a6e78e7aba1a142f0786 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Mon, 22 Apr 2024 16:04:17 -0700 Subject: [PATCH] if renaming case, use lower-case string() method instead of String() -- fixes #337 --- bind/gen.go | 10 ++++++++++ bind/gen_map.go | 2 +- bind/gen_slice.go | 2 +- bind/gen_struct.go | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bind/gen.go b/bind/gen.go index c8b6756..05fd70e 100644 --- a/bind/gen.go +++ b/bind/gen.go @@ -863,3 +863,13 @@ func (g *pyGen) genGoPkg() { g.genType(sym, false, false) // not exttypes } } + +// genStringerCall generates a call to either self.String() or self.string() +// depending on RenameCase option +func (g *pyGen) genStringerCall() { + if g.cfg.RenameCase { + g.pywrap.Printf("return self.string()\n") + } else { + g.pywrap.Printf("return self.String()\n") + } +} diff --git a/bind/gen_map.go b/bind/gen_map.go index 2803438..f65111f 100644 --- a/bind/gen_map.go +++ b/bind/gen_map.go @@ -134,7 +134,7 @@ otherwise parameter is a python list that we copy from if isStringer(m.obj) { g.pywrap.Printf("def __str__(self):\n") g.pywrap.Indent() - g.pywrap.Printf("return self.String()\n") + g.genStringerCall() g.pywrap.Outdent() g.pywrap.Printf("\n") } diff --git a/bind/gen_slice.go b/bind/gen_slice.go index 4ef47e4..fa0ab54 100644 --- a/bind/gen_slice.go +++ b/bind/gen_slice.go @@ -129,7 +129,7 @@ otherwise parameter is a python list that we copy from if isStringer(m.obj) { g.pywrap.Printf("def __str__(self):\n") g.pywrap.Indent() - g.pywrap.Printf("return self.String()\n") + g.genStringerCall() g.pywrap.Outdent() } } diff --git a/bind/gen_struct.go b/bind/gen_struct.go index 815c083..b50ddfc 100644 --- a/bind/gen_struct.go +++ b/bind/gen_struct.go @@ -101,7 +101,7 @@ in which case a new Go object is constructed first } g.pywrap.Printf("def __str__(self):\n") g.pywrap.Indent() - g.pywrap.Printf("return self.String()\n") + g.genStringerCall() g.pywrap.Outdent() g.pywrap.Printf("\n") } @@ -345,7 +345,7 @@ handle=A Go-side object is always initialized with an explicit handle=arg } g.pywrap.Printf("def __str__(self):\n") g.pywrap.Indent() - g.pywrap.Printf("return self.String()\n") + g.genStringerCall() g.pywrap.Outdent() g.pywrap.Printf("\n") }