lib/pycall/utils.rb in pycall-0.1.0.alpha.20170307 vs lib/pycall/utils.rb in pycall-0.1.0.alpha.20170308

- old
+ new

@@ -4,23 +4,19 @@ pyobj = LibPython.PyUnicode_DecodeUTF8(path_str, path_str.bytesize, nil) sys.path.append.(pyobj) end def callable?(pyobj) - case pyobj - when PyObject - when PyTypeObject - pyobj = PyObject.new(pyobj.to_ptr) - when PyObjectWrapper + unless pyobj.kind_of? LibPython::PyObjectStruct + raise TypeError, "the argument must be a Python object" unless pyobj.respond_to? :__pyobj__ pyobj = pyobj.__pyobj__ - else - raise TypeError, "the argument must be a PyObject" end 1 == LibPython.PyCallable_Check(pyobj) end def dir(pyobj) + pyobj = pyobj.__pyobj__ unless pyobj.kind_of? LibPython::PyObjectStruct value = LibPython.PyObject_Dir(pyobj) return value.to_ruby unless value.null? raise PyError.fetch end @@ -45,9 +41,14 @@ @len.(pyobj) end def None LibPython.Py_None + end + + def none?(pyobj) + pyobj = pyobj.__pyobj__ unless pyobj.kind_of? LibPython::PyObjectStruct + pyobj.to_ptr == self.None.to_ptr end def slice(*args) Slice.new(*args) end