@@ -29,8 +29,8 @@ public class PythonTuple : IList, IList<object?>, ICodeFormattable, IExpressionS
29
29
30
30
internal static readonly PythonTuple EMPTY = new PythonTuple ( ) ;
31
31
32
- public PythonTuple ( [ AllowNull ] object o ) {
33
- _data = MakeItems ( o ) ;
32
+ public PythonTuple ( CodeContext context , [ AllowNull ] object o ) {
33
+ _data = MakeItems ( context , o ) ;
34
34
}
35
35
36
36
protected PythonTuple ( object ? [ ] items ) {
@@ -55,19 +55,19 @@ public static PythonTuple __new__(CodeContext context, [NotNone] PythonType cls)
55
55
if ( cls == TypeCache . PythonTuple ) {
56
56
return EMPTY ;
57
57
} else {
58
- if ( ! ( cls . CreateInstance ( context ) is PythonTuple tupObj ) ) throw PythonOps . TypeError ( "{0} is not a subclass of tuple" , cls ) ;
58
+ if ( cls . CreateInstance ( context ) is not PythonTuple tupObj ) throw PythonOps . TypeError ( "{0} is not a subclass of tuple" , cls ) ;
59
59
return tupObj ;
60
60
}
61
61
}
62
62
63
63
public static PythonTuple __new__ ( CodeContext context , [ NotNone ] PythonType cls , object ? sequence ) {
64
- if ( sequence == null ) return new PythonTuple ( sequence ) ; // this will throw the proper exception
64
+ if ( sequence == null ) return new PythonTuple ( context , sequence ) ; // this will throw the proper exception
65
65
66
66
if ( cls == TypeCache . PythonTuple ) {
67
67
if ( sequence . GetType ( ) == typeof ( PythonTuple ) ) return ( PythonTuple ) sequence ;
68
- return new PythonTuple ( sequence ) ;
68
+ return new PythonTuple ( context , sequence ) ;
69
69
} else {
70
- if ( ! ( cls . CreateInstance ( context , sequence ) is PythonTuple tupObj ) ) throw PythonOps . TypeError ( "{0} is not a subclass of tuple" , cls ) ;
70
+ if ( cls . CreateInstance ( context , sequence ) is not PythonTuple tupObj ) throw PythonOps . TypeError ( "{0} is not a subclass of tuple" , cls ) ;
71
71
return tupObj ;
72
72
}
73
73
}
@@ -115,15 +115,15 @@ public int count(object? obj) {
115
115
116
116
internal static PythonTuple Make ( object o ) {
117
117
if ( o is PythonTuple t ) return t ;
118
- return new PythonTuple ( o ) ;
118
+ return new PythonTuple ( DefaultContext . Default , o ) ;
119
119
}
120
120
121
121
internal static PythonTuple MakeTuple ( params object ? [ ] items ) {
122
122
if ( items . Length == 0 ) return EMPTY ;
123
- return new PythonTuple ( items ) ;
123
+ return new PythonTuple ( DefaultContext . Default , items ) ;
124
124
}
125
125
126
- private static object ? [ ] MakeItems ( object ? o ) {
126
+ private static object ? [ ] MakeItems ( CodeContext context , object ? o ) {
127
127
var t = o ? . GetType ( ) ;
128
128
// Only use fast paths if we have an exact tuple/list, otherwise use iter
129
129
if ( t == typeof ( PythonTuple ) ) {
@@ -142,7 +142,7 @@ internal static PythonTuple MakeTuple(params object?[] items) {
142
142
PerfTrack . NoteEvent ( PerfTrack . Categories . OverAllocate , "TupleOA: " + PythonOps . GetPythonTypeName ( o ) ) ;
143
143
144
144
var l = new List < object ? > ( ) ;
145
- IEnumerator i = PythonOps . GetEnumerator ( o ) ;
145
+ IEnumerator i = PythonOps . GetEnumerator ( context , o ) ;
146
146
while ( i . MoveNext ( ) ) {
147
147
l . Add ( i . Current ) ;
148
148
}
@@ -315,8 +315,8 @@ public IEnumerator GetEnumerator() {
315
315
}
316
316
317
317
public object __getnewargs__ ( ) {
318
- // Call "new Tuple ()" to force result to be a Tuple (otherwise, it could possibly be a Tuple subclass)
319
- return PythonTuple . MakeTuple ( new PythonTuple ( this ) ) ;
318
+ // Call "MakeTuple ()" to force result to be specifically a Tuple (otherwise, it could possibly be a Tuple subclass)
319
+ return PythonTuple . MakeTuple ( _data ) ;
320
320
}
321
321
322
322
#region IEnumerable<object> Members
0 commit comments