@@ -939,7 +939,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
939939 {
940940 if ( this . HasAttr ( binder . Name ) )
941941 {
942- result = this . GetAttr ( binder . Name ) ;
942+ result = CheckNone ( this . GetAttr ( binder . Name ) ) ;
943943 return true ;
944944 }
945945 else
@@ -999,7 +999,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
999999 try
10001000 {
10011001 GetArgs ( args , out pyargs , out kwargs ) ;
1002- result = InvokeMethod ( binder . Name , pyargs , kwargs ) ;
1002+ result = CheckNone ( InvokeMethod ( binder . Name , pyargs , kwargs ) ) ;
10031003 }
10041004 finally
10051005 {
@@ -1023,7 +1023,7 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re
10231023 try
10241024 {
10251025 GetArgs ( args , out pyargs , out kwargs ) ;
1026- result = Invoke ( pyargs , kwargs ) ;
1026+ result = CheckNone ( Invoke ( pyargs , kwargs ) ) ;
10271027 }
10281028 finally
10291029 {
@@ -1133,10 +1133,26 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, Object arg
11331133 result = null ;
11341134 return false ;
11351135 }
1136- result = new PyObject ( res ) ;
1136+ result = CheckNone ( new PyObject ( res ) ) ;
1137+
11371138 return true ;
11381139 }
11391140
1141+ // Workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=41509
1142+ // See https://github.com/pythonnet/pythonnet/pull/219
1143+ private static object CheckNone ( PyObject pyObj )
1144+ {
1145+ if ( pyObj != null )
1146+ {
1147+ if ( pyObj . obj == Runtime . PyNone )
1148+ {
1149+ return null ;
1150+ }
1151+ }
1152+
1153+ return pyObj ;
1154+ }
1155+
11401156 public override bool TryUnaryOperation ( UnaryOperationBinder binder , out Object result )
11411157 {
11421158 int r ;
@@ -1170,7 +1186,7 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out Object r
11701186 result = null ;
11711187 return false ;
11721188 }
1173- result = new PyObject ( res ) ;
1189+ result = CheckNone ( new PyObject ( res ) ) ;
11741190 return true ;
11751191 }
11761192 }
0 commit comments