@@ -527,9 +527,8 @@ public enum RunFlagType
527527 Eval = 258
528528 }
529529
530- public class PySessionDisposedException : Exception
530+ public class PySessionDisposedException : Exception
531531 {
532-
533532 }
534533
535534 public class PyScope : IDisposable
@@ -564,7 +563,7 @@ public void ReleaseLock()
564563
565564 public void Dispose ( )
566565 {
567- this . ReleaseLock ( ) ;
566+ ReleaseLock ( ) ;
568567 GC . SuppressFinalize ( this ) ;
569568 }
570569
@@ -584,7 +583,7 @@ public void Dispose()
584583
585584 private PyScope ( GILState state )
586585 {
587- this . isDisposed = false ;
586+ isDisposed = false ;
588587 this . state = state ;
589588 globals = Runtime . PyDict_New ( ) ;
590589 if ( globals == IntPtr . Zero )
@@ -599,14 +598,14 @@ private PyScope(GILState state)
599598 }
600599
601600 internal PyScope ( string name , GILState state )
602- : this ( state )
601+ : this ( state )
603602 {
604603 this . state = state ;
605604 this . name = name ;
606605 Runtime . PyDict_SetItemString (
607- globals , "__builtins__" ,
608- Runtime . PyEval_GetBuiltins ( )
609- ) ;
606+ globals , "__builtins__" ,
607+ Runtime . PyEval_GetBuiltins ( )
608+ ) ;
610609 }
611610
612611 internal PyScope ( PyScope parent , GILState state )
@@ -639,29 +638,21 @@ internal PyScope(PyScope parent, GILState state)
639638 /// <summary>
640639 /// the dict for global variables
641640 /// </summary>
642- public IntPtr globals
643- {
644- get ;
645- private set ;
646- }
641+ public IntPtr globals { get ; private set ; }
647642
648643 /// <summary>
649644 /// the dict for local variables
650645 /// </summary>
651- public IntPtr locals
652- {
653- get ;
654- private set ;
655- }
646+ public IntPtr locals { get ; private set ; }
656647
657648 public PyScope SubScope ( )
658649 {
659- return new PyScope ( this , this . state ) ;
650+ return new PyScope ( this , state ) ;
660651 }
661652
662653 public void Suspend ( )
663654 {
664- this . state . ReleaseLock ( ) ;
655+ state . ReleaseLock ( ) ;
665656 }
666657
667658 /// <summary>
@@ -685,7 +676,7 @@ public PyObject Import(string name)
685676 /// </remarks>
686677 public PyObject ImportAs ( string name , string asname )
687678 {
688- this . AcquireLock ( ) ;
679+ AcquireLock ( ) ;
689680 PyObject module = PythonEngine . ImportModule ( name ) ;
690681 if ( asname == null )
691682 {
@@ -699,7 +690,7 @@ public PyObject Execute(PyObject script)
699690 {
700691 IntPtr ptr = Runtime . PyEval_EvalCode ( script . Handle , globals , locals ) ;
701692 Runtime . CheckExceptionOccurred ( ) ;
702- if ( ptr == Runtime . PyNone )
693+ if ( ptr == Runtime . PyNone )
703694 {
704695 Runtime . XDecref ( ptr ) ;
705696 return null ;
@@ -709,12 +700,12 @@ public PyObject Execute(PyObject script)
709700
710701 public T Execute < T > ( PyObject script )
711702 {
712- var pyObj = this . Execute ( script ) ;
713- if ( pyObj == null )
703+ PyObject pyObj = Execute ( script ) ;
704+ if ( pyObj == null )
714705 {
715706 return default ( T ) ;
716707 }
717- T obj = ( T ) pyObj . AsManagedObject ( typeof ( T ) ) ;
708+ var obj = ( T ) pyObj . AsManagedObject ( typeof ( T ) ) ;
718709 return obj ;
719710 }
720711
@@ -726,7 +717,7 @@ public T Execute<T>(PyObject script)
726717 /// </remarks>
727718 public PyObject Compile ( string code , string filename = "" , RunFlagType mode = RunFlagType . File )
728719 {
729- IntPtr flag = ( IntPtr ) mode ;
720+ var flag = ( IntPtr ) mode ;
730721 IntPtr ptr = Runtime . Py_CompileString ( code , filename , flag ) ;
731722 Runtime . CheckExceptionOccurred ( ) ;
732723 return new PyObject ( ptr ) ;
@@ -741,7 +732,7 @@ public PyObject Compile(string code, string filename = "", RunFlagType mode = Ru
741732 /// </remarks>
742733 public PyObject Eval ( string code )
743734 {
744- this . AcquireLock ( ) ;
735+ AcquireLock ( ) ;
745736 var flag = ( IntPtr ) Runtime . Py_eval_input ;
746737 IntPtr ptr = Runtime . PyRun_String (
747738 code , flag , globals , locals
@@ -759,7 +750,7 @@ public PyObject Eval(string code)
759750 public T Eval < T > ( string code )
760751 {
761752 PyObject pyObj = Eval ( code ) ;
762- T obj = ( T ) pyObj . AsManagedObject ( typeof ( T ) ) ;
753+ var obj = ( T ) pyObj . AsManagedObject ( typeof ( T ) ) ;
763754 return obj ;
764755 }
765756
@@ -771,8 +762,8 @@ public T Eval<T>(string code)
771762 /// </remarks>
772763 public void Exec ( string code )
773764 {
774- this . AcquireLock ( ) ;
775- Exec ( code , this . globals , this . locals ) ;
765+ AcquireLock ( ) ;
766+ Exec ( code , globals , locals ) ;
776767 }
777768
778769 private void Exec ( string code , IntPtr _globals , IntPtr _locals )
@@ -798,7 +789,7 @@ private void Exec(string code, IntPtr _globals, IntPtr _locals)
798789 /// </remarks>
799790 internal void SetGlobalVariable ( string name , object value )
800791 {
801- this . AcquireLock ( ) ;
792+ AcquireLock ( ) ;
802793 using ( var pyKey = new PyString ( name ) )
803794 {
804795 IntPtr _value = GetInstHandle ( value ) ;
@@ -819,7 +810,7 @@ internal void SetGlobalVariable(string name, object value)
819810 /// </remarks>
820811 internal void RemoveGlobalVariable ( string name )
821812 {
822- this . AcquireLock ( ) ;
813+ AcquireLock ( ) ;
823814 using ( var pyKey = new PyString ( name ) )
824815 {
825816 int r = Runtime . PyObject_DelItem ( globals , pyKey . obj ) ;
@@ -839,7 +830,7 @@ internal void RemoveGlobalVariable(string name)
839830 /// </remarks>
840831 public void SetVariable ( string name , object value )
841832 {
842- this . AcquireLock ( ) ;
833+ AcquireLock ( ) ;
843834 using ( var pyKey = new PyString ( name ) )
844835 {
845836 IntPtr _value = GetInstHandle ( value ) ;
@@ -860,7 +851,7 @@ public void SetVariable(string name, object value)
860851 /// </remarks>
861852 public void RemoveVariable ( string name )
862853 {
863- this . AcquireLock ( ) ;
854+ AcquireLock ( ) ;
864855 using ( var pyKey = new PyString ( name ) )
865856 {
866857 int r = Runtime . PyObject_DelItem ( locals , pyKey . obj ) ;
@@ -879,7 +870,7 @@ public void RemoveVariable(string name)
879870 /// </remarks>
880871 public bool ContainsVariable ( string name )
881872 {
882- this . AcquireLock ( ) ;
873+ AcquireLock ( ) ;
883874 using ( var pyKey = new PyString ( name ) )
884875 {
885876 if ( Runtime . PyMapping_HasKey ( locals , pyKey . obj ) != 0 )
@@ -899,7 +890,7 @@ public bool ContainsVariable(string name)
899890 /// </remarks>
900891 public PyObject GetVariable ( string name )
901892 {
902- this . AcquireLock ( ) ;
893+ AcquireLock ( ) ;
903894 using ( var pyKey = new PyString ( name ) )
904895 {
905896 IntPtr op ;
@@ -925,7 +916,7 @@ public PyObject GetVariable(string name)
925916
926917 public T GetVariable < T > ( string name )
927918 {
928- PyObject obj = this . GetVariable ( name ) ;
919+ PyObject obj = GetVariable ( name ) ;
929920 return ( T ) obj . AsManagedObject ( typeof ( T ) ) ;
930921 }
931922
@@ -938,29 +929,29 @@ private static IntPtr GetInstHandle(object value)
938929 }
939930 else
940931 {
941- var ptr = Converter . ToPython ( value , value . GetType ( ) ) ;
932+ IntPtr ptr = Converter . ToPython ( value , value . GetType ( ) ) ;
942933 return ptr ;
943934 }
944935 }
945936
946937 private void AcquireLock ( )
947938 {
948- if ( isDisposed )
939+ if ( isDisposed )
949940 {
950941 throw new PySessionDisposedException ( ) ;
951942 }
952- this . state . AcquireLock ( ) ;
943+ state . AcquireLock ( ) ;
953944 }
954945
955946 public virtual void Dispose ( )
956947 {
957- if ( isDisposed )
948+ if ( isDisposed )
958949 {
959950 return ;
960951 }
961952 Runtime . XDecref ( globals ) ;
962953 Runtime . XDecref ( locals ) ;
963- if ( this . parent == null )
954+ if ( parent == null )
964955 {
965956 Py . RemoveSession ( name ) ;
966957 }
@@ -999,7 +990,7 @@ public static PyScope Session(string name)
999990 {
1000991 PythonEngine . Initialize ( ) ;
1001992 }
1002- if ( Sessions . ContainsKey ( name ) )
993+ if ( Sessions . ContainsKey ( name ) )
1003994 {
1004995 return Sessions [ name ] ;
1005996 }
0 commit comments