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: Backport of PEP 3102 "keyword-only arguments" to 2.6
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, benjamin.peterson, christian.heimes, eric.araujo, eric.smith, georg.brandl, gsakkis, gvanrossum, michael.foord, robin.stocker, tav
Priority: normal Keywords: patch

Created on 2008-01-06 16:04 by robin.stocker, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
backport-keyword-only-arguments.patch robin.stocker, 2008-01-06 16:04 backport of PEP 3102
backport-keyword-only-arguments-full.patch robin.stocker, 2008-01-08 21:27 also includes changes after r52491
backport-keyword-only-arguments-full-2.patch robin.stocker, 2008-03-23 14:52 applies cleanly again
backport-keyword-only-arguments-full-3.patch gsakkis, 2010-03-22 01:21 Applies cleanly on r79264
Messages (21)
msg59391 - (view) Author: Robin Stocker (robin.stocker) Date: 2008-01-06 16:03
The attached patch ports the implementation of keyword-only arguments
from revision 52491 back to trunk.

This is the first time I've worked on the C internals, so here are some

- test_collections is the only test which fails, because it tries to
call a function with more than 255 arguments, which results in a
SyntaxError because of the following added code in Python/ast.c. What
should be done about it?

    if (nposargs + nkwonlyargs > 255) {
        ast_error(n, "more than 255 arguments");
        return NULL;

- The patch only adds what's in revision 52491. There is at least one
more change involving keyword-only arguments, for example issue1573. Are
there others? Should they be included in this patch or in a separate one?

- There are some changes which were generated, like Python/Python-ast.c
(which needs to be checked in separately).

- Is there documentation which needs to be updated?
msg59406 - (view) Author: Robin Stocker (robin.stocker) Date: 2008-01-06 21:24
Another note: Because the marshalling of code objects is changed, is
there a version number of the format which has to be incremented?
msg59430 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-07 04:22
Thanks for tackling this!

What line in is calling a function with >255 args? 
I'm a bit surprised since this has always been disallowed AFAICT.

I'd like to see everything related to keyword-only args included in one
patch.  Hopefully the unittests and/or svn history will give you an idea
of what to do.

There should be docs in the reference manual.  Maybe Georg knows where.

Don't worry about the generated Python-ast.c patch.

The version number you're looking for is MAGIC in Python/import.c.
msg59469 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-07 17:28
Keyword-only-args are not yet documented.
msg59515 - (view) Author: Robin Stocker (robin.stocker) Date: 2008-01-08 01:31
Thanks for the feedback!

It's on line 111 in

        n = 10000
        import string, random
        names = [''.join([random.choice(string.letters) for j in
range(10)]) for i in range(n)]
        Big = namedtuple('Big', names)
        b = Big(*range(n))

I think the condition is triggered because Big's __new__ (which seems to
be dynamically generated by namedtuple using exec) has an argument list
with 10000 arguments.

Ok, I'm now looking through SVN logs and have already added some more
changes to my patchset.

Thanks, I had changed MAGIC but didn't know that marshal.c uses it.

So I won't handle documentation in this issue then.
msg59521 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-08 03:55
I vaguely remember that I had to modify the tests to use 254 args in
Python 3.0.
msg59523 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-08 05:01
There's something I misunderstand then.  I thought 2.x also didn't
accept >255 args, but that test would seem to prove I'm wrong.
msg59561 - (view) Author: Robin Stocker (robin.stocker) Date: 2008-01-08 21:25
Guido: The check was only done for call nodes, not for function definitions.
msg59562 - (view) Author: Robin Stocker (robin.stocker) Date: 2008-01-08 21:27
Ok, I checked all the logs and updated the patch. test_collections uses
n = 254 now and all tests pass.

I left revision 54043 out on purpose, because it fixes Lib/
and Lib/ for both PEP 3102 and 3107, so it should be included in
the patch for PEP 3107.
msg64366 - (view) Author: Robin Stocker (robin.stocker) Date: 2008-03-23 14:52
I've updated the patch to apply cleanly again.
msg64665 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-29 01:25
Bumping priority.
msg65249 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2008-04-09 18:07
The patch doesn't apply cleanly for me.  I can fix the non-clean patch,
but another error is that obj2ast_arguments doesn't call arguments()
with the correct parameters.  If I pass in NULL's for the new params,
all tests pass, but that just tells me it's not being tested thoroughly.

I'll spend some time looking at it, but if anyone else wants to look at
it, go ahead.
msg70360 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-28 17:03
This will probably have to be deferred to 2.7.
msg70687 - (view) Author: tav (tav) Date: 2008-08-04 07:35
What's holding back the backport to 2.6?
msg70739 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-05 14:18
On Mon, Aug 4, 2008 at 1:35 AM, tav <> wrote:
> tav <> added the comment:
> What's holding back the backport to 2.6?

The fact that we are working towards the 3rd and final beta.
> ----------
> nosy: +tav
> _______________________________________
> Python tracker <>
> <>
> _______________________________________

Benjamin Peterson
"There's no place like"
msg71654 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-08-21 16:11
This will definitely not be in 2.6.
msg85345 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-03 23:55
Running out of time for 2.7 as well...
msg85348 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-04-03 23:58
2009/4/3 Michael Foord <>:
> Michael Foord <> added the comment:
> Running out of time for 2.7 as well...

How so? The first 2.7 alpha probably won't be until the end of summer.
msg101435 - (view) Author: George Sakkis (gsakkis) Date: 2010-03-21 17:36
Is there any update on this for 2.7 ?
msg101475 - (view) Author: George Sakkis (gsakkis) Date: 2010-03-22 01:21
FWIW I updated the patch to r79264; it applies cleanly and passes the tests but other than that I can't tell if it's ready. It would be nice to have it in 2.7 though.
msg109435 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2010-07-06 22:23
Now, that 2.7 is out we won't able to commit this anymore. It is sad to abandon a good patch like this.
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46086
2010-07-06 22:23:31alexandre.vassalottisetstatus: open -> closed
resolution: wont fix
messages: + msg109435

stage: patch review -> resolved
2010-03-22 01:21:57gsakkissetfiles: + backport-keyword-only-arguments-full-3.patch

messages: + msg101475
2010-03-21 17:36:01gsakkissetnosy: + gsakkis
messages: + msg101435
2010-02-13 17:25:36alexandre.vassalottisetmessages: - msg99320
2010-02-13 15:57:39alexandre.vassalottisetmessages: + msg99320
2009-09-27 15:09:51eric.araujosetnosy: + eric.araujo
2009-08-06 02:33:30alexandre.vassalottisetnosy: + alexandre.vassalotti

stage: patch review
2009-04-03 23:58:17benjamin.petersonsetmessages: + msg85348
2009-04-03 23:55:32michael.foordsetnosy: + michael.foord
messages: + msg85345
2009-01-17 16:28:46benjamin.petersonsetpriority: critical -> normal
2008-08-21 16:11:45gvanrossumsetkeywords: - 26backport
messages: + msg71654
2008-08-21 14:26:03benjamin.petersonsetversions: + Python 2.7, - Python 2.6
2008-08-05 14:18:38benjamin.petersonsetmessages: + msg70739
2008-08-04 07:35:36tavsetnosy: + tav
messages: + msg70687
2008-07-28 17:03:20benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg70360
2008-04-09 18:07:40eric.smithsetmessages: + msg65249
2008-03-29 01:26:00georg.brandllinkissue2327 superseder
2008-03-29 01:25:49georg.brandlsetpriority: normal -> critical
keywords: + 26backport
messages: + msg64665
2008-03-23 14:52:20robin.stockersetfiles: + backport-keyword-only-arguments-full-2.patch
messages: + msg64366
2008-03-18 17:23:47eric.smithsetnosy: + eric.smith
2008-01-08 21:27:59robin.stockersetfiles: + backport-keyword-only-arguments-full.patch
messages: + msg59562
2008-01-08 21:25:35robin.stockersetmessages: + msg59561
2008-01-08 05:01:32gvanrossumsetmessages: + msg59523
2008-01-08 03:55:17christian.heimessetpriority: normal
nosy: + christian.heimes
messages: + msg59521
2008-01-08 01:31:09robin.stockersetmessages: + msg59515
2008-01-07 17:28:04georg.brandlsetmessages: + msg59469
2008-01-07 04:22:59gvanrossumsetkeywords: + patch
2008-01-07 04:22:52gvanrossumsetnosy: + gvanrossum, georg.brandl
messages: + msg59430
2008-01-06 21:24:52robin.stockersetmessages: + msg59406
2008-01-06 16:04:01robin.stockercreate