From 61290c18b0b281365648651af68c5c5684a18a4b Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 4 Aug 2017 18:59:13 +0200 Subject: [PATCH] gopy,bind: drop package name out of tp_name Before this CL we used to prepend the Go package name of a struct to the python name of the corresponding python class: >>> import pkg >>> f = pkg.Foo() >>> f.bar caught error: 'pkg.Foo' object has no attribute 'bar' This CL drops 'pkg' to make the resulting string follow CPython convention: >>> import pkg >>> f = pkg.Foo() >>> f.bar caught error: 'Foo' object has no attribute 'bar' Fixes go-python#gopy/119. --- bind/gencpy_struct.go | 2 +- main_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bind/gencpy_struct.go b/bind/gencpy_struct.go index ee02a48..9a55461 100644 --- a/bind/gencpy_struct.go +++ b/bind/gencpy_struct.go @@ -43,7 +43,7 @@ func (g *cpyGen) genStruct(cpy Struct) { g.impl.Indent() g.impl.Printf("PyObject_HEAD_INIT(NULL)\n") g.impl.Printf("0,\t/*ob_size*/\n") - g.impl.Printf("\"%s.%s\",\t/*tp_name*/\n", pkgname, cpy.GoName()) + g.impl.Printf("\"%s\",\t/*tp_name*/\n", cpy.GoName()) g.impl.Printf("sizeof(%s),\t/*tp_basicsize*/\n", cpy.sym.cpyname) g.impl.Printf("0,\t/*tp_itemsize*/\n") g.impl.Printf("(destructor)%s_dealloc,\t/*tp_dealloc*/\n", cpy.sym.cpyname) diff --git a/main_test.go b/main_test.go index d25968a..cb5817a 100644 --- a/main_test.go +++ b/main_test.go @@ -711,7 +711,7 @@ s.Init() s.Upper('boo')= 'BOO' s1 = structs.S1() s1 = structs.S1{private:0} -caught error: 'structs.S1' object has no attribute 'private' +caught error: 'S1' object has no attribute 'private' s2 = structs.S2() s2 = structs.S2{Public:0, private:0} s2 = structs.S2(1) @@ -719,7 +719,7 @@ s2 = structs.S2{Public:1, private:0} caught error: S2.__init__ takes at most 1 argument(s) s2 = structs.S2{Public:42, private:0} s2.Public = 42 -caught error: 'structs.S2' object has no attribute 'private' +caught error: 'S2' object has no attribute 'private' `), })