lib/pycall/pyobject_wrapper.rb in pycall-0.1.0.alpha.20170224 vs lib/pycall/pyobject_wrapper.rb in pycall-0.1.0.alpha.20170226
- old
+ new
@@ -1,9 +1,10 @@
module PyCall
module PyObjectWrapper
- def initialize(pyobj, pytype)
+ def initialize(pyobj, pytype=nil)
check_type pyobj, pytype
+ pytype ||= LibPython.PyObject_Type(pyobj)
@__pyobj__ = pyobj
end
attr_reader :__pyobj__
@@ -39,10 +40,11 @@
end
private
def check_type(pyobj, pytype)
- return if pyobj.kind_of?(PyObject) && pyobj.kind_of?(pytype)
+ return if pyobj.kind_of?(PyObject)
+ return if pytype.nil? || pyobj.kind_of?(pytype)
raise TypeError, "the argument must be a PyObject of #{pytype}"
end
end
end