@@ -95,24 +95,21 @@ internal static Exception ToException(IntPtr ob)
9595/// </remarks>
9696public static class Exceptions
9797{
98- internal static IntPtr warnings_module ;
99- internal static IntPtr exceptions_module ;
98+ internal static PyModule warnings_module ;
99+ internal static PyModule exceptions_module ;
100100
101101/// <summary>
102102/// Initialization performed on startup of the Python runtime.
103103/// </summary>
104104internal static void Initialize ( )
105105{
106106string exceptionsModuleName = "builtins" ;
107- exceptions_module = Runtime . PyImport_ImportModule ( exceptionsModuleName ) ;
108-
109- Exceptions . ErrorCheck ( exceptions_module ) ;
110- warnings_module = Runtime . PyImport_ImportModule ( "warnings" ) ;
111- Exceptions . ErrorCheck ( warnings_module ) ;
107+ exceptions_module = PyModule . Import ( exceptionsModuleName ) ;
108+ warnings_module = PyModule . Import ( "warnings" ) ;
112109Type type = typeof ( Exceptions ) ;
113110foreach ( FieldInfo fi in type . GetFields ( BindingFlags . Public | BindingFlags . Static ) )
114111{
115- IntPtr op = Runtime . PyObject_GetAttrString ( exceptions_module , fi . Name ) ;
112+ IntPtr op = Runtime . PyObject_GetAttrString ( exceptions_module . obj , fi . Name ) ;
116113if ( op != IntPtr . Zero )
117114{
118115fi . SetValue ( type , op ) ;
@@ -147,8 +144,8 @@ internal static void Shutdown()
147144Runtime . XDecref ( op ) ;
148145fi . SetValue ( null , IntPtr . Zero ) ;
149146}
150- Runtime . Py_CLEAR ( ref exceptions_module ) ;
151- Runtime . Py_CLEAR ( ref warnings_module ) ;
147+ exceptions_module . Dispose ( ) ;
148+ warnings_module . Dispose ( ) ;
152149}
153150
154151/// <summary>
@@ -348,9 +345,7 @@ public static void warn(string message, IntPtr exception, int stacklevel)
348345Exceptions . RaiseTypeError ( "Invalid exception" ) ;
349346}
350347
351- Runtime . XIncref ( warnings_module ) ;
352- IntPtr warn = Runtime . PyObject_GetAttrString ( warnings_module , "warn" ) ;
353- Runtime . XDecref ( warnings_module ) ;
348+ IntPtr warn = Runtime . PyObject_GetAttrString ( warnings_module . obj , "warn" ) ;
354349Exceptions . ErrorCheck ( warn ) ;
355350
356351IntPtr args = Runtime . PyTuple_New ( 3 ) ;