Strange error, possibly related to var
class CTest(object):
def __init__(self,arg=None):
var('x,y')
if type(arg) is list:
print [x in ZZ for x in arg]
elif arg in PolynomialRing(ZZ,2,(x,y)):
pass
a=CTest()
Traceback (most recent call last):
...
File "", line 6, in __init__
UnboundLocalError: local variable 'x' referenced before assignment
Replacing var('x,y') with x,y=var('x,y') eliminates the error. So does replacing PolynomialRing(ZZ,2,(x,y)) with [1,2,3]. Or changing the x in [x in ZZ for x in arg] to z.
I believe this is Python local versus global variable thing. `var('x y')` injects `x` and `y` into the "global namespace", but Python considers all variables talked about inside a function to be "local", even if they have the same names. (This is good or bad, depending on whom you ask.) But I couldn't isolate the exact problem either, frustrating. Maybe this will help anyway?