[issue16429] Emit SyntaxWarning for code that risks UnboundLocalError

2012-11-07 Thread Nick Coghlan

New submission from Nick Coghlan:

The compiler is actually in a fairly good position to tell when code is at risk 
of triggering UnboundLocalError at runtime: specifically, in the section of the 
code that checks for duplicated parameter names [1]

Now, we can't emit SyntaxError here for backwards compatibility reasons (if you 
have an early reference that is never executed, your code is dodgy but will 
still run OK).

However, we should be able to emit a Syntax *Warning* when we detect an 
existing symbol at function scope having DEF_LOCAL applied for the first time 
*after* it has already been referenced in a way which doesn't create a local 
variable.

Something like:

SyntaxWarning: Local variable NAME bound after earlier reference (risks 
UnboundLocalError when function is called)

[1] http://hg.python.org/cpython/file/default/Python/symtable.c#l1002

--
messages: 175107
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Emit SyntaxWarning for code that risks UnboundLocalError
versions: Python 3.4

___
Python tracker 

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



[issue16429] Emit SyntaxWarning for code that risks UnboundLocalError

2012-11-15 Thread Andrew Svetlov

Changes by Andrew Svetlov :


--
nosy: +asvetlov

___
Python tracker 

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



[issue16429] Emit SyntaxWarning for code that risks UnboundLocalError

2013-05-04 Thread Daniel Urban

Changes by Daniel Urban :


--
nosy: +daniel.urban

___
Python tracker 

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