This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Remove namedtuple 255 arguments restriction
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: giampaolo.rodola, pitrou, python-dev, r.david.murray, rhettinger, serhiy.storchaka, valorien
Priority: normal Keywords: patch

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

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:
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
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 (issue27095). 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.
msg283420 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-16 17:22
Thank you Raymond for your review.
Date User Action Args
2022-04-11 14:57:50adminsetgithub: 63096
2017-03-31 16:36:34dstufftsetpull_requests: + pull_request1075
2016-12-16 17:22:24serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg283420

stage: patch review -> resolved
2016-12-16 17:19:22python-devsetnosy: + python-dev
messages: + msg283419
2016-12-15 05:19:41rhettingersetmessages: + msg283242
2016-12-14 20:30:50serhiy.storchakasetassignee: serhiy.storchaka
2016-11-28 10:22:52serhiy.storchakasetfiles: + no-params-limit.patch

components: + Interpreter Core
versions: + Python 3.7, - Python 3.4
keywords: + patch
nosy: + serhiy.storchaka

messages: + msg281854
stage: patch review
2013-09-07 05:58:52terry.reedysetversions: + Python 3.4, - Python 3.3
2013-09-01 05:02:31rhettingersetmessages: + msg196704
2013-09-01 04:07:14r.david.murraysetnosy: + r.david.murray
2013-08-31 19:33:38valoriensetmessages: + msg196667
2013-08-31 18:49:56pitrousetnosy: + rhettinger, pitrou
messages: + msg196664
2013-08-31 18:47:20giampaolo.rodolasetnosy: + giampaolo.rodola
2013-08-31 18:05:10valoriencreate