lib/pycall/dict.rb in pycall-0.1.0.alpha.20170307 vs lib/pycall/dict.rb in pycall-0.1.0.alpha.20170308
- old
+ new
@@ -2,11 +2,11 @@
class Dict
include PyObjectWrapper
def self.new(init=nil)
case init
- when PyObject
+ when LibPython::PyObjectStruct
super
when nil
new(LibPython.PyDict_New())
when Hash
new.tap do |dict|
@@ -17,32 +17,29 @@
else
raise TypeError, "the argument must be a PyObject or a Hash"
end
end
- def initialize(pyobj)
- super(pyobj, LibPython.PyDict_Type)
- end
-
def [](key)
key = key.to_s if key.is_a? Symbol
value = if key.is_a? String
LibPython.PyDict_GetItemString(__pyobj__, key).to_ruby
else
LibPython.PyDict_GetItem(__pyobj__, key).to_ruby
end
ensure
case value
- when PyObject
+ when LibPython::PyObjectStruct
PyCall.incref(value)
when PyObjectWrapper
PyCall.incref(value.__pyobj__)
end
end
def []=(key, value)
key = key.to_s if key.is_a? Symbol
value = Conversions.from_ruby(value)
+ value = value.__pyobj__ unless value.kind_of? LibPython::PyObjectStruct
if key.is_a? String
LibPython.PyDict_SetItemString(__pyobj__, key, value)
else
LibPython.PyDict_SetItem(__pyobj__, key, value)
end