Commits

Jeff Hardy committed 0681bdf

Restrict Tuple.elts to a PythonList and a PythonTuple.

  • Participants
  • Parent commits a86e444

Comments (0)

Files changed (1)

File _ast/_ast.cs

         [PythonType]
         public class ExtSlice : slice
         {
-            private PythonTuple _dims;
+            private PythonList _dims;
 
             public ExtSlice()
             {
                 _fields = new PythonTuple(new[]{"dims",});
             }
 
-            internal ExtSlice(PythonTuple dims)
+            internal ExtSlice(PythonList dims)
                 : this()
             {
                 _dims = dims;
             }
 
-            public PythonTuple dims
+            public PythonList dims
             {
                 get { return _dims; }
                 set { _dims = value; }
                 AST index = Convert(expr.Index);
                 if (index is expr)
                     if (index is Tuple)
-                        _slice = new ExtSlice(((Tuple)index).elts);
+                        _slice = new ExtSlice((PythonList)((Tuple)index).elts);
                     else
                         _slice = new Index((expr)index);
                 else if (index is slice) // includes Ellipsis
         [PythonType]
         public class Tuple : expr
         {
-            private PythonTuple _elts;
+            private PythonList _elts;
             private expr_context _ctx;
 
             public Tuple()
 
             internal Tuple(TupleExpression list, expr_context ctx) : this()
             {
-                ArrayList items = new ArrayList();
+                _elts = PythonOps.MakeEmptyList(list.Items.Length);
                 foreach(Compiler.Ast.Expression expr in list.Items)
-                    items.Add(Convert(expr, ctx));
-
-                _elts = PythonOps.MakeTuple(items.ToArray());
+                    _elts.Add(Convert(expr, ctx));
+
                 _ctx = ctx;
             }
 
-            public PythonTuple elts
+            public object elts
             {
                 get { return _elts; }
-                set { _elts = value; }
+                set
+                {
+                    if(value is PythonList)
+                    {
+                        _elts = (PythonList)value;
+                    }
+                    else if(value is PythonTuple)
+                    {
+                        //PythonTuple t = (PythonTuple)elts;
+                        //object[] a = new object[t.Count];
+                        //t.CopyTo(a, 0);
+
+                        _elts = PythonOps.MakeListFromSequence((PythonTuple)value);
+                    }
+                    else
+                    {
+                        throw new ArgumentTypeException("can only assign list or tuple to Tuple.elts");
+                    }
+                }
             }
 
             public expr_context ctx