From 146ebce9a06a472044c2af941ccc1b9c415dcfde Mon Sep 17 00:00:00 2001 From: Martin-Molinero Date: Fri, 6 May 2022 16:05:12 -0300 Subject: [PATCH 1/2] Fix collection handling --- src/embed_tests/QCTest.cs | 18 +++++++++++++++++- src/runtime/InteropConfiguration.cs | 5 +++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/embed_tests/QCTest.cs b/src/embed_tests/QCTest.cs index 4433a4856..789834735 100644 --- a/src/embed_tests/QCTest.cs +++ b/src/embed_tests/QCTest.cs @@ -9,6 +9,7 @@ namespace Python.EmbeddingTest { class QCTests { + private static dynamic containsTest; private static dynamic module; private static string testModule = @" from clr import AddReference @@ -22,13 +23,20 @@ def TestA(self): return True except: return False + +def ContainsTest(key, collection): + if key in collection.Keys: + return True + return False "; [OneTimeSetUp] public void Setup() { PythonEngine.Initialize(); - module = PyModule.FromString("module", testModule).GetAttr("PythonModule").Invoke(); + var pyModule = PyModule.FromString("module", testModule); + containsTest = pyModule.GetAttr("ContainsTest"); + module = pyModule.GetAttr("PythonModule").Invoke(); } [OneTimeTearDown] @@ -46,6 +54,14 @@ public void ParamTest() var output = (bool)module.TestA(); Assert.IsTrue(output); } + + [TestCase("AAPL", false)] + [TestCase("SPY", true)] + public void ContainsTest(string key, bool expected) + { + var dic = new Dictionary { { "SPY", new object() } }; + Assert.AreEqual(expected, (bool)containsTest(key, dic)); + } } public class Algo diff --git a/src/runtime/InteropConfiguration.cs b/src/runtime/InteropConfiguration.cs index 30c9a1c2c..202991d25 100644 --- a/src/runtime/InteropConfiguration.cs +++ b/src/runtime/InteropConfiguration.cs @@ -20,8 +20,9 @@ public static InteropConfiguration MakeDefault() { PythonBaseTypeProviders = { - DefaultBaseTypeProvider.Instance, - new CollectionMixinsProvider(new Lazy(() => Py.Import("clr._extras.collections"))), + DefaultBaseTypeProvider.Instance + // see https://github.com/pythonnet/pythonnet/issues/1785 + // new CollectionMixinsProvider(new Lazy(() => Py.Import("clr._extras.collections"))), }, }; } From 9b341b7ef8b51cc380fc4a6c61e862c564140fa2 Mon Sep 17 00:00:00 2001 From: Martin-Molinero Date: Fri, 6 May 2022 16:12:32 -0300 Subject: [PATCH 2/2] Update to pythonnet 2.0.14 --- src/perf_tests/Python.PerformanceTests.csproj | 4 ++-- src/runtime/Properties/AssemblyInfo.cs | 4 ++-- src/runtime/Python.Runtime.csproj | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/perf_tests/Python.PerformanceTests.csproj b/src/perf_tests/Python.PerformanceTests.csproj index acba18ddd..a7726f2d7 100644 --- a/src/perf_tests/Python.PerformanceTests.csproj +++ b/src/perf_tests/Python.PerformanceTests.csproj @@ -13,7 +13,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + compile @@ -25,7 +25,7 @@ - + diff --git a/src/runtime/Properties/AssemblyInfo.cs b/src/runtime/Properties/AssemblyInfo.cs index 6513f75bf..ff96d4531 100644 --- a/src/runtime/Properties/AssemblyInfo.cs +++ b/src/runtime/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ [assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")] [assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")] -[assembly: AssemblyVersion("2.0.13")] -[assembly: AssemblyFileVersion("2.0.13")] +[assembly: AssemblyVersion("2.0.14")] +[assembly: AssemblyFileVersion("2.0.14")] diff --git a/src/runtime/Python.Runtime.csproj b/src/runtime/Python.Runtime.csproj index 407e691f7..24d007d75 100644 --- a/src/runtime/Python.Runtime.csproj +++ b/src/runtime/Python.Runtime.csproj @@ -5,7 +5,7 @@ Python.Runtime Python.Runtime QuantConnect.pythonnet - 2.0.13 + 2.0.14 false LICENSE https://github.com/pythonnet/pythonnet