-
Notifications
You must be signed in to change notification settings - Fork 138
object: always return the same value for Py_None, Py_True, and Py_False #87
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, and to make it behave more like the C API, one could modify togo
to check the ptr
pointer for C.Py_None
and return python.Py_None
.
https://github.com/sbinet/go-python/blob/master/object.go#L36
WDYT?
That's a way better solution. |
We should probably do the same with |
SGTM. |
There's an initialisation loop: var Py_None = togo(C._gopy_pynone())
func togo(obj *C.PyObject) *PyObject {
switch obj {
case nil:
return nil
case Py_None.ptr:
return Py_None
case Py_True.ptr:
return Py_True
case Py_False.ptr:
return Py_False
default:
return &PyObject{ptr: obj}
}
}
We can either not use the var Py_None = &Object{C._gopy_pynone()}
// etc ... or split func togo(obj *C.PyObject) *PyObject {
switch obj {
case Py_None.ptr:
return Py_None
case Py_True.ptr:
return Py_True
case Py_False.ptr:
return Py_False
default:
return newgo(obj)
}
}
func newgo(obj *C.PyObject) *PyObject {
if obj == nil {
return nil
}
return &PyObject{ptr: obj}
}
var Py_None = newgo(C._gopy_pynone()) what do you think? |
I went with the 2 functions |
I must say I am unsure about the approach of these 2 very similarly-looking functions that do almost the same thing but not quite. I think it would be as simple to leave only one function ( var Py_None = &PyObject{ptr: C._gopy_none()}
var Py_False = &PyObject{ptr: C._gopy_pyfalse()}
var Py_True = &PyObject{ptr: C._gopy_pytrue()} |
no problem |
@sbinet should be good to go |
https://docs.python.org/2/c-api/none.html
You're supposed to be able to compare a
python.PyObject
topython.Py_None
but this doesn't work.I think we should consider adding a
PyNone_Check
function to compare the underlying pointer.