-
Notifications
You must be signed in to change notification settings - Fork 720
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
Error when exposing a python method to .Net in python 2. #492
Comments
The definition of PyIterCheck in runtime.cs is
We have tried to implement PyIter_Check for python 2, similarly to the way it is done for python 3, but we have not gotten it to work. Here is what we tried
Maybe you can tell us what we are doing wrong. |
I got a bit further, and I believe that I have understood what is happening. ClassDerivedObject.AddPythonMethod calls PyObject.IsIterable() to find out whether it makes sense to call GetEnumerator on that pyobject. PyObject.IsIterable does a PyIter_Check to find out whether the PyObject implements the iterator interface. However, e.g. So, the test in ClassDerivedObject.AddPythonMethod should probably not be IsIterable, but rather something like |
Here is comparison of macros from CPython C-API: https://github.com/python/cpython/blob/2.7/Include/abstract.h#L637
https://github.com/python/cpython/blob/3.6/Include/abstract.h#L711
|
Yes, and the only difference there is that in python 3.6, the |
Update: Calling IsIterable() in ClassDerivedObject.AddPythonMethod is probably correct - it's the implementation which returns wheter the object is an iterator, not an iterable... |
Perhaps it's easier to discuss in code. I put up a prospective fix at rickardraysearch@5d052ca |
@rickardraysearch feel free to submit a pull request! |
Hi @denfromufa , now there's a PR that passes all tests and might be possible to merge. |
Thanks for finding this issue and fixing it! |
Environment
Details
We are trying to expose a python method in .Net, in a class that inherits from System.Object.
We are following the example code in clr.py in the pythonnet repository except that we are inheriting from System.Object and that we are using a namespace. When we run
we get the error message
Traceback (most recent call last):
File "test.py", line 80, in
class X(System.Object):
TypeError: Error when calling the metaclass bases
Unable to find an entry point named 'PyIter_Check' in DLL 'python27'.
The error seems to be due to the fact that PyIter_Check is a #define statement and not a function in python. Therefore the import of the function fails in runtime.cs. The error does not occur in python 3 because PyIter_Check is not imported when python 3 is used.
The text was updated successfully, but these errors were encountered: