Issue 18896: Remove namedtuple 255 arguments restriction (original) (raw)

Created on 2013-08-31 18:05 by valorien, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
no-params-limit.patch serhiy.storchaka,2016-11-28 10:22 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft,2017-03-31 16:36
Messages (8)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2016-12-15 05:19
Thanks. The patch looks good.
msg283419 - (view) Author: Roundup Robot (python-dev) (Python triager) 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) * (Python committer) Date: 2016-12-16 17:22
Thank you Raymond for your review.
History
Date User Action Args
2022-04-11 14:57:50 admin set github: 63096
2017-03-31 16:36:34 dstufft set pull_requests: + <pull%5Frequest1075>
2016-12-16 17:22:24 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2016-12-16 17:19:22 python-dev set nosy: + python-devmessages: +
2016-12-15 05:19:41 rhettinger set messages: +
2016-12-14 20:30:50 serhiy.storchaka set assignee: serhiy.storchaka
2016-11-28 10:22:52 serhiy.storchaka set files: + no-params-limit.patchcomponents: + Interpreter Coreversions: + Python 3.7, - Python 3.4keywords: + patchnosy: + serhiy.storchakamessages: + stage: patch review
2013-09-07 05:58:52 terry.reedy set versions: + Python 3.4, - Python 3.3
2013-09-01 05:02:31 rhettinger set messages: +
2013-09-01 04:07:14 r.david.murray set nosy: + r.david.murray
2013-08-31 19:33:38 valorien set messages: +
2013-08-31 18:49:56 pitrou set nosy: + rhettinger, pitroumessages: +
2013-08-31 18:47:20 giampaolo.rodola set nosy: + giampaolo.rodola
2013-08-31 18:05:10 valorien create