File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -82,10 +82,20 @@ internal static class EnumOps<T> where T : Enum
82
82
{
83
83
[ ForbidPythonThreads ]
84
84
#pragma warning disable IDE1006 // Naming Styles - must match Python
85
- public static PyInt __int__ ( T value )
85
+ public static PyInt __int__ ( T value ) {
86
86
#pragma warning restore IDE1006 // Naming Styles
87
- => typeof ( T ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 )
88
- ? new PyInt ( Convert . ToUInt64 ( value ) )
89
- : new PyInt ( Convert . ToInt64 ( value ) ) ;
87
+ if ( typeof ( T ) . GetEnumUnderlyingType ( ) == typeof ( UInt64 ) )
88
+ {
89
+ var converted = Convert . ToUInt64 ( value ) ;
90
+ using var _ = Py . GIL ( ) ;
91
+ return new PyInt ( converted ) ;
92
+ }
93
+ else
94
+ {
95
+ var converted = Convert . ToInt64 ( value ) ;
96
+ using var _ = Py . GIL ( ) ;
97
+ return new PyInt ( converted ) ;
98
+ }
99
+ }
90
100
}
91
101
}
Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ def test_ulong_enum():
87
87
assert Test .ULongEnum .Two == Test .ULongEnum (2 )
88
88
89
89
90
+ def test_simple_enum_to_int ():
91
+ from System import DayOfWeek
92
+ assert int (DayOfWeek .Sunday ) == 0
93
+
94
+
90
95
def test_long_enum_to_int ():
91
96
assert int (Test .LongEnum .Max ) == 9223372036854775807
92
97
assert int (Test .LongEnum .Min ) == - 9223372036854775808
@@ -138,6 +143,7 @@ def test_enum_undefined_value():
138
143
# explicitly permit undefined values
139
144
Test .FieldTest ().EnumField = Test .ShortEnum (20 , True )
140
145
146
+
141
147
def test_enum_conversion ():
142
148
"""Test enumeration conversion."""
143
149
ob = Test .FieldTest ()
You can’t perform that action at this time.
0 commit comments