[Python-ideas] Null coalescing operators

Matthias Bussonnier bussonniermatthias at gmail.com
Tue Sep 22 05:21:49 CEST 2015

Hi Stephen, 

Thanks for the response and the time you took to investigate, 

> On Sep 21, 2015, at 19:34, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> But the syntax is extremely restrictive.  Both "None? 1 + 2" and
> "None ?" are SyntaxErrors, as are "a?.attr" and even "*int*? ".
> Prefixing the help operator also gives help, and in that case
> whitespace may separate the operator from the word (apparently defined
> as non-whitespace, and any trailing detritus is ignored).  Perhaps the
> prefix form (a little less natural for people coming directly from
> natural languages, I guess) should be emphasized -- there are no
> proposals for unary prefix use of "?" or "??”.

Yes I’m not worrying for the time being, the current syntax proposal does not conflict, 
and I just wanted to describe a few usage and reference to consideration in the PEP.
I prefer to give the PEP authors all the cards so that they can work out  a proposal
that fits majority of the people. 

I don’t want to let people write a pep, go through iteration and once they are
happy with it complain that it does not fit my needs. 

> So, this is the kind of DWIM that I doubt will confuse many users, at
> least not for very long.

I do not think we are in contact with the same users. 
Yes, I see users confused by % syntax, just last Thursday,
amy neighbor reported my that IPython was printing only for element of tuple,
but was working for list:

In [1]: print((1))
In [2]: print([1])

Yes people do get confused for %magics, vs modulo  vs %-format, 
less because module is number, % for strings. But it gets betterwith time.

>  Do you envision a problem keeping IPython
> facilities separate from Python language syntax?  Technically, I think
> the current rules that divide valid IPython requests for help from
> Python syntax (valid or invalid) should continue to work.

For no with current proposal, no no problem to keep them separate.

>  Whether it
> would confuse users, I doubt, but there are possible surprises for
> some (many?) users, I suppose.

I can see the Python `??`/`?` vs IPython `?`/`??` being one explicit point in
our docs/teaching/tutorial. I cannot say how much confusion this will 
be into our user head, I think the greater confusion will be the double 
meaning plus the fact that’s a Python 3.6+ only feature. So I doubt it will
be taught before a few years. Though it is still another small difficulty. 

I guess we will start to get this king of experience with 3.5 now that 
@ is there both for decorator and __matmul__ (thanks for 3.5 in general BTW) 

> Definitely, it should be mentioned in the PEP,


> but Python syntax is
> something that Python defines; shells and language variants have to be
> prepared to deal with Python syntax changes.

Yes, we are prepared, but our user don’t always understand :-)

I’m wondering if there wouldn’t be a way for interpreter
to a actually help Python beta-test some syntax changes, 
at least at the REPL level. Like website do user testing. 

>> leading the casual user thinking that this is a Python feature.
> Casual users actually expect software to DWIM in my experience.  The
> rule "leading help or stuck-right-on-the-end help works, elsewhere it
> means something else" (including no meaning == SyntaxError) is
> intuitively understood by them already, I'm sure.  Also, I rather
> doubt that "casual users" will encounter "?." or "??" until they're
> not so casual anymore.

In my domain people get confronted to advance syntax really rapidly, 
one feedback that I have for such weird syntax, especially when you 
are new to python, is that you don’t even now how to Google for this
kind of thing (especially for non english speaker). 

Trying to put a name on *arg and **kwarg is hard, google is starting to get better, 
but still ignore chars like ?,+,-

The google search for `Python` and `Python ??` seem to be identical.

>> As someone that have to regularly teach Python, and interact with
>> new Python users, it will be hard to explain that `?` and `??` have
>> different meaning depending on the context,
> I've never had a question about the context-sensitivity of "%" in
> IPython.  Have you?

Cf above yes, but more form the side where people don’t
get what modulo mean, but fair enough it was non native english, 
and they were confused by indent/implement/increment being roughly
the same word with 3 completely different meaning.

Though the number of people I see using modulo is low,
then they use numpy.mod on arrays once we get to numerics.
And in string formatting  we push for .format(*args, **kwargs).

But I’ll try to gather some statistics around. 

>> and that most book on Scientific Python are wrong/inaccurate.
> I'm afraid that's Scientific Python's cross to bear, not Python's.
>> It will be even harder if we have to remove the usage of
>> `?`/`??`[4].
> Not to worry about that.  IPython can define its own syntax for
> parsing out help requests vs. Python syntax.  I doubt you'll have to
> modify the current rules in any way.

I hope that won’t change in the final PEP, and I’m not too worry, 
worse case we use more reg-ex, and shift the problem elsewhere :-) 

>> I also want to note that the use of `?`/`??` is not present to just
>> being or end of identifiers as it can also be used use to search
>> for names:
>>> In [1]: *int*?
> But again "*int* ?" is a SyntaxError.  This is the kind of thing most
> casual users can easily work with.  (At least speakers of American
> English.  In email text, my Indian students love to separate trailing
> punctuation from the preceding word for some reason, but they would
> certainly learn quickly that you can't do that in IPython.)

French also separate punctuation, I’m still torn on that.
But if we have to slightly change the rules, so be it. 

> Again, I agree it would be useful to mention this in the PEP, but as
> far as I can see there really isn't a conflict.

Happy you agree on point 1, and that you confirm point 2.

> The main thing I'd
> want to know to convince me there's a risk would be if a lot of users
> are confused by "%quickref" (an IPython command) vs. "3 % 2" (a Python
> expression).

Will try to get more qualitative info. 


More information about the Python-ideas mailing list