Re: Problem/bug with class definition inside function definition

2018-05-08 Thread Gregory Ewing
Alexey Muranov wrote: x = 42 class C: x = x # Works I'd say it kind of works by accident, and is not really an intended feature. if Python does not allow to refer "simultaneously" to variables from different scopes if they have the same name. It seems perfectly reasonable to

Re: Problem/bug with class definition inside function definition

2018-05-08 Thread Ned Batchelder
On 5/8/18 3:55 AM, Alexey Muranov wrote: Sorry, i was confused.  I would say that this mostly works as expected, though the difference between    x = 42    class C:    x = x  # Works and    def f2(a):    class D:    a = a  # Does not work <    return D is still surpr

Re: Problem/bug with class definition inside function definition

2018-05-08 Thread Alexey Muranov
Sorry, i was confused. I would say that this mostly works as expected, though the difference between x = 42 class C: x = x # Works and def f2(a): class D: a = a # Does not work < return D is still surprising to me. Otherwise, probably the solu

Re: Problem/bug with class definition inside function definition

2018-05-07 Thread Gregory Ewing
Python 3.5.1 (default, Jun 1 2016, 13:15:26) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def f(a): ... class D: ... pass ... D.a = a ... return D ... >>> c = f(42) >>> c .D'> >>> c.a 42 -- Greg -- https://mail.pyth

Re: Problem/bug with class definition inside function definition

2018-05-07 Thread Alexey Muranov
To be more exact, i do see a few workarounds, for example: def f4(a): b = a class D: a = b # Works return D But this is not what i was hoping for. Alexey. On Tue, 8 May, 2018 at 12:02 AM, Alexey Muranov wrote: I have discovered the following bug or proble

Problem/bug with class definition inside function definition

2018-05-07 Thread Alexey Muranov
I have discovered the following bug or problem: it looks like i am forced to choose different names for class attributes and function arguments, and i see no workaround. Am i missing some special syntax feature ? Alexey. --- x = 42 class C1: y = x # Works class C2: x = x # Works #