File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,22 @@ public PyIter(IntPtr ptr) : base(ptr)
25
25
{
26
26
}
27
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
+
28
44
/// <summary>
29
45
/// PyIter factory function.
30
46
/// </summary>
You can’t perform that action at this time.
0 commit comments