I've got the following Python code:
def GF(p, m=1):
    # Yeah, I know this should be a metaclass, but I can't find a good tutorial on them
    q = p ** m
    class _element:
        p = p
        m = m
        q = q
        def __init__(self, value):
            self.value = value
        def __repr__(self):
            return 'GF(%i, %i)(%i)' % (self.p, self.m, self.value)
        ...
    return _element
The problem here is with the line p = p: the left side "binds" p to the class' definition, preventing it from pulling in p from the locals.
One fix I can see is hacking around the variable names to fit:
def GF(p, m=1):
    q = p ** m
    _p, _m, _q = p, m, q
    class _element:
        p = _p
        m = _m
        q = _q
        def __init__(self, value):
            self.value = value
        def __repr__(self):
            return 'GF(%i, %i)(%i)' % (self.p, self.m, self.value)
        ...
    return _element
Is there a more recognized or stable way to do this?
 
    