Skip to content

Commit df3b569

Browse files
committed
Fix enum codec
A boxed enum value can't be casted directly to an integer, but using `System.Convert` functions instead works fine.
1 parent 37f1235 commit df3b569

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/runtime/Codecs/EnumPyIntCodec.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@ public bool TryDecode<T>(PyObject pyObj, out T? value)
5353
var enumType = value.GetType();
5454
if (!enumType.IsEnum) return null;
5555

56-
try
57-
{
58-
return new PyInt((long)value);
59-
}
60-
catch (InvalidCastException)
61-
{
62-
return new PyInt((ulong)value);
63-
}
56+
return new PyInt(Convert.ToInt64(value));
6457
}
6558

6659
private EnumPyIntCodec() { }

0 commit comments

Comments
 (0)