Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Nature, to be commanded, must be obeyed. -- Francis Bacon


devel / comp.lang.python / Where is the error?

SubjectAuthor
o Where is the error?Peter J. Holzer

1
Where is the error?

<mailman.214.1691355048.23016.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23855&group=comp.lang.python#23855

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Where is the error?
Date: Sun, 6 Aug 2023 22:41:51 +0200
Lines: 81
Message-ID: <mailman.214.1691355048.23016.python-list@python.org>
References: <20230806204151.rvaspz6iu4w3w5db@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="psytoclz3uvxybed"
X-Trace: news.uni-berlin.de x0gFg5lFq+/8BR5YnohteAtWUEbOvzNKffE8lCSVCO1g==
Cancel-Lock: sha1:bwtEPFEsmyj2bUxbOaUHEixlyqo= sha256:+SI9TQHpzlKAG5Ls5RIKamzmoDW3p2ekCH1vO29iSWM=
Return-Path: <hjp-python@hjp.at>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'content-
type:multipart/signed': 0.05; 'subject:error': 0.07; 'better,':
0.09; 'content-type:application/pgp-signature': 0.09;
'expression': 0.09; 'filename:fname piece:asc': 0.09;
'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'syntax': 0.15; 'that.':
0.15; '"creative': 0.16; '3.10': 0.16; '3.9': 0.16; '__/': 0.16;
'behaviour': 0.16; 'challenge!"': 0.16; 'decision?': 0.16;
'from:addr:hjp-python': 0.16; 'from:addr:hjp.at': 0.16;
'from:name:peter j. holzer': 0.16; 'great,': 0.16; 'hjp@hjp.at':
0.16; 'holzer': 0.16; 'mostly,': 0.16; 'reality.': 0.16; 'side-
effect': 0.16; 'stross,': 0.16; 'syntax.': 0.16; 'syntaxerror:':
0.16; 'url-ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16;
'url:hjp': 0.16; 'useless': 0.16; '|_|_)': 0.16; 'python': 0.16;
'to:addr:python-list': 0.20; 'languages': 0.22; 'lines': 0.23;
'(and': 0.25; 'programming': 0.25; "isn't": 0.27; 'bit': 0.27;
'fact': 0.28; 'sense': 0.28; 'error': 0.29; 'program': 0.31;
'but': 0.32; 'there': 0.33; 'skip:" 20': 0.34; 'invalid': 0.35;
'close': 0.35; 'missing': 0.37; "it's": 0.37; 'file': 0.38; 'me.':
0.62; 'received:212': 0.62; 'experience': 0.64; 'received:userid':
0.66; 'url-ip:212/8': 0.69; 'took': 0.69; 'longer': 0.71; 'head':
0.73; 'easy': 0.74; 'points': 0.84; 'earlier)': 0.84; 'forgot':
0.84; 'received:at': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20230806204151.rvaspz6iu4w3w5db@hjp.at>
 by: Peter J. Holzer - Sun, 6 Aug 2023 20:41 UTC
Attachments: signature.asc (application/pgp-signature)

Mostly, error messages got a lot better in Python 3.10, but this one had
me scratching my head for a few minutes.

Consider this useless and faulty script:

------------------------------------------------------------------------
r = {
"x": (1 + 2 + 3)
"y": (4 + 5 + 6)
"z": (7 + 8 + 9)
} ------------------------------------------------------------------------

Python 3.9 (and earlier) reports:

------------------------------------------------------------------------
File "/home/hjp/tmp/foo", line 3
"y": (4 + 5 + 6)
^
SyntaxError: invalid syntax
------------------------------------------------------------------------

This isn't great, but experience with lots of programming languages
tells me that an error is noticed where or after it actually occurs, so
it's easy to see that there is a comma missing just before the "y".

Python 3.10 and 3.11 report:

------------------------------------------------------------------------
File "/home/hjp/tmp/foo", line 2
"x": (1 + 2 + 3)
^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
------------------------------------------------------------------------

The error message is now a lot better, of course, but the fact that it
points at the expression *before* the error completely threw me. The
underlined expression is clearly not missing a comma, nor is there an
error before that. My real program was a bit longer of course, so I
checked the lines before that to see if I forgot to close any
parentheses. Took me some time to notice the missing comma *after* the
underlined expression.

Is this "clairvoyant" behaviour a side-effect of the new parser or was
that a deliberate decision?

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor