[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-14 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-14 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset de2aea0ff02fa9486365ce9d215bef150fae3a0b by Pablo Galindo in 
branch 'master':
bpo-34939: Allow annotated global names in module namespace (GH-9844)
https://github.com/python/cpython/commit/de2aea0ff02fa9486365ce9d215bef150fae3a0b


--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-13 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch
pull_requests: +9217
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-11 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

I think we can just go ahead and allow this. If there is a volunteer, please go 
ahead, otherwise I will try to find time for this myself.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-09 Thread Rohan Padhye


Rohan Padhye  added the comment:

Another point I'd like to make is that there is no error in either file or 
interactive if the annotated assignment appears before the `global` declaration 
like so:

```
x:int = 0

def set_x():
global x
x = 1

# Works fine!
```

The syntax error specifically occurs when the annotated assignment occurs after 
a `global` declaration in the program, even if the assignment is in a different 
scope.

Neither the docs nor the PEP say anything about such an ordering constraint.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

This looks similar to say

x = 1
global x

It is an error in a file, but is not an error in interactive mode.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-09 Thread Guido van Rossum


Guido van Rossum  added the comment:

I agree with Ivan.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-09 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

Hm, I think this should be allowed. The formulation in the docs is not very 
clear, but the wording in the PEP clarifies the intention. Indeed, only 
annotations at the same scope with global declarations should be prohibited.

So I think this is a bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-09 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

The error message was added with 6cff8744a0ae58c88728df8bbca4580ffa6c6a86 and 
issue27999. The docs were also changed as below with the commit : 

https://docs.python.org/3.8/reference/simple_stmts.html#the-global-statement

> Names listed in a global statement must not be defined as formal parameters 
> or in a for loop control target, class definition, function definition, 
> import statement, or variable annotation.


Thanks

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-08 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +gvanrossum, levkivskyi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34939] Possibly spurious SyntaxError: annotated name can't be global

2018-10-08 Thread Rohan Padhye


New submission from Rohan Padhye :

The following code when run as a script file gives syntax error:

```
def set_x():
global x
x = 1

x:int = 0   # SyntaxError: annotated name 'x' can't be global
```

PEP 526 does not seem to forbid this. The error message "annotated name [...] 
can't be global" is usually seen when using the `global x` declaration *in the 
same scope* as an annotated assignment. In the above case, the annotated 
assignment is outside the function scope, yet Python 3.7 gives a syntax error.


Is this a bug in CPython? Or should the PEP 526 document say something about 
forward references?

Interestingly, if the above program is run in interactive mode, there is no 
syntax error. 

In interactive mode:
```
>>> def set_x():
... global x
... x = 1
... 
>>> x:int = 0
>>> set_x()
>>> print(x)
1
```

Further, forward references work fine with `nonlocal`. For example, the 
following works fine both as a script file and in interactive mode:
```
def outer():
def inner():
nonlocal y
y = 1
y:int = 0
```

I don't see why a forward reference in `global` is a problem.

--
components: Interpreter Core
messages: 327378
nosy: rohanpadhye
priority: normal
severity: normal
status: open
title: Possibly spurious SyntaxError: annotated name can't be global
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com