[Python-Dev] Order of positional and keyword arguments (original) (raw)
Chris Jerdonek chris.jerdonek at gmail.com
Fri Apr 27 05:46:27 EDT 2018
- Previous message (by thread): [Python-Dev] Order of positional and keyword arguments
- Next message (by thread): [Python-Dev] Order of positional and keyword arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Apr 26, 2018 at 12:25 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
f(b=2, *[1]) is surprised in two ways:
1. Argument values are passed not in order. The first value is assigned to the second parameter, and the second value is assigned to the first parameter. 2. Argument values are evaluated not from left to right. This contradicts the general rule that expressions are evaluated from left to right (with few known exceptions). I never seen the form
f(b=2, *[1])
in practice (though the language reference contains an explicit example for it), and it looks weird to me. I don't see reasons of writingf(b=2, *[1])
instead of more naturalf(*[1],_ _b=2)
. I propose to disallow it.
Coincidentally, I recently came across and reviewed a PR to Django that proposed exactly this, or at least something very similar. They proposed changing--
def create_cursor(self, name=None):
to-- def create_cursor(self, name=None, *args, **kwargs):
https://github.com/django/django/pull/9674/files#diff-53fcf3ac0535307033e0cfabb85c5301R173
--Chris
This will also make the grammar simpler. Current grammar: argumentlist:
positionalarguments
[","starredandkeywords
] : [","keywordsarguments
] : |starredandkeywords
[","keywordsarguments
] : |keywordsarguments
positionalarguments: [""]expression
("," [""]expression
)* starredandkeywords: ("*"expression
|keyworditem
) : ("," ""expression
| ","keyworditem
) keywordsarguments: (keyworditem
| "**"expression
) : (","keyworditem
| "," "**"expression
)* keyworditem:identifier
"="expression
Proposed grammar: argumentlist:positionalarguments
[","keywordsarguments
] : |keywordsarguments
positionalarguments: [""]expression
("," [""]expression
)* keywordsarguments:keywordargument
(","keywordargument
)* keywordargument:identifier
"="expression
| "**"expression
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/chris.jerdonek%40gmail.com
- Previous message (by thread): [Python-Dev] Order of positional and keyword arguments
- Next message (by thread): [Python-Dev] Order of positional and keyword arguments
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]