Classes lack __annotations__ (PEP-526)
See original GitHub issueWith python 3.7 dataclasses were introduced. They work just fine in Cython except for their standard init function.
How to reproduce: test.pyx
from dataclasses import dataclass
@dataclass
class TestClass:
x: int
y: int
some_string: str
This file compiles to Cython code just fine. However, when ran from the python it raises an error: test2.py
import test
test_class = test.TestClass(1, 2, 'string')
This raises the following:
Traceback (most recent call last):
File ".\test2.py", line 3, in <module>
test_class = test.TestClass(1, 2, 'string')
TypeError: __init__() takes 1 positional argument but 4 were given
if you rename test.pyx to test.py and do not compile it, no such error occurs.
my current workaround: setting each property after initialization separately: test.pyx remains unchanged. test.py
import test
test_class = test.TestClass()
test_class.x = 1
test_class.y = 2
test_class.some_string = 'string'
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:24 (16 by maintainers)
Top Results From Across the Web
PEP 526 – Syntax for Variable Annotations
This PEP aims at adding syntax to Python for annotating the types of variables (including class variables and instance variables), instead of expressing ......
Read more >[Python-Dev] Please reject or postpone PEP 526
Hi everyone, I think we should reject, or at least postpone PEP 526. PEP 526 represents a major change to the language, however...
Read more >What are variable annotations? - python
Taken from PEP 526 -- Syntax for Variable Annotations, Python will remain a dynamically typed language, and the authors have no desire to...
Read more >PEP-526 ready for review: Syntax for Variable and Attribute ...
Actually, the main benefit that I personally think variable annotations can bring isn't actually articulated very well in the PEP, imo -- I ......
Read more >Dataclasses without type annotations - death and gravity
PEP 526 : (my definition) Titled "Syntax for Variable Annotations", ... @dataclass class Hell: one: "starting with Python 3.10", two: it(s=not ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
awesome news that this is implemented 🎉 thanks a lot
thanks for the quick reply. i will try to get some proper time to work on this. in the meantime i have tried a little workaround:
this seems to work properly. is this what you meant by "get away with building the dict in Python and adding it to the class dict "?