Skip to content

Python handling of C# collection #1785

Closed
@Martin-Molinero

Description

@Martin-Molinero

Environment

  • Pythonnet version: master/3.0
  • Python version: *
  • Operating System: *
  • .NET Runtime: *

Details

  • Describe what you were trying to get done.

Seems that since CollectionMixinsProvider was added this case started failing (if key in collection.Keys:), not sure why CollectionMixinsProvider is required, if this is a bug or not..
Test passes commenting out https://github.com/pythonnet/pythonnet/blob/master/src/runtime/InteropConfiguration.cs#L24

    class ATests
    {
        private static dynamic containsTest;
        private static string testModule = @"
from clr import AddReference
AddReference(""System"")
AddReference(""Python.EmbeddingTest"")

def ContainsTest(key, collection):
    if key in collection.Keys:
        return True
    return False
";

        [OneTimeSetUp]
        public void Setup()
        {
            PythonEngine.Initialize();
            var pyModule = PyModule.FromString("module", testModule);
            containsTest = pyModule.GetAttr("ContainsTest");
        }

        [TestCase("AAPL", false)]
        [TestCase("SPY", true)]
        public void ContainsTest(string key, bool expected)
        {
            var dic = new Dictionary<string, object> { { "SPY", new object() } };
            Assert.AreEqual(expected, (bool)containsTest(key, dic));
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions