Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does cython support dataclasses or something similar

I am interested in passing data between Python and Cython code so that the data are accessible from C and without GIL. I am thinking about achieving this using dataclasses (since py3.7), named tuples (with nice defining syntax since py3.6) or Cython's extension types (cdef classess).

Unfortunately, dataclasses and named tuples seem to be handled like generic objects from Cython without any support of being compiled into C.

Cython extension types (cdef classes) can be used, but they have many disadvantages compared to dataclasses, most importantly you have to implement __init__ with boilerplate code for setting all your class attributes, right?

like image 550
Lefty Avatar asked Mar 23 '19 14:03

Lefty


1 Answers

I asked Cython developers and they opened a feature request for implementing @dataclass for extension types (cdef classes): https://github.com/cython/cython/issues/2903. So hopefully they will be supported in Cython soon.

like image 94
Lefty Avatar answered Sep 29 '22 22:09

Lefty