<div dir="ltr">It seems all the core devs who have commented on this are in the positive (Victor, Yury, Ethan, Yury, Guido, Terry, and Steven; MAL didn't explicitly vote). So to me that suggests there's enough support to warrant writing a PEP. Are you up for writing it, Victor, or is someone else going to write it?<div><br><div class="gmail_quote"><div dir="ltr">On Tue, 28 Feb 2017 at 13:18 Victor Stinner <<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="gmail_msg">
<br class="gmail_msg">
For technical reasons, many functions of the Python standard libraries<br class="gmail_msg">
implemented in C have positional-only parameters. Example:<br class="gmail_msg">
-------<br class="gmail_msg">
$ ./python<br class="gmail_msg">
Python 3.7.0a0 (default, Feb 25 2017, 04:30:32)<br class="gmail_msg">
>>> help(str.replace)<br class="gmail_msg">
replace(self, old, new, count=-1, /) # <== notice "/" at the end<br class="gmail_msg">
...<br class="gmail_msg">
>>> "a".replace("x", "y") # ok<br class="gmail_msg">
'a'<br class="gmail_msg">
<br class="gmail_msg">
>>> "a".replace(old="x", new="y") # ERR!<br class="gmail_msg">
TypeError: replace() takes at least 2 arguments (0 given)<br class="gmail_msg">
-------<br class="gmail_msg">
<br class="gmail_msg">
When converting the methods of the builtin str type to the internal<br class="gmail_msg">
"Argument Clinic" tool (tool to generate the function signature,<br class="gmail_msg">
function docstring and the code to parse arguments in C), I asked if<br class="gmail_msg">
we should add support for keyword arguments in str.replace(). The<br class="gmail_msg">
answer was quick: no! It's a deliberate design choice.<br class="gmail_msg">
<br class="gmail_msg">
Quote of Yury Selivanov's message:<br class="gmail_msg">
"""<br class="gmail_msg">
I think Guido explicitly stated that he doesn't like the idea to<br class="gmail_msg">
always allow keyword arguments for all methods. I.e. `str.find('aaa')`<br class="gmail_msg">
just reads better than `str.find(needle='aaa')`. Essentially, the idea<br class="gmail_msg">
is that for most of the builtins that accept one or two arguments,<br class="gmail_msg">
positional-only parameters are better.<br class="gmail_msg">
"""<br class="gmail_msg">
<a href="http://bugs.python.org/issue29286#msg285578" rel="noreferrer" class="gmail_msg" target="_blank">http://bugs.python.org/issue29286#msg285578</a><br class="gmail_msg">
<br class="gmail_msg">
I just noticed a module on PyPI to implement this behaviour on Python functions:<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://pypi.python.org/pypi/positional" rel="noreferrer" class="gmail_msg" target="_blank">https://pypi.python.org/pypi/positional</a><br class="gmail_msg">
<br class="gmail_msg">
My question is: would it make sense to implement this feature in<br class="gmail_msg">
Python directly? If yes, what should be the syntax? Use "/" marker?<br class="gmail_msg">
Use the @positional() decorator?<br class="gmail_msg">
<br class="gmail_msg">
Do you see concrete cases where it's a deliberate choice to deny<br class="gmail_msg">
passing arguments as keywords?<br class="gmail_msg">
<br class="gmail_msg">
Don't you like writing int(x="123") instead of int("123")? :-) (I know<br class="gmail_msg">
that Serhiy Storshake hates the name of the "x" parameter of the int<br class="gmail_msg">
constructor ;-))<br class="gmail_msg">
<br class="gmail_msg">
By the way, I read that "/" marker is unknown by almost all Python<br class="gmail_msg">
developers, and [...] syntax should be preferred, but<br class="gmail_msg">
inspect.signature() doesn't support this syntax. Maybe we should fix<br class="gmail_msg">
signature() and use [...] format instead?<br class="gmail_msg">
<br class="gmail_msg">
Replace "replace(self, old, new, count=-1, /)" with "replace(self,<br class="gmail_msg">
old, new[, count=-1])" (or maybe even not document the default<br class="gmail_msg">
value?).<br class="gmail_msg">
<br class="gmail_msg">
Python 3.5 help (docstring) uses "S.replace(old, new[, count])".<br class="gmail_msg">
<br class="gmail_msg">
Victor<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Python-ideas mailing list<br class="gmail_msg">
<a href="mailto:Python-ideas@python.org" class="gmail_msg" target="_blank">Python-ideas@python.org</a><br class="gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" class="gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br class="gmail_msg">
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" class="gmail_msg" target="_blank">http://python.org/psf/codeofconduct/</a><br class="gmail_msg">
</blockquote></div></div></div>