[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-10-01 Thread SP Praveen
Change by SP Praveen : -- components: +Tkinter -Interpreter Core type: enhancement -> crash versions: +Python 3.11 -Python 3.10 ___ Python tracker ___

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-09-30 Thread Josh Rosenberg
Josh Rosenberg added the comment: Aaron: Your understanding of how LEGB works in Python is a little off. Locals are locals for the *entire* scope of the function, bound or unbound; deleting them means they hold nothing (they're unbound) but del can't actually stop them from being locals.

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-09-30 Thread Aaron Smith
Aaron Smith added the comment: I encountered the similar behavior unexpectedly when dealing with LEGB scope of names. Take the following example run under Python 3.9.2: def doSomething(): x = 10 del x print(x) x = 5 doSomething() This produces a UnboundLocalError at print(x)

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-06-02 Thread Irit Katriel
Irit Katriel added the comment: Following a discussion on PR24976 we opted for "cannot access local variable 'x' where it is not associated with a value" This is because binding it not always related to assignment. I don't know whether this completely resolves this issue, or whether there

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-06-02 Thread Irit Katriel
Irit Katriel added the comment: New changeset 7b1f527d5b37dc3aa085ebbe11a1a2dd29ef210f by Irit Katriel in branch 'main': bpo-17792: more accurate error message for unbound variable access exceptions (GH-24976) https://github.com/python/cpython/commit/7b1f527d5b37dc3aa085ebbe11a1a2dd29ef210f

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-03-22 Thread Irit Katriel
Change by Irit Katriel : -- pull_requests: +23735 stage: -> patch review pull_request: https://github.com/python/cpython/pull/24976 ___ Python tracker ___

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-03-21 Thread pmp-p
Change by pmp-p : -- nosy: +pmpp ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2021-03-21 Thread Irit Katriel
Irit Katriel added the comment: I think the issue is that the error message for UnboundLocalError is wrong, see this example: >>> def g(): ...x = 42 ...del x ...print(x) ... >>> g() Traceback (most recent call last): File "", line 1, in File "", line 4, in g

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2017-03-21 Thread Ivan Levkivskyi
Changes by Ivan Levkivskyi : -- nosy: +levkivskyi ___ Python tracker ___ ___

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-07-05 Thread Christian Heimes
Changes by Christian Heimes li...@cheimes.de: -- nosy: +christian.heimes ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17792 ___ ___

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-05-30 Thread Phil Connell
Changes by Phil Connell pconn...@gmail.com: -- nosy: +pconnell ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17792 ___ ___ Python-bugs-list

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-05-30 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17792 ___

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-23 Thread Ezio Melotti
Ezio Melotti added the comment: Attached a new patch that improves the following things: * added some tests; * the code in the previous message is now handled correctly; * the patch now raises a proper SyntaxWarning; There are still several problems though: * it doesn't work for the global

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: - Using PyUnicode_FromFormat() works, but then I don't know how to convert the result to const char* PyUnicode_AsUTF8() -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-23 Thread Ezio Melotti
Ezio Melotti added the comment: I considered that, but is it guaranteed that the output encoding is UTF-8? What if the warning is printed on a Windows console that uses cp1252? I also considered encoding it and then use PyBytes_AsString, but I was hoping in something simpler (also I'm not

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I considered that, but is it guaranteed that the output encoding is UTF-8? PyErr_WarnExplicit() calls PyUnicode_FromString() which made an inverse decoding from UTF-8. -- ___ Python tracker

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-20 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: Ezio, the problem with your patch is that it also gives a warning on this code, which is totally safe: def good(): exc = None try: bar(int(sys.argv[1])) except KeyError as e: print('ke') exc = e except ValueError as e:

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-19 Thread Eric Snow
Eric Snow added the comment: FWIW this has come up before: http://mail.python.org/pipermail/python-dev/2012-October/122504.html and relatedly: issue16429 -- nosy: +eric.snow ___ Python tracker rep...@bugs.python.org

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Barry A. Warsaw
New submission from Barry A. Warsaw: As described here: http://www.wefearchange.org/2013/04/python-3-language-gotcha-and-short.html the following code will produce an UnboundLocalError when the exception is triggered: def bad(): e = None try: do_something() except

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Ezio Melotti
Ezio Melotti added the comment: Maybe we could raise a warning when the deleted name already exists in the local namespace? (FWIW I knew about the fact that the name gets deleted, and still managed to get bitten by it a couple of times.) -- nosy: +ezio.melotti

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Apr 19, 2013, at 12:01 AM, Ezio Melotti wrote: Maybe we could raise a warning when the deleted name already exists in the local namespace? Ideally, I think a SyntaxError if you could detect a previously bound name in the namespace being used as an

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread R. David Murray
R. David Murray added the comment: And what if it weren't a print statement? An error is better than a randomly changed value, I think. I'm really not sure there is anything we can do here, beyond Ezio's warning suggestion. -- nosy: +r.david.murray

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread R. David Murray
R. David Murray added the comment: This used to raise a SyntaxError. See issue 4617. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17792 ___

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Apr 19, 2013, at 12:37 AM, R. David Murray wrote: And what if it weren't a print statement? An error is better than a randomly changed value, I think. I'm really not sure there is anything we can do here, beyond Ezio's warning suggestion. Right. The

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Nick Coghlan
Nick Coghlan added the comment: It seems to me that this kind of dubious-but-legal code is what http://docs.python.org/3/library/exceptions.html#SyntaxWarning is designed to handle. Something like SyntaxWarning: implicitly deleted exception variable referenced after end of except clause.

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread R. David Murray
R. David Murray added the comment: It occurs to me that one of the problems here is that the UnboundLocalError only occurs when the except clause is executed. Do you think it would be helpful and acceptable (in 3.4, as it is a behavior change) to have the 'as' variable *always* deleted at

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Nick Coghlan
Nick Coghlan added the comment: I don't think we want to mess with the control flow, as that would be even weirder and may interact strangely with else and finally clauses. A SyntaxWarning would be unconditional (so it doesn't matter whether or not the exception is triggered at run time),

[issue17792] Unhelpful UnboundLocalError due to del'ing of exception target

2013-04-18 Thread Ezio Melotti
Ezio Melotti added the comment: Attached a sketchy proof of concept. It only checks for locals, but it should probably check for globals too. Does the approach make sense? -- keywords: +patch nosy: +benjamin.peterson type: - enhancement Added file: