UnboundLocalError in oneOf() on Python 3.4 (easy fix)
Brought to you by:
ptmcg
In Python 3.4, this kind of code is invalid (see, official docs for a full explanation: https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value). See also: http://gis.stackexchange.com/questions/61241/unboundlocalerror-local-variable-referenced-before-assignment.
if isinstance(strs,basestring): symbols = strs.split() elif isinstance(strs, collections.Sequence): symbols = list(strs[:]) elif isinstance(strs, _generatorType): symbols = list(strs) else: warnings.warn("Invalid argument to oneOf, expected string or list", SyntaxWarning, stacklevel=2) i = 0
while i < len(symbols)-1:E UnboundLocalError: local variable 'symbols' referenced before assignment
In fact, "symbols" may not get assigned at all (in the "else" case). It would be probably sufficient to just add "symbols = []" before the if block.
Fix checked into SVN, will include in next release
Thanks, I'll make your suggested change and check it in to SVN.
-- Paul
From: aldanor [mailto:aldanor@users.sf.net]
Sent: Saturday, June 28, 2014 7:42 AM
To: Ticket 74
Subject: [pyparsing:bugs] #74 UnboundLocalError in oneOf() on Python 3.4
(easy fix)
[bugs:#74] http://sourceforge.net/p/pyparsing/bugs/74/ UnboundLocalError
in oneOf() on Python 3.4 (easy fix)
Status: open
Group: v1.0 (example)
Created: Sat Jun 28, 2014 12:42 PM UTC by aldanor
Last Updated: Sat Jun 28, 2014 12:42 PM UTC
Owner: Paul McGuire
In Python 3.4, this kind of code is invalid (see, official docs for a full
explanation:
https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlo
calerror-when-the-variable-has-a-value). See also:
http://gis.stackexchange.com/questions/61241/unboundlocalerror-local-variabl
e-referenced-before-assignment.
while i < len(symbols)-1:
E UnboundLocalError: local variable 'symbols' referenced before assignment
In fact, "symbols" may not get assigned at all (in the "else" case). It
would be probably sufficient to just add "symbols = []" before the if block.
Sent from sourceforge.net because you indicated interest in
https://sourceforge.net/p/pyparsing/bugs/74/
To unsubscribe from further messages, please visit
https://sourceforge.net/auth/subscriptions/
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
Related
Bugs:
#74