2 parents 1391639 + 86aedb0 commit 191bc89Copy full SHA for 191bc89
1 file changed
src/runtime/pyiter.cs
@@ -25,6 +25,22 @@ public PyIter(IntPtr ptr) : base(ptr)
25
{
26
}
27
28
+ /// <summary>
29
+ /// Creates new <see cref="PyIter"/> from an untyped reference to Python object.
30
+ /// The object must support iterator protocol.
31
+ /// </summary>
32
+ public PyIter(PyObject pyObject) : base(FromPyObject(pyObject)) { }
33
+ static BorrowedReference FromPyObject(PyObject pyObject) {
34
+ if (pyObject is null) throw new ArgumentNullException(nameof(pyObject));
35
+
36
+ if (!Runtime.PyIter_Check(pyObject.Reference))
37
+ throw new ArgumentException("Object does not support iterator protocol");
38
39
+ return pyObject.Reference;
40
+ }
41
42
+ internal PyIter(BorrowedReference reference) : base(reference) { }
43
44
/// <summary>
45
/// PyIter factory function.
46
/// </summary>
0 commit comments