Skip to content

Commit 7ec0c02

Browse files
committed
Exceptions init fix.
1 parent 4c691f8 commit 7ec0c02

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Python.Runtime/exceptions.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,21 @@ internal static void Initialize()
9797
warnings_module = Runtime.PyImport_ImportModule("warnings");
9898
Exceptions.ErrorCheck(warnings_module);
9999
Type type = typeof(Exceptions);
100-
foreach (FieldInfo fi in type.GetFields(BindingFlags.Public |
101-
BindingFlags.Static))
100+
foreach (var fi in type.GetFields(
101+
BindingFlags.Public |
102+
BindingFlags.Static))
102103
{
103-
IntPtr op = Runtime.PyObject_GetAttrString(exceptions_module, fi.Name);
104+
if (Runtime.pyversionnumber < 25
105+
&& (fi.Name == "BaseException" || fi.Name == "GeneratorExit"))
106+
{
107+
continue;
108+
}
109+
if (Runtime.pyversionnumber >= 32 && fi.Name == "StandardError")
110+
{
111+
continue;
112+
}
113+
114+
var op = Runtime.PyObject_GetAttrString(exceptions_module, fi.Name);
104115
if (op != IntPtr.Zero)
105116
{
106117
fi.SetValue(type, op);

0 commit comments

Comments
 (0)