Skip to content

Commit 146ebce

Browse files
Fix collection handling
1 parent 4ff3705 commit 146ebce

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/embed_tests/QCTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Python.EmbeddingTest
99
{
1010
class QCTests
1111
{
12+
private static dynamic containsTest;
1213
private static dynamic module;
1314
private static string testModule = @"
1415
from clr import AddReference
@@ -22,13 +23,20 @@ def TestA(self):
2223
return True
2324
except:
2425
return False
26+
27+
def ContainsTest(key, collection):
28+
if key in collection.Keys:
29+
return True
30+
return False
2531
";
2632

2733
[OneTimeSetUp]
2834
public void Setup()
2935
{
3036
PythonEngine.Initialize();
31-
module = PyModule.FromString("module", testModule).GetAttr("PythonModule").Invoke();
37+
var pyModule = PyModule.FromString("module", testModule);
38+
containsTest = pyModule.GetAttr("ContainsTest");
39+
module = pyModule.GetAttr("PythonModule").Invoke();
3240
}
3341

3442
[OneTimeTearDown]
@@ -46,6 +54,14 @@ public void ParamTest()
4654
var output = (bool)module.TestA();
4755
Assert.IsTrue(output);
4856
}
57+
58+
[TestCase("AAPL", false)]
59+
[TestCase("SPY", true)]
60+
public void ContainsTest(string key, bool expected)
61+
{
62+
var dic = new Dictionary<string, object> { { "SPY", new object() } };
63+
Assert.AreEqual(expected, (bool)containsTest(key, dic));
64+
}
4965
}
5066

5167
public class Algo

src/runtime/InteropConfiguration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public static InteropConfiguration MakeDefault()
2020
{
2121
PythonBaseTypeProviders =
2222
{
23-
DefaultBaseTypeProvider.Instance,
24-
new CollectionMixinsProvider(new Lazy<PyObject>(() => Py.Import("clr._extras.collections"))),
23+
DefaultBaseTypeProvider.Instance
24+
// see https://github.com/pythonnet/pythonnet/issues/1785
25+
// new CollectionMixinsProvider(new Lazy<PyObject>(() => Py.Import("clr._extras.collections"))),
2526
},
2627
};
2728
}

0 commit comments

Comments
 (0)