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

Implement @dataclass for cdef classes #2903

scoder opened this Issue Mar 24, 2019 · 0 comments


None yet
1 participant
Copy link

commented Mar 24, 2019

PEP 557 defines dataclasses, a new feature in Py3.7. It would be nice if Cython could generate equivalent code for cdef classes directly at translation time when it finds an @dataclass constructor on them.

This can be done by generating Cython code and injecting it into the module, similar to what we do for fused types (see or auto-pickling (see the AnalyseDeclarationsTransform in The latter would probably also be a good place to implement the @dataclass decorator, although it seems worth keeping the main part of the implementation in a separate module instead of the transform itself, e.g. Cython.Compiler.Dataclasses.

Since this only applies to cdef classes, it seems better to use a safe and dedicated separate decorator @cython.dataclass than to rely on the generic Python decorator, at least initially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.