@@ -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
@@ -972,7 +972,7 @@ private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs)
972972 }
973973 else
974974 {
975- ptr = Converter . ToPython ( inargs [ i ] , inargs [ i ] . GetType ( ) ) ;
975+ ptr = Converter . ToPython ( inargs [ i ] , inargs [ i ] ? . GetType ( ) ) ;
976976 }
977977 if ( Runtime . PyTuple_SetItem ( argtuple , i , ptr ) < 0 )
978978 throw new PythonException ( ) ;
@@ -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,25 @@ 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 ) ) ;
11371137 return true ;
11381138 }
11391139
1140+ // Workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=41509
1141+ // See https://github.com/pythonnet/pythonnet/pull/219
1142+ private static object CheckNone ( PyObject pyObj )
1143+ {
1144+ if ( pyObj != null )
1145+ {
1146+ if ( pyObj . obj == Runtime . PyNone )
1147+ {
1148+ return null ;
1149+ }
1150+ }
1151+
1152+ return pyObj ;
1153+ }
1154+
11401155 public override bool TryUnaryOperation ( UnaryOperationBinder binder , out Object result )
11411156 {
11421157 int r ;
@@ -1170,7 +1185,7 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out Object r
11701185 result = null ;
11711186 return false ;
11721187 }
1173- result = new PyObject ( res ) ;
1188+ result = CheckNone ( new PyObject ( res ) ) ;
11741189 return true ;
11751190 }
11761191 }
0 commit comments