The following code (not directly in an interpreter, but execute as file)
def top(deck):
pass
def b():
global deck
produces the error
SyntaxError: name 'deck' is local and global
on python2.6.4 and
SyntaxError: name 'deck' is parameter and global
on python 3.1
python2.4 seems to accept this code, so does the 2.6.4 interactive interpreter.
This is already odd; why is 'deck' conflicting if it's a global in one method and a parameter in the other?
But it gets weirder. Rename 'top' to basically anything else, and the problem disappears.
Can someone explain this behaviour? I feel like I'm missing something very obvious here. Is the name 'top' somehow affecting certain scoping internals?
Update
This indeed appears to be a bug in the python core. I have filed a bug report.
print top
yields "name 'top' is not defined", so at least it's not a function or something. Odd. – Davidb
first, thentop
). – Davidb
is part of the function body oftop
(i.e. that the parameter and the global are in the same scope). – Davidtop
that triggers the bug? For the record,id
andhash
of top don't look odd (3074663844=0xb74465a4, -1220303452=-0x48bb9a5c) – David