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

Lines changed: 1 addition & 8 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy