classification
Title: Keyword only argument default values are evaluated before other defaults
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.2
process
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 2013-02-10 14:48 by python-dev. This issue is now closed.

Messages (5)
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) Date: 2013-02-10 14:32
New changeset d296cf1600a8 by Benjamin Peterson in branch 'default':
evaluate positional defaults before keyword-only defaults (closes #16967)
http://hg.python.org/cpython/rev/d296cf1600a8
msg181809 - (view) Author: Roundup Robot (python-dev) 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)
http://hg.python.org/cpython/rev/6917402c6191
History
Date User Action Args
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