Hi all, given the following minimal example:
___________
class_a.py:
from typing import TYPE_CHECKING
import cython
if TYPE_CHECKING:
if cython.compiled:
from cython.cimports.class_b import B
else:
from class_b import B
class A:
def __init__(self):
pass
def do_something(self):
cself = cython.cast(B, self)
cself.a = 1
cself.do_something_2()
def do_something_2(self):
cself = cython.cast(B, self)
cself.b = 2
___________
class_a.pxd:
cdef class A:
cpdef void do_something(self)
cpdef void do_something_2(self)
from class_a import A
class B(A):
def __init__(self):
self.a = 0
self.b = 0
from class_a cimport A
cdef class B(A):
cdef public int a
cdef public int b
_____________________________
This compiles fine using cython 3.0.9 and python 3.11.6.
However, when trying to
from class_b import B
I get an Error:
AttributeError: partially initialized module 'class_b' has no attribute 'B' (most likely due to a circular import)
I got the same error before only using python (without cython) when the TYPE_CHECKING was missing. So TYPE_CHECKING solved the issue for python, but it does not seem to work with cython.
Do you have an idea how to make the example work with cython?
Thanks and best regards,
Sebastian
PS: The example code may seem a bit strange, trying to cast self to B... This is supposed to be a work around, so I can have a child class that inherits methods from a parent class but may have diffferent typed class attributes. I currently don't know if this will work, because I stumbled across the issue described above.