(original) (raw)
Christian,
When I wrote this, my intention was like: cur & DEF\_LOCAL is a "more serious" error, so that if both errors are made in the same statement:def f():
x: int = 5--
On 12 September 2016 at 11:37, Christian Heimes <christian@python.org> wrote:
On 2016-09-09 18:53, guido.van.rossum wrote:
\> https://hg.python.org/cpython/rev/804b71d43c85
\> changeset: 103415:804b71d43c85
\> user: Guido van Rossum <guido@dropbox.com>
\> date: Fri Sep 09 09:36:26 2016 -0700
\> summary:
\> Issue #27999: Make "global after use" a SyntaxError, and ditto for nonlocal.
\> Patch by Ivan Levkivskyi.
\>
\> files:
\> Doc/reference/simple\_stmts.rst | 5 +-
\> Lib/test/test\_syntax.py | 18 +++-
\> Misc/NEWS | 3 +
\> Python/symtable.c | 104 +++++++-------------
\> 4 files changed, 59 insertions(+), 71 deletions(-)
\>
\[...\]
\> @@ -1337,31 +1313,23 @@
\> long cur = symtable\_lookup(st, name);
\> if (cur < 0)
\> VISIT\_QUIT(st, 0);
\> - if (cur & DEF\_ANNOT) {
\> - PyErr\_Format(PyExc\_SyntaxError,
\> - "annotated name '%U' can't be nonlocal",
\> - name);
\> + if (cur & (DEF\_LOCAL | USE | DEF\_ANNOT)) {
\> + char\* msg;
\> + if (cur & DEF\_ANNOT) {
\> + msg = NONLOCAL\_ANNOT;
\> + }
\> + if (cur & DEF\_LOCAL) {
\> + msg = NONLOCAL\_AFTER\_ASSIGN;
\> + }
\> + else {
\> + msg = NONLOCAL\_AFTER\_USE;
\> + }
\> + PyErr\_Format(PyExc\_SyntaxError, msg, name);
Hi Guido,
did you mean if / else if / else here? It's not completely clear if the
code means to set msg a second time if both cur & DEF\_ANNOT and cur &
DEF\_LOCAL are true.
Christian
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/ levkivskyi%40gmail.com