msg196660 - (view) |
Author: Alori (valorien) |
Date: 2013-08-31 18:05 |
Named tuples offer a useful mix of features from both dict and tuple data structures. However, unlike dictionaries and tuples, Named tuples are only allowed to hold up to 255 items. This behavior seems inconsistent and un-Pythonic. Is there a way to remove this restriction? Why not set a much higher limit? Also see: http://grokbase.com/t/python/python-ideas/109hbv63sv/new-3-x-restriction-on-number-of-keyword-arguments#responses_tab_top http://stackoverflow.com/questions/18550270/any-way-to-bypass-namedtuple-255-arguments-limitation |
|
|
msg196664 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-08-31 18:49 |
I'll let Raymond give his answer here, but namedtuples are meant as lightweight structures or records (if you know C, think "struct"), not arbitrary containers. |
|
|
msg196667 - (view) |
Author: Alori (valorien) |
Date: 2013-08-31 19:33 |
@pitrou: Thank you for your answer. I agree they should not replace databases or files, but I think 255 is just way too lightweight. It feels unnatural to have this limitation for no specific reason. Recently, I've seen a lot of solutions that emulate the namedtuple functionality with some classes in order to workaround this issue, but they all feel "forced" and require some unsavory hacks. I think namedtuple is one the most useful structures in the language, and like tuples and dicts, shouldn't be limited by design. |
|
|
msg196704 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2013-09-01 05:02 |
I would like to see the limitation removed. IIRC, Guido has said the same. That said, the limitation isn't due to anything in the namedtuple code. Instead, it is due to a CPython bytecode implementation detail that limits all function/method definitions to no more than 255 arguments. |
|
|
msg281854 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-11-28 10:22 |
Currently it is not possible to declare a Python function with more than 255 parameters. There were two historical causes of this: 1. Opcodes MAKE_FUNCTION and MAKE_CLOSURE packed the number of default values for positional and keyword parameters in the opcode argument as 8-bit numbers. 2. co_cell2arg was of type "unsigned char *". It's mapped a cell index to an argument index and didn't support arguments with index > 254. The first limitation is disappeared in 3.6 after changing the format of MAKE_FUNCTION (). Proposed patch gets rid of the second cause by changing the type of co_cell2arg and removes explicit check in the compiler. |
|
|
msg283242 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2016-12-15 05:19 |
Thanks. The patch looks good. |
|
|
msg283419 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2016-12-16 17:19 |
New changeset 7454ca88aacb by Serhiy Storchaka in branch 'default': Issue #18896: Python function can now have more than 255 parameters. https://hg.python.org/cpython/rev/7454ca88aacb |
|
|
msg283420 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-12-16 17:22 |
Thank you Raymond for your review. |
|
|