File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,19 @@ public class PyIter : PyObject, IEnumerator<PyObject>
24
24
public PyIter ( IntPtr ptr ) : base ( ptr )
25
25
{
26
26
}
27
+ /// <summary>
28
+ /// Creates new <see cref="PyIter"/> from an untyped reference to Python object.
29
+ /// </summary>
30
+ public PyIter ( PyObject pyObject ) : base ( FromPyObject ( pyObject ) ) { }
31
+ static BorrowedReference FromPyObject ( PyObject pyObject ) {
32
+ if ( pyObject is null ) throw new ArgumentNullException ( nameof ( pyObject ) ) ;
33
+
34
+ if ( ! Runtime . PyIter_Check ( pyObject . Reference ) )
35
+ throw new ArgumentException ( "Object does not support iterator protocol" ) ;
36
+
37
+ return pyObject . Reference ;
38
+ }
39
+
27
40
internal PyIter ( BorrowedReference reference ) : base ( reference ) { }
28
41
29
42
protected override void Dispose ( bool disposing )
You can’t perform that action at this time.
0 commit comments