diff --git a/src/runtime/pyiter.cs b/src/runtime/pyiter.cs index da2a600c6..72e967be2 100644 --- a/src/runtime/pyiter.cs +++ b/src/runtime/pyiter.cs @@ -25,6 +25,22 @@ public PyIter(IntPtr ptr) : base(ptr) { } + /// + /// Creates new from an untyped reference to Python object. + /// The object must support iterator protocol. + /// + public PyIter(PyObject pyObject) : base(FromPyObject(pyObject)) { } + static BorrowedReference FromPyObject(PyObject pyObject) { + if (pyObject is null) throw new ArgumentNullException(nameof(pyObject)); + + if (!Runtime.PyIter_Check(pyObject.Reference)) + throw new ArgumentException("Object does not support iterator protocol"); + + return pyObject.Reference; + } + + internal PyIter(BorrowedReference reference) : base(reference) { } + /// /// PyIter factory function. /// pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy