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

Cesare Di Mauro cesare.di.mauro at gmail.com
Sun Oct 24 08:31:04 CEST 2010

2010/10/24 Greg Ewing <greg.ewing at canterbury.ac.nz>

> Cesare Di Mauro wrote:
>> I think that having max 255 args and 255 kwargs is a good and reasonable
>> limit which we can live on, and helps the virtual machine implementation
> Is there any corresponding limit to the number of arguments to
>  tuple and dict constructor?

AFAIK there's no such limit. However, I'll use BUILD_TUPLE and BUILD_MAP
opcodes for such purpose, because they are faster.

> If not, the limit could perhaps be
> circumvented without changing the VM by having the compiler
> convert calls with large numbers of args into code that builds
> an appropriate tuple and dict and makes a *args/**kwds call.
> --
> Greg

I greatly prefer this solution, but it's a bit more complicated when there
are *arg and/or **kwargs special arguments.

If we have > 255 args and *args is defined, we need to:
1) emit BUILD_TUPLE after pushed the regular arguments
2) emit LOAD_GLOBAL("tuple")
3) push *args
4) emit CALL_FUNCTION(1) to convert *args to a tuple
5) emit BINARY_ADD to append *args to the regular arguments

If we have > 255 kwargs and **kwargs defined, we need to:
1) emit BUILD_MAP after pushed the regular keyword arguments
2) emit LOAD_ATTR("update")
3) push **kwargs
4) emit CALL_FUNCTION(1) to update the regular keyword arguments with the
ones in **kwargs

And, finally, combining all the above in the worst case.

But, as I said, I prefer this one to handle "complex" cases instead of
changing the VM slowing the common ones.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20101024/5cc5c547/attachment.html>

More information about the Python-ideas mailing list