[Python-Dev] Inconsistent script/console behaviour

anatoly techtonik techtonik at gmail.com
Thu Dec 15 09:58:31 CET 2011


On Sat, Sep 24, 2011 at 11:27 AM, Georg Brandl <g.brandl at gmx.net> wrote:

> Am 24.09.2011 01:32, schrieb Guido van Rossum:
> > On Fri, Sep 23, 2011 at 4:25 PM, anatoly techtonik <techtonik at gmail.com>
> wrote:
> >> Currently if you work in console and define a function and then
> >> immediately call it - it will fail with SyntaxError.
> >> For example, copy paste this completely valid Python script into
> console:
> >>
> >> def some():
> >>  print "XXX"
> >> some()
> >>
> >> There is an issue for that that was just closed by Eric. However, I'd
> >> like to know if there are people here that agree that if you paste a
> >> valid Python script into console - it should work without changes.
> >
> > You can't fix this without completely changing the way the interactive
> > console treats blank lines. None that it's not just that a blank line
> > is required after a function definition -- you also *can't* have a
> > blank line *inside* a function definition.
>
> While the former could be changed (I think), the latter certainly cannot.
> So it's probably not worth changing established behavior.


I've just hit this UX bug once more, but now I more prepared. Despite
Guido's proposal to move into python-ideas, I continue discussion here,
because:

1. It is not a proposal, but a defect (well, you may argue, but please,
don't)
2. This thread has a history of analysis of what's going wrong in console
3. This thread also has developer's decision that answers the question
    "why it's so wrong?" and "why it can't/won't be fixed"
4. Yesterday I've heard from a Java person that Python is hard to pick up
    and remembered how I struggled with indentation myself trying to
    'learn by example' in console

Right now I am trying to cope with point (3.). To summarize, let's speak
code
that is copy/pasted into console. Two things that will make me happy if they
behave consistently in console from .py file:

---ex1---
def some():
    print "XXX"
some()
---/ex1---

--ex1.output--
[ex1.py]
XXX
[console]
  File "<stdin>", line 3
    some()
       ^
SyntaxError: invalid syntax
--/ex1.output--


--ex2--
def some():
pass
--/ex2--

--ex2.output--
[ex2.py]
  File "./ex2.py", line 2
    pass
       ^
IndentationError: expected an indented block
[console]
  File "<stdin>", line 2
    pass
       ^
IndentationError: expected an indented block
--/ex2.output--


The second example already works as expected. Why it is not possible to fix
ex1? Guido said:

> You can't fix this without completely changing the way the interactive
> console treats blank lines.

But the fix doesn't require changing the way interactive console treats
blank lines at all. It only requires to finish current block when a
dedented line is encountered and not throwing obviously confusing
SyntaxError. At the very least it should not say it is SyntaxError, because
the code is pretty valid Python code. If it appears to be invalid "Python
Console code" - the error message should say that explicitly. That would be
a correct user-friendly fix for this UX issue, but I'd still like the
behavior to be fixed - i.e. "allow dedented lines end current block in
console without SyntaxError". Right now I don't see the reasons why it is
not possible.

Please speak code when replying about use cases/examples that will be
broken - I didn't quite get the problem with "global scope if" statements.
-- 
anatoly t.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20111215/3c72d25e/attachment.html>


More information about the Python-Dev mailing list