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: Keyword only argument default values are evaluated before other defaults
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: Arfrever, Kay.Hayen, benjamin.peterson, georg.brandl, ncoghlan, python-dev
Priority: normal Keywords:

Created on 2013-01-14 19:37 by Kay.Hayen, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg179970 - (view) Author: Kay Hayen (Kay.Hayen) Date: 2013-01-14 19:37
Suprisingly, keyword only arguments become evaluated first:

>>> def f(a=undefined1,*,b=undefined2):pass
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'undefined2' is not defined

It should be "undefined1".

I am sure, this is going to surprise developers and breaks assumptions, people tend to make. So far (to my knowledge) nothing that was separated by a "," could be evaluated in a mixed order.

Please consider to change this around.
msg179972 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-01-14 19:47
Looks like a bug to me, although it isn't likely to cause great harm.
msg181783 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-02-10 10:29
Agreed on it being a bug that we do it the wrong way around, but "Yikes!" at the idea of code where it makes a significant difference.
msg181808 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-10 14:32
New changeset d296cf1600a8 by Benjamin Peterson in branch 'default':
evaluate positional defaults before keyword-only defaults (closes #16967)
msg181809 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-10 14:48
New changeset 6917402c6191 by Benjamin Peterson in branch 'default':
evaluate lambda keyword-only defaults after positional defaults (#16967 again)
msg221151 - (view) Author: Kay Hayen (Kay.Hayen) Date: 2014-06-21 04:10
I can confirm that Python3.4 is not affected. Python 3.3 and 3.2 still are.
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61171
2014-06-21 04:10:09Kay.Hayensetmessages: + msg221151
2013-02-10 14:48:29python-devsetmessages: + msg181809
2013-02-10 14:32:36python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg181808

resolution: fixed
stage: resolved
2013-02-10 14:21:31benjamin.petersonsetassignee: benjamin.peterson

nosy: + benjamin.peterson
2013-02-10 10:29:40ncoghlansetnosy: + ncoghlan
messages: + msg181783
2013-01-14 22:42:43Arfreversetnosy: + Arfrever
2013-01-14 19:47:51georg.brandlsetnosy: + georg.brandl

messages: + msg179972
title: Keyword keyword only default parameters are evaluated before po -> Keyword only argument default values are evaluated before other defaults
2013-01-14 19:37:14Kay.Hayencreate