@@ -34,7 +34,7 @@ static void TupleConversionsGeneric<T, TTuple>()
34
34
using ( var scope = Py . CreateScope ( ) )
35
35
{
36
36
void Accept ( T value ) => restored = value ;
37
- var accept = new Action < T > ( Accept ) . ToPython ( ) ;
37
+ using var accept = new Action < T > ( Accept ) . ToPython ( ) ;
38
38
scope . Set ( nameof ( tuple ) , tuple ) ;
39
39
scope . Set ( nameof ( accept ) , accept ) ;
40
40
scope . Exec ( $ "{ nameof ( accept ) } ({ nameof ( tuple ) } )") ;
@@ -55,7 +55,7 @@ static void TupleConversionsObject<T, TTuple>()
55
55
using ( var scope = Py . CreateScope ( ) )
56
56
{
57
57
void Accept ( object value ) => restored = ( T ) value ;
58
- var accept = new Action < object > ( Accept ) . ToPython ( ) ;
58
+ using var accept = new Action < object > ( Accept ) . ToPython ( ) ;
59
59
scope . Set ( nameof ( tuple ) , tuple ) ;
60
60
scope . Set ( nameof ( accept ) , accept ) ;
61
61
scope . Exec ( $ "{ nameof ( accept ) } ({ nameof ( tuple ) } )") ;
@@ -71,7 +71,7 @@ public void TupleRoundtripObject()
71
71
static void TupleRoundtripObject < T , TTuple > ( )
72
72
{
73
73
var tuple = Activator . CreateInstance ( typeof ( T ) , 42.0 , "42" , new object ( ) ) ;
74
- var pyTuple = TupleCodec < TTuple > . Instance . TryEncode ( tuple ) ;
74
+ using var pyTuple = TupleCodec < TTuple > . Instance . TryEncode ( tuple ) ;
75
75
Assert . IsTrue ( TupleCodec < TTuple > . Instance . TryDecode ( pyTuple , out object restored ) ) ;
76
76
Assert . AreEqual ( expected : tuple , actual : restored ) ;
77
77
}
@@ -85,7 +85,7 @@ public void TupleRoundtripGeneric()
85
85
static void TupleRoundtripGeneric < T , TTuple > ( )
86
86
{
87
87
var tuple = Activator . CreateInstance ( typeof ( T ) , 42 , "42" , new object ( ) ) ;
88
- var pyTuple = TupleCodec < TTuple > . Instance . TryEncode ( tuple ) ;
88
+ using var pyTuple = TupleCodec < TTuple > . Instance . TryEncode ( tuple ) ;
89
89
Assert . IsTrue ( TupleCodec < TTuple > . Instance . TryDecode ( pyTuple , out T restored ) ) ;
90
90
Assert . AreEqual ( expected : tuple , actual : restored ) ;
91
91
}
@@ -98,9 +98,9 @@ public void ListDecoderTest()
98
98
var codec = ListDecoder . Instance ;
99
99
var items = new List < PyObject > ( ) { new PyInt ( 1 ) , new PyInt ( 2 ) , new PyInt ( 3 ) } ;
100
100
101
- var pyList = new PyList ( items . ToArray ( ) ) ;
101
+ using var pyList = new PyList ( items . ToArray ( ) ) ;
102
102
103
- var pyListType = pyList . GetPythonType ( ) ;
103
+ using var pyListType = pyList . GetPythonType ( ) ;
104
104
Assert . IsTrue ( codec . CanDecode ( pyListType , typeof ( IList < bool > ) ) ) ;
105
105
Assert . IsTrue ( codec . CanDecode ( pyListType , typeof ( IList < int > ) ) ) ;
106
106
Assert . IsFalse ( codec . CanDecode ( pyListType , typeof ( System . Collections . IEnumerable ) ) ) ;
@@ -128,8 +128,8 @@ public void ListDecoderTest()
128
128
Assert . Throws ( typeof ( InvalidCastException ) , ( ) => { var x = stringList [ 0 ] ; } ) ;
129
129
130
130
//can't convert python iterable to list (this will require a copy which isn't lossless)
131
- var foo = GetPythonIterable ( ) ;
132
- var fooType = foo . GetPythonType ( ) ;
131
+ using var foo = GetPythonIterable ( ) ;
132
+ using var fooType = foo . GetPythonType ( ) ;
133
133
Assert . IsFalse ( codec . CanDecode ( fooType , typeof ( IList < int > ) ) ) ;
134
134
}
135
135
@@ -140,8 +140,8 @@ public void SequenceDecoderTest()
140
140
var items = new List < PyObject > ( ) { new PyInt ( 1 ) , new PyInt ( 2 ) , new PyInt ( 3 ) } ;
141
141
142
142
//SequenceConverter can only convert to any ICollection
143
- var pyList = new PyList ( items . ToArray ( ) ) ;
144
- var listType = pyList . GetPythonType ( ) ;
143
+ using var pyList = new PyList ( items . ToArray ( ) ) ;
144
+ using var listType = pyList . GetPythonType ( ) ;
145
145
//it can convert a PyList, since PyList satisfies the python sequence protocol
146
146
147
147
Assert . IsFalse ( codec . CanDecode ( listType , typeof ( bool ) ) ) ;
0 commit comments