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
Cython mishandles PEP-3135 __class__ cell in methods #2912
Comments
I think we handle PR welcome, it's probably quite easy. See |
Finishes up #2916 and closes #2912 Uses ClassClassNode for regular classes to get the attribute reliably at runtime (for cdef class it can be resolved at compile-time). It essentially adds the line: __class__ = <ClassCellNode> at the start of the top-level function. This seems slightly clunky, but the advantage is that __class__ is automatically picked up by locals() and is also automatically captured into the scope of any inner functions. No other approach looked like it would handle inner functions particularly easily. Co-authored-by: Tom Keefe <tom.keefe@eigentech.com> Co-authored-by: Tom Keefe <8655118+MisterKeefe@users.noreply.github.com>
Hello, I am having trouble with some inconsistent behaviour round the value of
__class__
in Cythonized code. This is on Python 3.6.7 with Cython 0.29.1.Briefly, in uncythonized code
__class__
inside a method on aclass
refers to theclass
object, whereas once cythonized, it seems to refer to<class 'module'>
. This behaviour is a bit unintuitive, and has caused a few issues in a codebase I'm working on, but it's possible I have misunderstood the language semantics!I have tried to search for reasons / documentation why this is the case, but I couldn't turn up anything. I apologise if there is something really obvious I'm missing here; let me know if so and I'll close the issue at once.
Example:
minimal.py
:(in an interpreter, uncythonized):
(after running
cythonize minimal.py -3
):I believe there is an obvious workaround -- in instance methods,
self.__class__
should still have the correct value. But I was curious if this is intended behaviour, and if so, is there something in the docs about it?The text was updated successfully, but these errors were encountered: