[Cython] Class scope lookup order
Vitja Makarov
vitja.makarov at gmail.com
Mon Aug 15 07:49:54 CEST 2011
2011/8/15 Vitja Makarov <vitja.makarov at gmail.com>:
> When creating python-class dict it seems that CPython first looks at
> dict then at globals:
>
> A = 1
> class X:
> A = A
>
> def y():
> A = 3
> class Y:
> A = A
> return Y
> Y = y()
>
> print(X.A, Y.A)
>
> Will print: 1, 1
> And not: 1, 3
>
> I didn't find documentation for this but if I'm correct that should be
> easy to fix issue in Cython.
>
> Now for this code cython reports compile-time error: local variable
> referenced before assignment
>
>
One more interesting example:
A = 1
def foo(a):
A = a
class X:
a = A
A = A
class Y:
a = A
return X, Y
X, Y = foo(666)
print X.a, X.A, Y.a
--
vitja.
More information about the cython-devel
mailing list