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

Dataclasses do not work with Cython due to annotations being stripped out. #3336

nekokatt opened this issue Jan 29, 2020 · 1 comment


Copy link

@nekokatt nekokatt commented Jan 29, 2020

It would appear that dataclasses now do not work since 3dc2b9d was implemented.

Using the most recent master commit at the time of writing:

import dataclasses

class Foo:
    bar: str = dataclasses.field(default="hello")

>>> cythonize -3i
Compiling /home/.../code/cython-bug/ because it changed.
[1/1] Cythonizing /home/.../code/cython-bug/
running build_ext
building 'test' extension
creating /home/.../code/cython-bug/tmpbh4j4lqe/home
creating /home/.../code/cython-bug/tmpbh4j4lqe/home/
creating /home/.../code/cython-bug/tmpbh4j4lqe/home//code
creating /home/.../code/cython-bug/tmpbh4j4lqe/home///code/cython-bug
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -march=x86-64 -mtune=generic -O3 -pipe -fno-plt -fPIC -I/home/.../code/hikari/.venv/include -I/usr/include/python3.8 -c /home/.../code/cython-bug/test.c -o /home/.../code/cython-bug/tmpbh4j4lqe/home/.../code/cython-bug/test.o
gcc -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now /home/.../code/cython-bug/tmpbh4j4lqe/home/.../code/cython-bug/test.o -L/usr/lib -o /home/.../code/cython-bug/

>>> python -c "import test"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 3, in init test
  File "/usr/lib/python3.8/", line 1011, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "/usr/lib/python3.8/", line 885, in _process_class
    raise TypeError(f'{name!r} is a field but has no type annotation')
TypeError: 'bar' is a field but has no type annotation

Version info:

>>> python -V
Python 3.8.1
>>> pip freeze | grep -i cython

This comment has been minimized.

Copy link

@scoder scoder commented Jan 29, 2020

Isn't this just #2552? Did this ever work for you before? What does Foo.__annotations__ give?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.