nimpy icon indicating copy to clipboard operation
nimpy copied to clipboard

Iterators not exported when using PyNimObjectExperimental

Open etorres404 opened this issue 2 years ago • 0 comments

Hi friends!

I was playing around with PyNimObjectExperimental and I found that iterators are not exported. For example:

# mymodule.nim
import nimpy

type TestType = ref object of PyNimObjectExperimental
  myField: string

proc setMyField(self: TestType, value: string) {.exportpy.} =
  self.myField = value

proc getMyField(self: TestType): string {.exportpy.} =
  self.myField

iterator iterate(self: TestType): int {.exportpy.} =
  for i in 0..<10: yield i
# test.py
import nimporter
import mymodule
tt = mymodule.TestType()
tt.setMyField("Hello")
assert(tt.getMyField() == "Hello")
print(list(tt.iterate()))

When I execute test.py I obtain the following error:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(list(tt.iterate()))
AttributeError: 'TestType' object has no attribute 'iterate'

This code works if I call the iterate function as mymodule.iterate(tt). I think it could be useful to also have iterators exported for PyNimObjectExperimental types. I'm pretty new to Nim, but I can have a look to that if it is ok :)

etorres404 avatar Jun 16 '22 09:06 etorres404