11using System ;
22using System . Collections . Generic ;
33using System . Diagnostics ;
4+ using System . Linq ;
45using System . Reflection ;
5- using System . Runtime . InteropServices ;
66using System . Text ;
77
88namespace Python . Runtime
@@ -51,6 +51,8 @@ static OperatorMethod()
5151 [ "op_OnesComplement" ] = new SlotDefinition ( "__invert__" , TypeOffset . nb_invert ) ,
5252 [ "op_UnaryNegation" ] = new SlotDefinition ( "__neg__" , TypeOffset . nb_negative ) ,
5353 [ "op_UnaryPlus" ] = new SlotDefinition ( "__pos__" , TypeOffset . nb_positive ) ,
54+
55+ [ "__int__" ] = new SlotDefinition ( "__int__" , TypeOffset . nb_int ) ,
5456 } ;
5557 ComparisonOpMap = new Dictionary < string , string >
5658 {
@@ -97,14 +99,11 @@ public static bool IsComparisonOp(MethodBase method)
9799 /// </summary>
98100 public static void FixupSlots ( BorrowedReference pyType , Type clrType )
99101 {
100- const BindingFlags flags = BindingFlags . Public | BindingFlags . Static ;
101102 Debug . Assert ( _opType != null ) ;
102103
103- var staticMethods =
104- clrType . IsEnum ? typeof ( EnumOps < > ) . MakeGenericType ( clrType ) . GetMethods ( flags )
105- : clrType . GetMethods ( flags ) ;
104+ var operatorCandidates = GetOperatorCandidates ( clrType ) ;
106105
107- foreach ( var method in staticMethods )
106+ foreach ( var method in operatorCandidates )
108107 {
109108 // We only want to override slots for operators excluding
110109 // comparison operators, which are handled by ClassBase.tp_richcompare.
@@ -124,6 +123,18 @@ public static void FixupSlots(BorrowedReference pyType, Type clrType)
124123 }
125124 }
126125
126+ static IEnumerable < MethodInfo > GetOperatorCandidates ( Type clrType )
127+ {
128+ const BindingFlags flags = BindingFlags . Public | BindingFlags . Static ;
129+ if ( clrType . IsEnum )
130+ {
131+ return typeof ( EnumOps < > ) . MakeGenericType ( clrType ) . GetMethods ( flags )
132+ . Concat ( typeof ( FlagEnumOps < > ) . MakeGenericType ( clrType ) . GetMethods ( flags ) ) ;
133+ }
134+
135+ return clrType . GetMethods ( flags ) ;
136+ }
137+
127138 public static string GetPyMethodName ( string clrName )
128139 {
129140 if ( OpMethodMap . ContainsKey ( clrName ) )
0 commit comments