Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword only argument default values are evaluated before other defaults #61171

Closed
kayhayen mannequin opened this issue Jan 14, 2013 · 6 comments
Closed

Keyword only argument default values are evaluated before other defaults #61171

kayhayen mannequin opened this issue Jan 14, 2013 · 6 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@kayhayen
Copy link
Mannequin

kayhayen mannequin commented Jan 14, 2013

BPO 16967
Nosy @birkenfeld, @ncoghlan, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/benjaminp'
closed_at = <Date 2013-02-10.14:32:36.689>
created_at = <Date 2013-01-14.19:37:14.319>
labels = ['interpreter-core']
title = 'Keyword only argument default values are evaluated before other defaults'
updated_at = <Date 2014-06-21.04:10:09.514>
user = 'https://bugs.python.org/KayHayen'

bugs.python.org fields:

activity = <Date 2014-06-21.04:10:09.514>
actor = 'Kay.Hayen'
assignee = 'benjamin.peterson'
closed = True
closed_date = <Date 2013-02-10.14:32:36.689>
closer = 'python-dev'
components = ['Interpreter Core']
creation = <Date 2013-01-14.19:37:14.319>
creator = 'Kay.Hayen'
dependencies = []
files = []
hgrepos = []
issue_num = 16967
keywords = []
message_count = 6.0
messages = ['179970', '179972', '181783', '181808', '181809', '221151']
nosy_count = 6.0
nosy_names = ['georg.brandl', 'ncoghlan', 'benjamin.peterson', 'Arfrever', 'python-dev', 'Kay.Hayen']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue16967'
versions = ['Python 3.2']

@kayhayen
Copy link
Mannequin Author

kayhayen mannequin commented Jan 14, 2013

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.

@kayhayen kayhayen mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 14, 2013
@birkenfeld
Copy link
Member

Looks like a bug to me, although it isn't likely to cause great harm.

@birkenfeld birkenfeld changed the title Keyword keyword only default parameters are evaluated before po Keyword only argument default values are evaluated before other defaults Jan 14, 2013
@ncoghlan
Copy link
Contributor

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.

@benjaminp benjaminp self-assigned this Feb 10, 2013
@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 10, 2013

New changeset d296cf1600a8 by Benjamin Peterson in branch 'default':
evaluate positional defaults before keyword-only defaults (closes bpo-16967)
http://hg.python.org/cpython/rev/d296cf1600a8

@python-dev python-dev mannequin closed this as completed Feb 10, 2013
@python-dev
Copy link
Mannequin

python-dev mannequin commented Feb 10, 2013

New changeset 6917402c6191 by Benjamin Peterson in branch 'default':
evaluate lambda keyword-only defaults after positional defaults (bpo-16967 again)
http://hg.python.org/cpython/rev/6917402c6191

@kayhayen
Copy link
Mannequin Author

kayhayen mannequin commented Jun 21, 2014

I can confirm that Python3.4 is not affected. Python 3.3 and 3.2 still are.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

3 participants