Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterators not exported when using PyNimObjectExperimental #266

Open
etorres404 opened this issue Jun 16, 2022 · 0 comments
Open

Iterators not exported when using PyNimObjectExperimental #266

etorres404 opened this issue Jun 16, 2022 · 0 comments

Comments

@etorres404
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants