On Tue, Nov 9, 2021 at 6:31 AM Steven D'Aprano <st...@pearwood.info> wrote:

> By the way, this discussion is probably better suited to the
> Python-Ideas mailing list. But since we're here...
>
> On Tue, Nov 09, 2021 at 11:37:40AM +0100, Sebastian Rittau wrote:
>
> > >>To me, the "natural" solution looks like this:
> > >>
> > >>def foo(x=None, y): ...
> [...]
>
> Chris Angelico asked:
> > >What would this mean, though:
> > >
> > >foo(2)
> > >
> > >Is that legal?
> >
> > No. This would be equal to foo(x=2) (same as now), meaning the required
> > argument "y" is missing.
>
> That's an odd interpretation. What you described earlier is very similar
> to the calling convention of range, which conceptually looks like this:
>
>     range([start=0,] end, [step=1])
>
> With your example of "foo(x=None, y)" I would expect foo(2) to mean that
> x gets the default and y gets the passed in argument 2, similar to the
> way that range(2) works.
>

But we all understand range() because we have been using it for years and
there's a mathematical understanding of what it represents. If you were
taught "range(2, 5) returns the numbers 2 through 5, exclusive" and then
were asked, "what does range(2) do?", I'm not sure what a beginner would
assume, but thinking it goes from 5 to infinity wouldn't be an unreasonable
leap to make.

An API like range() is also not pervasive, so it can be supported without
any special parameter support and not feel icky; `def range(x, y=None, z=1,
/)` covers its unique situation.

But for me, the key issue is simply remembering what one argument means
compares to two. foo(1) versus foo(1, 2) is not self-documenting whether
that `1` in the first call would get bound to the same thing as the `1` in
the second call. I would need to have quite the understanding of the API to
know that without having to look something up in the docs. But the current
semantics don't have this issue, and `1` means the same thing in both
scenarios (unless you're doing something really weird like range(), which
is something I wouldn't want to encourage).
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/I52V5QLMNR5OUGRUEPX4S6WDCYUF3X2L/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to