| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -786,7 +786,7 @@ public static void InvokeCtor(IPythonDerivedType obj, string origCtorName, Objec | |||
| 786 | 786 | PyObject[] pyargs = new PyObject[args.Length]; | |
| 787 | 787 | for (int i = 0; i < args.Length; ++i) | |
| 788 | 788 | { | |
| 789 | - pyargs[i] = new PyObject(Converter.ToPython(args[i], args[i].GetType())); | ||
| 789 | + pyargs[i] = new PyObject(Converter.ToPython(args[i], args[i]?.GetType())); | ||
| 790 | 790 | disposeList.Add(pyargs[i]); | |
| 791 | 791 | } | |
| 792 | 792 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -228,7 +228,7 @@ internal static IntPtr ToPython(Object value, Type type) | |||
| 228 | 228 | { | |
| 229 | 229 | foreach (object o in (IEnumerable)value) | |
| 230 | 230 | { | |
| 231 | - using (var p = new PyObject(ToPython(o, o.GetType()))) | ||
| 231 | + using (var p = new PyObject(ToPython(o, o?.GetType()))) | ||
| 232 | 232 | resultlist.Append(p); | |
| 233 | 233 | } | |
| 234 | 234 | Runtime.Incref(resultlist.Handle); | |
@@ -962,7 +962,7 @@ public static class ConverterExtension | |||
| 962 | 962 | { | |
| 963 | 963 | public static PyObject ToPython(this object o) | |
| 964 | 964 | { | |
| 965 | - return new PyObject(Converter.ToPython(o, o.GetType())); | ||
| 965 | + return new PyObject(Converter.ToPython(o, o?.GetType())); | ||
| 966 | 966 | } | |
| 967 | 967 | } | |
| 968 | 968 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,10 @@ public ModuleObject(string name) : base() | |||
| 35 | 35 | string docstring = "Namespace containing types from the following assemblies:\n\n"; | |
| 36 | 36 | foreach (Assembly a in AssemblyManager.GetAssemblies(name)) | |
| 37 | 37 | { | |
| 38 | - filename = a.Location; | ||
| 38 | + if (!a.IsDynamic && a.Location != null) | ||
| 39 | + { | ||
| 40 | + filename = a.Location; | ||
| 41 | + } | ||
| 39 | 42 | docstring += "- " + a.FullName + "\n"; | |
| 40 | 43 | } | |
| 41 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -939,7 +939,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) | |||
| 939 | 939 | { | |
| 940 | 940 | if (this.HasAttr(binder.Name)) | |
| 941 | 941 | { | |
| 942 | - result = this.GetAttr(binder.Name); | ||
| 942 | + result = CheckNone(this.GetAttr(binder.Name)); | ||
| 943 | 943 | return true; | |
| 944 | 944 | } | |
| 945 | 945 | else | |
@@ -972,7 +972,7 @@ private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs) | |||
| 972 | 972 | } | |
| 973 | 973 | else | |
| 974 | 974 | { | |
| 975 | - ptr = Converter.ToPython(inargs[i], inargs[i].GetType()); | ||
| 975 | + ptr = Converter.ToPython(inargs[i], inargs[i]?.GetType()); | ||
| 976 | 976 | } | |
| 977 | 977 | if (Runtime.PyTuple_SetItem(argtuple, i, ptr) < 0) | |
| 978 | 978 | throw new PythonException(); | |
@@ -999,7 +999,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o | |||
| 999 | 999 | try | |
| 1000 | 1000 | { | |
| 1001 | 1001 | GetArgs(args, out pyargs, out kwargs); | |
| 1002 | - result = InvokeMethod(binder.Name, pyargs, kwargs); | ||
| 1002 | + result = CheckNone(InvokeMethod(binder.Name, pyargs, kwargs)); | ||
| 1003 | 1003 | } | |
| 1004 | 1004 | finally | |
| 1005 | 1005 | { | |
@@ -1023,7 +1023,7 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re | |||
| 1023 | 1023 | try | |
| 1024 | 1024 | { | |
| 1025 | 1025 | GetArgs(args, out pyargs, out kwargs); | |
| 1026 | - result = Invoke(pyargs, kwargs); | ||
| 1026 | + result = CheckNone(Invoke(pyargs, kwargs)); | ||
| 1027 | 1027 | } | |
| 1028 | 1028 | finally | |
| 1029 | 1029 | { | |
@@ -1133,10 +1133,25 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, Object arg | |||
| 1133 | 1133 | result = null; | |
| 1134 | 1134 | return false; | |
| 1135 | 1135 | } | |
| 1136 | - result = new PyObject(res); | ||
| 1136 | + result = CheckNone(new PyObject(res)); | ||
| 1137 | 1137 | return true; | |
| 1138 | 1138 | } | |
| 1139 | 1139 | ||
| 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 | + | ||
| 1140 | 1155 | public override bool TryUnaryOperation(UnaryOperationBinder binder, out Object result) | |
| 1141 | 1156 | { | |
| 1142 | 1157 | int r; | |
@@ -1170,7 +1185,7 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out Object r | |||
| 1170 | 1185 | result = null; | |
| 1171 | 1186 | return false; | |
| 1172 | 1187 | } | |
| 1173 | - result = new PyObject(res); | ||
| 1188 | + result = CheckNone(new PyObject(res)); | ||
| 1174 | 1189 | return true; | |
| 1175 | 1190 | } | |
| 1176 | 1191 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -487,7 +487,7 @@ public static KeywordArguments kw(params object[] kv) | |||
| 487 | 487 | if (kv[i + 1] is PyObject) | |
| 488 | 488 | value = ((PyObject)kv[i + 1]).Handle; | |
| 489 | 489 | else | |
| 490 | - value = Converter.ToPython(kv[i + 1], kv[i + 1].GetType()); | ||
| 490 | + value = Converter.ToPython(kv[i + 1], kv[i + 1]?.GetType()); | ||
| 491 | 491 | if (Runtime.PyDict_SetItemString(dict.Handle, (string)kv[i], value) != 0) | |
| 492 | 492 | throw new ArgumentException(string.Format("Cannot add key '{0}' to dictionary.", (string)kv[i])); | |
| 493 | 493 | if (!(kv[i + 1] is PyObject)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,7 @@ | |||
| 108 | 108 | </PropertyGroup> | |
| 109 | 109 | <ItemGroup> | |
| 110 | 110 | <Compile Include="arraytest.cs" /> | |
| 111 | + <Compile Include="callbacktest.cs" /> | ||
| 111 | 112 | <Compile Include="classtest.cs" /> | |
| 112 | 113 | <Compile Include="constructortests.cs" /> | |
| 113 | 114 | <Compile Include="conversiontest.cs" /> | |
@@ -127,6 +128,7 @@ | |||
| 127 | 128 | <Compile Include="subclasstest.cs" /> | |
| 128 | 129 | </ItemGroup> | |
| 129 | 130 | <ItemGroup> | |
| 131 | + <Reference Include="Microsoft.CSharp" /> | ||
| 130 | 132 | <Reference Include="System" /> | |
| 131 | 133 | <Reference Include="System.Core"> | |
| 132 | 134 | <RequiredTargetFramework>3.5</RequiredTargetFramework> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Linq; | ||
| 4 | + using System.Text; | ||
| 5 | + | ||
| 6 | + namespace Python.Test | ||
| 7 | + { | ||
| 8 | + //======================================================================== | ||
| 9 | + // Tests callbacks into python code. | ||
| 10 | + //======================================================================== | ||
| 11 | + | ||
| 12 | + public class CallbackTest | ||
| 13 | + { | ||
| 14 | + public string Call_simpleDefaultArg_WithNull(string moduleName) | ||
| 15 | + { | ||
| 16 | + using (Runtime.Py.GIL()) | ||
| 17 | + { | ||
| 18 | + dynamic module = Runtime.Py.Import(moduleName); | ||
| 19 | + return module.simpleDefaultArg(null); | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + public string Call_simpleDefaultArg_WithEmptyArgs(string moduleName) | ||
| 23 | + { | ||
| 24 | + using (Runtime.Py.GIL()) | ||
| 25 | + { | ||
| 26 | + dynamic module = Runtime.Py.Import(moduleName); | ||
| 27 | + return module.simpleDefaultArg(); | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ | |||
| 18 | 18 | # other test modules that import System.Windows.Forms | |
| 19 | 19 | # run first. They must not do module level import/AddReference() | |
| 20 | 20 | # of the System.Windows.Forms namespace. | |
| 21 | + 'test_suite', | ||
| 21 | 22 | 'test_event', | |
| 22 | 23 | 'test_constructors', | |
| 23 | 24 | 'test_enum', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + import unittest | ||
| 2 | + | ||
| 3 | + __all__ = ['test_suite'] | ||
| 4 | + | ||
| 5 | + from .test_import import test_suite as import_tests | ||
| 6 | + from .test_callback import test_suite as callback_tests | ||
| 7 | + | ||
| 8 | + def test_suite(): | ||
| 9 | + suite = unittest.TestSuite() | ||
| 10 | + suite.addTests((import_tests(),)) | ||
| 11 | + suite.addTests((callback_tests(),)) | ||
| 12 | + return suite | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + | ||
| 2 | + import this_package_should_never_exist_ever | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments