Implement cdef dataclasses (GH-3400)
New decorator/function "@cython.dataclasses.dataclass" and "cython.dataclasses.field()" to mark dataclasses and their fields. Tries to match the interface provided by a regular dataclass as much as possible. This means taking the types from the dataclasses module if available (so they match exactly) or a fallback Python version that just implements the core parts (executed with "PyRun_String()" in the C source). Use of placeholders in generated "__init__" code means the code in the C file isn't hugely readable. Probably not a huge issue, but don't really see a way round that. As part of this I've also also implemented a Cython version of "typing.ClassVar". Although really designed for use with dataclasses it behaves sensibly when used in types in a normal cdef class. This is worth documenting more thoroughly. Closes https://github.com/cython/cython/issues/2903
Showing
Cython/Compiler/Dataclass.py
0 → 100644
This diff is collapsed.
Cython/Utility/Dataclasses.c
0 → 100644
tests/run/typing_module.py
0 → 100644
Please register or sign in to comment