[issue9226] erroneous behavior when creating classes inside a closure

2021-12-01 Thread Irit Katriel
Irit Katriel added the comment: Reproduced on 3.11. -- nosy: +iritkatriel versions: +Python 3.10, Python 3.11, Python 3.9 -Python 2.6, Python 2.7, Python 3.1, Python 3.2 ___ Python tracker __

[issue9226] erroneous behavior when creating classes inside a closure

2018-07-25 Thread Tal Einat
Tal Einat added the comment: See additional discussion in the duplicate issue19979. -- nosy: +taleinat ___ Python tracker ___ ___ Py

[issue9226] erroneous behavior when creating classes inside a closure

2012-11-07 Thread Nick Coghlan
Changes by Nick Coghlan : -- nosy: +ncoghlan ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Guido van Rossum
Guido van Rossum added the comment: On Sat, Jul 24, 2010 at 3:21 PM, Terry J. Reedy wrote: > > Terry J. Reedy added the comment: > > Guido clarified: >> Class scopes *do* behave differently from function scopes; >> outside a nested function, this should work: >> x = 1 >> class C(object): >>  

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Terry J. Reedy
Terry J. Reedy added the comment: Guido clarified: > Class scopes *do* behave differently from function scopes; > outside a nested function, this should work: > x = 1 > class C(object): > x = x > assert C.x == 1 > And I think it should work that way inside a function too. I take that to mean

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Guido van Rossum
Guido van Rossum added the comment: I meant, of course, assert C.x == 1 -- ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Guido van Rossum
Guido van Rossum added the comment: Hm. This seems an old bug, probably introduced when closures where first introduced (2.1 ISTR, by Jeremy Hylton). Class scopes *do* behave differently from function scopes; outside a nested function, this should work: x = 1 class C(object): x = x assert

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-23 Thread Terry J. Reedy
Terry J. Reedy added the comment: Chris, when posting something like this, *please* include the output. I had to insert ()s to run this with 3.1. I will upload the py3 version as test3.py. Is your output the same as mine? x: success Test.x: error Test2.y: success Test3.x: error Test3.y: error

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Eric Smith
Changes by Eric Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Benjamin Peterson
Changes by Benjamin Peterson : Added file: http://bugs.python.org/file17954/obscure_corner_cases2.patch ___ Python tracker ___ ___ Python-bugs-

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Éric Araujo
Changes by Éric Araujo : -- nosy: +merwok ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Mark Dickinson added the comment: I think it would be worth bringing this up on python-dev, especially since it affects alternative Python implementations. It would also be good to have a documentation fix to the reference manual that clearly explains whatever behaviour is decided on; it's n

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Benjamin Peterson
Benjamin Peterson added the comment: Here's a patch. It raises a NameError in that case. -- keywords: +patch Added file: http://bugs.python.org/file17953/obscure_corner_cases.patch ___ Python tracker __

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread R. David Murray
R. David Murray added the comment: I agree with Mark, I'd expect an UnboundLocalError. I remembered this thread on Python-dev that may or may not be relevant, but is certainly analogous: http://www.mail-archive.com/python-...@python.org/msg37576.html -- nosy: +r.david.murray __

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Mark Dickinson added the comment: Jython 2.5.1 gives the same results as Python: newton:~ dickinsm$ cat test.py x = "error" def test(x): class Test(object): x = x print("x: ", x) print("Test.x: ", Test.x) test("success") newton:~ dickinsm$ jython2.5.1/jython test.py ('x: '

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Mark Dickinson added the comment: I don't see anything in http://docs.python.org/reference/executionmodel.html#naming-and-binding to suggest that the class should behave differently from a nested function here; that is, I'd expect UnboundLocalError. -- nosy: +mark.dickinson ___

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Benjamin Peterson
Benjamin Peterson added the comment: I'm not sure what I correct behavior is in this case. Consider the function equivalent: x = 3 def f(x): def m(): x = x print x m() f(4) which gives: Traceback (most recent call last): File "x.py", line 7, in f(4) File "x.p

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Changes by Mark Dickinson : -- components: +Interpreter Core stage: -> needs patch type: -> behavior versions: +Python 2.7, Python 3.2 ___ Python tracker ___ ___

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Chris Monsanto
Changes by Chris Monsanto : -- versions: +Python 2.6, Python 3.1 -3rd party ___ Python tracker ___ ___ Python-bugs-list mailing list Un

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Chris Monsanto
Chris Monsanto added the comment: A friend confirmed that this was the case on 3.1.2 as well. -- versions: +3rd party -Python 2.6 ___ Python tracker ___ _

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Chris Monsanto
New submission from Chris Monsanto : I have a function whose closure contains a local variable that shadows a global variable (lets call it x). If I create a class as follows: class Test(object): x = x Test.x will contain the value of the global x, not the local x. This ONLY happens when the