Commits

raineszm  committed 0fc6fb8

Remove a number of redundant methods and simplify the process of building the argument tuple for Python method invocation.

  • Participants
  • Parent commits 9c49855

Comments (0)

Files changed (2)

File lib/rubypython/pyobject.rb

     check != 0
   end
 
-  # Manipulates the supplied PyObject instance such that it is suitable to
-  # passed to #callObject or #callObjectKeywords. If +rbObject+ is a tuple
-  # then the argument passed in is returned. If it is a list then the list
-  # is converted to a tuple. Otherwise returns a tuple with one element:
-  # +rbObject+.
-  # [rbObject]  The argument to be turned into a Tuple.
-  def self.makeTuple(rbObject)
-    pTuple = nil
-
-    if RubyPython::Macros.PyObject_TypeCheck(rbObject.pointer, RubyPython::Python.PyList_Type.to_ptr) != 0
-      pTuple = RubyPython::Python.PySequence_Tuple(rbObject.pointer)
-    elsif RubyPython::Macros.PyObject_TypeCheck(rbObject.pointer, RubyPython::Python.PyTuple_Type.to_ptr) != 0
-      pTuple = rbObject.pointer
-    else
-      pTuple = RubyPython::Python.PyTuple_Pack(1, :pointer, rbObject.pointer)
-    end
-
-    self.new pTuple
-  end
-
-  # Wraps up the supplied arguments in a \Python List.
-  def self.newList(*args)
-    rbList = self.new RubyPython::Python.PyList_New(args.length)
-
-    args.each_with_index do |el, i|
-      el.xIncref # PyList_SetItem steals references!
-      RubyPython::Python.PyList_SetItem rbList.pointer, i, el.pointer
-    end
-
-    rbList
-  end
 
   # Converts the supplied arguments to PyObject instances.
   def self.convert(*args)
   # [args] An array of PyObjects; the arguments to be inserted into the
   # Tuple.
   def self.buildArgTuple(*args)
-    pList = newList(*args)
-    pTuple = makeTuple(pList)
-    pList.xDecref
-    pTuple
+    self.new RubyPython::Conversion.rtopArrayToTuple(args)
   end
 end

File spec/pyobject_spec.rb

     end
   end
 
-  describe "#makeTuple" do
-    it "should wrap single arguments in a tuple" do
-      arg = described_class.new AString
-      described_class.makeTuple(arg).rubify.should == [AString]
-    end
-
-    it "should turn a Python list into a tuple" do
-      arg = @objects.a_list.pObject
-      converted = described_class.makeTuple(arg)
-      converted.rubify.should == AnArray
-    end
-
-    it "should return the given argument if it is a tuple" do
-      arg = @objects.a_tuple.pObject
-      converted = described_class.makeTuple(arg)
-      converted.pointer.address.should == arg.pointer.address
-    end
-  end
 
   describe "#callObject" do
     #Expand coverage types
     end
   end
 
-  describe "#newList" do
-    it "should wrap supplied args in a Python list" do
-      args = AnArray.map do |obj|
-        described_class.new obj
-      end
-      described_class.newList(*args).rubify.should == AnArray
-    end
-  end
-
   describe "#function_or_method?" do
     it "should be true given a method" do
       mockObjClass = @objects.RubyPythonMockObject.pObject