[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 ___ ___

[issue9226] erroneous behavior when creating classes inside a closure

2012-11-07 Thread Nick Coghlan
Changes by Nick Coghlan ncogh...@gmail.com: -- nosy: +ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9226 ___ ___ Python-bugs-list mailing

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Guido van Rossum
Guido van Rossum gu...@python.org 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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Guido van Rossum
Guido van Rossum gu...@python.org added the comment: I meant, of course, assert C.x == 1 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9226 ___

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Terry J. Reedy
Terry J. Reedy tjre...@udel.edu 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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-24 Thread Guido van Rossum
Guido van Rossum gu...@python.org added the comment: On Sat, Jul 24, 2010 at 3:21 PM, Terry J. Reedy rep...@bugs.python.org wrote: Terry J. Reedy tjre...@udel.edu added the comment: Guido clarified: Class scopes *do* behave differently from function scopes; outside a nested function, this

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-23 Thread Terry J. Reedy
Terry J. Reedy tjre...@udel.edu 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:

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Chris Monsanto
New submission from Chris Monsanto ch...@monsan.to: 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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Chris Monsanto
Chris Monsanto ch...@monsan.to 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 rep...@bugs.python.org http://bugs.python.org/issue9226

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Chris Monsanto
Changes by Chris Monsanto ch...@monsan.to: -- versions: +Python 2.6, Python 3.1 -3rd party ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9226 ___

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Changes by Mark Dickinson dicki...@gmail.com: -- components: +Interpreter Core stage: - needs patch type: - behavior versions: +Python 2.7, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9226

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org 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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com 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:

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com 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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread R. David Murray
R. David Murray rdmur...@bitdance.com 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:

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org 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 rep...@bugs.python.org

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com 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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Éric Araujo
Changes by Éric Araujo mer...@netwok.org: -- nosy: +merwok ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9226 ___ ___ Python-bugs-list mailing

[issue9226] erroneous behavior when creating classes inside a closure

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

[issue9226] erroneous behavior when creating classes inside a closure

2010-07-11 Thread Eric Smith
Changes by Eric Smith e...@trueblade.com: -- nosy: +eric.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9226 ___ ___ Python-bugs-list mailing