[Cython] Class scope lookup order
Vitja Makarov
vitja.makarov at gmail.com
Mon Aug 15 11:55:38 CEST 2011
2011/8/15 Stefan Behnel <stefan_ml at behnel.de>:
> Stefan Behnel, 15.08.2011 11:34:
>>
>> at least to me, the most surprising thing is this:
>>
>> >>> A = 1
>> >>> def foo(x):
>> ... A = x
>> ... class X:
>> ... a = A
>> ... return X
>> ...
>> >>> foo(2).a
>> 2
>> >>> def foo(x):
>> ... A = x
>> ... class X:
>> ... A = A
>> ... return X
>> ...
>> >>> foo(2).A
>> 1
>>
>> That looks pretty sick, but I would guess that the 'reasoning' behind this
>> is that the second case contains an assignment to A inside of the class
>> namespace, and assignments make a variable local to a scope, in this case,
>> the function scope.
>
> Argh, sorry, I interpreted the results the wrong way around. No, I have no
> idea for a serious explanation. Let's see what c.l.py brings up.
>
I've tried emulate this behaviour in cython here:
https://github.com/vitek/cython/commit/26ec702fd93fb6dc2109a501b52130e5f775c793
Actually I think this is made to support assignments like A = A in class scope.
--
vitja.
More information about the cython-devel
mailing list