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

MRAB python at mrabarnett.plus.com
Fri Sep 17 22:23:49 CEST 2010

On 17/09/2010 21:00, Raymond Hettinger wrote:
> 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.
Strings can be any length, lists can be any length, even the humble int
can be any length!

It does seem unPythonic to have a low limit like that.

I think that the implementation hack needs a bit of a rethink if that's
what it's causing, IMHO.

More information about the Python-ideas mailing list