@@ -34,7 +34,7 @@ static void TupleConversionsGeneric<T, TTuple>()
3434 using ( var scope = Py . CreateScope ( ) )
3535 {
3636 void Accept ( T value ) => restored = value ;
37- var accept = new Action < T > ( Accept ) . ToPython ( ) ;
37+ using var accept = new Action < T > ( Accept ) . ToPython ( ) ;
3838 scope . Set ( nameof ( tuple ) , tuple ) ;
3939 scope . Set ( nameof ( accept ) , accept ) ;
4040 scope . Exec ( $ "{ nameof ( accept ) } ({ nameof ( tuple ) } )") ;
@@ -55,7 +55,7 @@ static void TupleConversionsObject<T, TTuple>()
5555 using ( var scope = Py . CreateScope ( ) )
5656 {
5757 void Accept ( object value ) => restored = ( T ) value ;
58- var accept = new Action < object > ( Accept ) . ToPython ( ) ;
58+ using var accept = new Action < object > ( Accept ) . ToPython ( ) ;
5959 scope . Set ( nameof ( tuple ) , tuple ) ;
6060 scope . Set ( nameof ( accept ) , accept ) ;
6161 scope . Exec ( $ "{ nameof ( accept ) } ({ nameof ( tuple ) } )") ;
@@ -71,7 +71,7 @@ public void TupleRoundtripObject()
7171 static void TupleRoundtripObject < T , TTuple > ( )
7272 {
7373 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 ) ;
7575 Assert . IsTrue ( TupleCodec < TTuple > . Instance . TryDecode ( pyTuple , out object restored ) ) ;
7676 Assert . AreEqual ( expected : tuple , actual : restored ) ;
7777 }
@@ -85,7 +85,7 @@ public void TupleRoundtripGeneric()
8585 static void TupleRoundtripGeneric < T , TTuple > ( )
8686 {
8787 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 ) ;
8989 Assert . IsTrue ( TupleCodec < TTuple > . Instance . TryDecode ( pyTuple , out T restored ) ) ;
9090 Assert . AreEqual ( expected : tuple , actual : restored ) ;
9191 }
@@ -98,9 +98,9 @@ public void ListDecoderTest()
9898 var codec = ListDecoder . Instance ;
9999 var items = new List < PyObject > ( ) { new PyInt ( 1 ) , new PyInt ( 2 ) , new PyInt ( 3 ) } ;
100100
101- var pyList = new PyList ( items . ToArray ( ) ) ;
101+ using var pyList = new PyList ( items . ToArray ( ) ) ;
102102
103- var pyListType = pyList . GetPythonType ( ) ;
103+ using var pyListType = pyList . GetPythonType ( ) ;
104104 Assert . IsTrue ( codec . CanDecode ( pyListType , typeof ( IList < bool > ) ) ) ;
105105 Assert . IsTrue ( codec . CanDecode ( pyListType , typeof ( IList < int > ) ) ) ;
106106 Assert . IsFalse ( codec . CanDecode ( pyListType , typeof ( System . Collections . IEnumerable ) ) ) ;
@@ -128,8 +128,8 @@ public void ListDecoderTest()
128128 Assert . Throws ( typeof ( InvalidCastException ) , ( ) => { var x = stringList [ 0 ] ; } ) ;
129129
130130 //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 ( ) ;
133133 Assert . IsFalse ( codec . CanDecode ( fooType , typeof ( IList < int > ) ) ) ;
134134 }
135135
@@ -140,8 +140,8 @@ public void SequenceDecoderTest()
140140 var items = new List < PyObject > ( ) { new PyInt ( 1 ) , new PyInt ( 2 ) , new PyInt ( 3 ) } ;
141141
142142 //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 ( ) ;
145145 //it can convert a PyList, since PyList satisfies the python sequence protocol
146146
147147 Assert . IsFalse ( codec . CanDecode ( listType , typeof ( bool ) ) ) ;
0 commit comments