[IronPython] TypeError: expected Tuple, got tuple

Jeff Hardy jdhardy at gmail.com
Thu Nov 22 03:00:17 CET 2007


Hi,
If I have the following C# library:
namespace TestLib
{
    public class Foo
    {
        public string Bar(Microsoft.Scripting.Tuple t)
        {
            return t.ToString();
        }
    }
}

Calling Bar from IronPython results in "TypeError: expected Tuple, got
tuple". Why are the Python tuple and Microsoft.Scripting.Tuple
different? And what is the proper type to use for Python tuples?

-Jeff

Python code:
IronPython console: IronPython 2.0A6 (2.0.11102.00) on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReference("TestLib")
>>> import TestLib
>>> TestLib.Foo().Bar((1, 2, 3))
Traceback (most recent call last):
  File , line 0, in ##235
TypeError: expected Tuple, got tuple


With -X:ExceptionDetail:
IronPython console: IronPython 2.0A6 (2.0.11102.00) on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReference("TestLib")
>>> import TestLib
>>> TestLib.Foo().Bar((1, 2, 3))
expected Tuple, got tuple
   at IronPython.Runtime.Converter.Convert(Object value, Type to)
   at IronPython.Runtime.Converter.ConvertToReferenceType(Object fromObject, Run
timeTypeHandle typeHandle)
   at Microsoft.Scripting.Utils.InvokeHelper`3.Invoke(Object arg0, Object arg1)
   at Microsoft.Scripting.Utils.ReflectedCaller.Invoke(Object[] args)
   at Microsoft.Scripting.Ast.MethodCallExpression.InvokeMethod(Object instance,
 Object[] parameters)
   at Microsoft.Scripting.Ast.MethodCallExpression.DoEvaluate(CodeContext contex
t)
   at Microsoft.Scripting.Ast.UnaryExpression.DoEvaluate(CodeContext context)
   at Microsoft.Scripting.Ast.ConditionalExpression.DoEvaluate(CodeContext conte
xt)
   at Microsoft.Scripting.Ast.MethodCallExpression.DoEvaluate(CodeContext contex
t)
   at Microsoft.Scripting.Ast.ReturnStatement.DoExecute(CodeContext context)
   at Microsoft.Scripting.Ast.Statement.Execute(CodeContext context)
   at Microsoft.Scripting.Actions.ActionBinder.UpdateSiteAndExecute[T](CodeConte
xt callerContext, DynamicAction action, Object[] args, Object site, T& target, R
uleSet`1& rules)
   at Microsoft.Scripting.Actions.DynamicSite`3.UpdateBindingAndInvoke(CodeConte
xt context, T0 arg0, T1 arg1)
   at Microsoft.Scripting.Actions.DynamicSiteHelpers.UninitializedTargetHelper`7
.Invoke2(DynamicSite`3 site, CodeContext context, T0 arg0, T1 arg1)
   at Microsoft.Scripting.Actions.DynamicSite`3.Invoke(CodeContext context, T0 a
rg0, T1 arg1)
   at ##235(Object[] , CodeContext )
   at Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext, Boolean tryEva
luate)
   at Microsoft.Scripting.ScriptCode.Run(ScriptModule module)
   at Microsoft.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module)
   at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScri
ptModule module)
   at Microsoft.Scripting.Shell.CommandLine.RunOneInteraction()
   at Microsoft.Scripting.Shell.CommandLine.TryInteractiveAction()
   at IronPython.Hosting.PythonCommandLine.TryInteractiveAction()
   at Microsoft.Scripting.Shell.CommandLine.RunInteractiveLoop()
TypeError: expected Tuple, got tuple



More information about the Ironpython-users mailing list