>     open('example.txt', encoding, newline, errors, mode)
>
>     open('example.txt', *, encoding, newline, errors, mode)
>
> Would you agree that the two of those have *radically* different
> meanings? The first will, if you are lucky, fail immediately; the second
> may succeed. But to the poor unfortunate reader who doesn't know what
> the star does, the difference is puzzling.
>
> This holds even more strongly if the various parameters take the same
> type:
>
>     # a real signature from one of my functions
>     def function(
>            meta:bool,
>            dunder:bool,
>            private:bool,
>            ignorecase:bool,
>            invert:bool)
>
>     function(dunder, invert, private, meta, ignorecase)
>     function(*, dunder, invert, private, meta, ignorecase)
>



>
> [...]
> > > Have I missed something?
> > >
> >
> > Something weird seems to have happened in this thread. Rodrigo first
> > proposed the magic asterisk syntax here:
> >
> https://mail.python.org/archives/list/[email protected]/message/N2ZY5NQ5T2OJRSUGZJOANEQOGEQIYYIK/
>
> Ah, that's the bit I missed.
>

I missed that message too.

But even having missed the original proposal, it was immediately obvious to
me what the code was saying with very little intro from Alex Hall, because
of its similarity to keyword-only function definition syntax. It feels like
the meaning is obvious.

However I'll agree with Steve D' that it could easily lead to some
confusing reading. The example I quoted above is compelling.

At first I was tempted to say: "hey now! That code was written in a puppet
obfuscatory way! Why would someone change the order of the arguments like
that?"

But the answer came to me: because of the proposed syntax I am feeling very
free to just splatter all the arguments the function asked for in any
order-- I'm not going to scroll up to read the docs to mimic the safe order
especially if the parameters are keyword only.

But this means the reader could miss the star, especially with a very large
function call over multiple lines, and if that reader happens to use that
particular function A LOT and know the parameter order without having to
look they would pretty easily believe the arguments are doing something
different than what is actually happening.

It's an interesting problem with the syntax. I'm not sure if it moves me in
the negative on the proposal or not.

>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/SENUXW35VEVP5MOYTROG7MYIKLJFJH52/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to