Skip to content

Commit 61290c1

Browse files
committed
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.
1 parent f777c32 commit 61290c1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

bind/gencpy_struct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (g *cpyGen) genStruct(cpy Struct) {
4343
g.impl.Indent()
4444
g.impl.Printf("PyObject_HEAD_INIT(NULL)\n")
4545
g.impl.Printf("0,\t/*ob_size*/\n")
46-
g.impl.Printf("\"%s.%s\",\t/*tp_name*/\n", pkgname, cpy.GoName())
46+
g.impl.Printf("\"%s\",\t/*tp_name*/\n", cpy.GoName())
4747
g.impl.Printf("sizeof(%s),\t/*tp_basicsize*/\n", cpy.sym.cpyname)
4848
g.impl.Printf("0,\t/*tp_itemsize*/\n")
4949
g.impl.Printf("(destructor)%s_dealloc,\t/*tp_dealloc*/\n", cpy.sym.cpyname)

main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,15 +711,15 @@ s.Init()
711711
s.Upper('boo')= 'BOO'
712712
s1 = structs.S1()
713713
s1 = structs.S1{private:0}
714-
caught error: 'structs.S1' object has no attribute 'private'
714+
caught error: 'S1' object has no attribute 'private'
715715
s2 = structs.S2()
716716
s2 = structs.S2{Public:0, private:0}
717717
s2 = structs.S2(1)
718718
s2 = structs.S2{Public:1, private:0}
719719
caught error: S2.__init__ takes at most 1 argument(s)
720720
s2 = structs.S2{Public:42, private:0}
721721
s2.Public = 42
722-
caught error: 'structs.S2' object has no attribute 'private'
722+
caught error: 'S2' object has no attribute 'private'
723723
`),
724724
})
725725

0 commit comments

Comments
 (0)