Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 11 src/embed_tests/dynamic.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Python.Runtime;
Expand Down Expand Up @@ -126,5 +127,15 @@ public void PassPyObjectInNet()
// Compare in .NET
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
}

// regression test for https://github.com/pythonnet/pythonnet/issues/1680
[Test]
public void ForEach()
{
dynamic pyList = PythonEngine.Eval("[1,2,3]");
var list = new List<int>();
foreach (int item in pyList)
list.Add(item);
}
}
}
6 changes: 6 additions & 0 deletions 6 src/runtime/PythonTypes/PyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,12 @@ public override bool TryConvert(ConvertBinder binder, out object? result)
return converted;
}

if (binder.Type == typeof(System.Collections.IEnumerable) && this.IsIterable())
{
result = new PyIterable(this.Reference);
return true;
}

return false;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.