[Python-ideas] New 3.x restriction on number of keyword arguments

Raymond Hettinger raymond.hettinger at gmail.com
Fri Sep 17 22:00:08 CEST 2010

One of the use cases for named tuples is to have them be automatically created from a SQL query or CSV header.  Sometimes (but not often), those can have a huge number of columns.  In Python 2.x, it worked just fine -- we had a test for a named tuple with 5000 fields.  In Python 3.x, there is a SyntaxError when there are more than 255 fields.

The origin of the change was a hack to fit positional argument counts and keyword-only argument counts in a single oparg in the python opcode encoding.

ISTM, this is an implementation specific hack and there is no reason that other implementations would have the same restriction (unless their starting point is Python's bytecode).  

The good news is that long argument lists are uncommon.  They probably only arise in cases with dynamically created functions and classes.  Most people are unaffected.

The bad news is that an implementation detail has become visible and added a language restriction.  The 255 limit seems weird to me in a version of Python that has gone to lengths to unify ints and longs so that char/short/long boundaries stop manifesting themselves to users.

Is there any support here for trying to get smarter about the keyword-only argument implementation?  The 255 limit does not seem unreasonably low, but then it was once thought that no one would ever need more that 640k of ram.  If the new restriction isn't necessary, it would be great to remove it.


More information about the Python-ideas mailing list