ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Cannot create a dataclass with more than 255 fields #134

Closed jbasko closed 6 years ago

jbasko commented 6 years ago

In Python 3.6.6 (the only one I've tried), when I declare a dataclass with more than 255 fields, I am getting the 255 arguments error:

....
File "...../python3.6/site-packages/dataclasses.py", line 871, in _process_class
    else 'self',
File "...../python3.6/site-packages/dataclasses.py", line 490, in _init_fn
    return_type=None)
File "...../python3.6/site-packages/dataclasses.py", line 356, in _create_fn
    exec(txt, globals, locals)
File "<string>", line 1
SyntaxError: more than 255 arguments

Not sure if it's worth "fixing" this :)

ericvsmith commented 6 years ago

This is a Python limitation, not one imposed by dataclasses. There's nothing dataclasses can do to work around it, short of *args, which defeats the whole point of dataclasses!

ericvsmith commented 6 years ago

It looks like this restriction has been removed in python 3.8. At least, a quick test shows a __init__ with 260 parameters doesn't fail in 3.8 (master), while it does in 3.6. I don't have a 3.7 handy.

jbasko commented 6 years ago

I wouldn’t expect it to be fixed as it would make the code probably much slower for normal use cases, but don’t necessarily agree with *args and **kwargs beating the purpose of dataclasses because who said a dataclass-using code cannot be generated (which is where I hit this) :)