Re: comments and the continuation prompt

2017-06-26 Thread Chris Angelico
On Mon, Jun 26, 2017 at 10:53 PM, Steve D'Aprano
 wrote:
> - Jython 2.5 doesn't do this:
>
 # comment

>
> - Neither does bpython.
>
> - I no longer have IronPython installed on any of my systems, so I can't check
> that, or PyPy.

PyPy doesn't, fwiw.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: comments and the continuation prompt

2017-06-26 Thread Steve D'Aprano
On Mon, 26 Jun 2017 01:32 pm, Ben Finney wrote:

> Steve D'Aprano  writes:
> 
>> On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote:
>>
>> >   According to The Python Language Reference Release 3.6.0, 2.1.3
>> >   Comments, »A comment signifies the end of the logical line unless
>> >   the implicit line joining rules are invoked.«.
>> > 
>> >   So, why do I get a continuation prompt when I enter a comment?
>>
>> Why not? As far as the interactive interpreter is concerned, you
>> haven't yet entered a statement.
> 
> And yet, according to the Language Reference, the logical line has ended
> and another begun.

Correct. That doesn't contradict anything I said.


> So I think the question is worth exploring: Why does the interactive
> prompt imply the logical line is continuing, when the Language Reference
> would say otherwise?

What leads you to believe that the prompt implies the logical line is
continuing? That's not implied by the prompt. I gave examples where the
secondary prompt is displayed that have nothing to do with logical lines:

py> def func():
... x = 1
... y = 2
...


That's not one logical line, and the presence of the secondary prompt ps2 does
not imply that it is.

The same applies to class, try, for, while, with, triple-quoted strings, and
possibly others. So why are we (by which I mean *not me*) thinking that the ps2
secondary prompt implies a single logical line?

All logical line continuations are displayed with the secondary prompt. This
does not imply that every time the secondary prompt is displayed, the line is
being continued.

Analogy: all people called "Ben" are human beings, but not all human beings are
called "Ben".

There is no puzzle here. The secondary prompt displayed after a comment is a
quirk of the CPython REPL, it isn't part of the language and it doesn't need to
be fixed because it isn't broken.

- IDLE doesn't do this.

- IPython doesn't do this:

In [1]: #comment

In [2]:


- Jython 2.5 doesn't do this:

>>> # comment
>>>

- Neither does bpython.

- I no longer have IronPython installed on any of my systems, so I can't check
that, or PyPy.

- The emulated REPL provided by the `code` module doesn't do it either:

py> import code
py> code.interact()
Python 3.5.2 (default, Oct 12 2016, 10:47:40)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
py> # comment
py>



It's a quirk of the CPython default REPL, of no consequence and with no
implications, and it especially has nothing to do with line continuations.


> Maybe the answer is “the continuation prompt does not prompt for the
> continuation of a logical line, 

Sometimes it does.


> but the continuation of ”.
> 
> What exactly goes in the “” placeholder; that is,
> exactly what should the user understand by that transition from one
> prompt to a different one?

A nested block; a triple-quoted string; a line continuation; a statement after a
comment; whatever reasonable thing a REPL chooses.

The language does not, so far as I am aware, mandate when the ps1 and ps2
prompts are used, and there is no basis for drawing any conclusion about the
Python language from the choices made by any specific REPL -- not even the
default CPython REPL.

https://docs.python.org/3/library/sys.html#sys.ps1




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: comments and the continuation prompt

2017-06-26 Thread Terry Reedy

On 6/25/2017 11:32 PM, Ben Finney wrote:

Steve D'Aprano  writes:


On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote:


   According to The Python Language Reference Release 3.6.0, 2.1.3
   Comments, »A comment signifies the end of the logical line unless
   the implicit line joining rules are invoked.«.

   So, why do I get a continuation prompt when I enter a comment?


In IDLE, you don't.

>>> #
>>> #sjflksj
>>>

Maybe this was once true for the interactive interpreter and changed. 
Or maybe this is buglet in IDLE in terms of imitating the console 
interpreter.  I have no idea.



Why not? As far as the interactive interpreter is concerned, you
haven't yet entered a statement.


And yet, according to the Language Reference, the logical line has ended
and another begun.

So I think the question is worth exploring: Why does the interactive
prompt imply the logical line is continuing, when the Language Reference
would say otherwise?

Maybe the answer is “the continuation prompt does not prompt for the
continuation of a logical line, but the continuation of ”.

What exactly goes in the “” placeholder; that is,
exactly what should the user understand by that transition from one
prompt to a different one?


Look into the behavior of compile('code', 'fake', 'single').


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: comments and the continuation prompt

2017-06-25 Thread Ben Finney
Steve D'Aprano  writes:

> On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote:
>
> >   According to The Python Language Reference Release 3.6.0, 2.1.3
> >   Comments, »A comment signifies the end of the logical line unless
> >   the implicit line joining rules are invoked.«.
> > 
> >   So, why do I get a continuation prompt when I enter a comment?
>
> Why not? As far as the interactive interpreter is concerned, you
> haven't yet entered a statement.

And yet, according to the Language Reference, the logical line has ended
and another begun.

So I think the question is worth exploring: Why does the interactive
prompt imply the logical line is continuing, when the Language Reference
would say otherwise?

Maybe the answer is “the continuation prompt does not prompt for the
continuation of a logical line, but the continuation of ”.

What exactly goes in the “” placeholder; that is,
exactly what should the user understand by that transition from one
prompt to a different one?

-- 
 \   “Philosophy is questions that may never be answered. Religion |
  `\  is answers that may never be questioned.” —anonymous |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: comments and the continuation prompt

2017-06-25 Thread Steve D'Aprano
On Mon, 26 Jun 2017 08:44 am, Stefan Ram wrote:

>   When I enter »12\«, I get a continuation prompt in the
>   Python 3.6 console:
> 
 12\
> ...
> 
>   . I thought that this might indicate that the logical line
>   is not terminated yet.

No. You get the level 2 prompt (sys.ps2) for a number of reasons:

- after statements that require a block (def, class, if, while, for, 
  with, try, and any others I have missed);

- in triple-quoted strings;

- bracketed expressions which haven't been closed yet ( [ { 

- after comments.

 
>   According to The Python Language Reference Release 3.6.0,
>   2.1.3 Comments, »A comment signifies the end of the logical
>   line unless the implicit line joining rules are invoked.«.
> 
>   So, why do I get a continuation prompt when I enter a comment?

Why not? As far as the interactive interpreter is concerned, you haven't yet
entered a statement.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list