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

Guido van Rossum guido at python.org
Sat Sep 18 02:16:39 CEST 2010


On Fri, Sep 17, 2010 at 1:00 PM, Raymond Hettinger
<raymond.hettinger at gmail.com> 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.

+256 on removing this limit from the language.

I've come across code generators that produced quite insane-looking
code that worked perfectly fine because Python's grammar has no (or
very large) limits, and I consider this a language feature. I've also
written code where there was a good reason to use **kwds in the
function definition and another good reason to pass **kwds to the call
where the kwds passed could be huge.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list