From 86aedb01697e1f8d32dc2c4634a091871e500003 Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Sat, 17 Oct 2020 13:06:33 -0700 Subject: [PATCH] enable creating PyIter from existing PyObject --- src/runtime/pyiter.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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