Usually it's typical to have a "minimal working example", so that we don't need your extra functions.
There are two problems here. First, even if the error you got was avoided, you'd get this one.
def test():
res = ['x1','x2']
A.<res> = BooleanPolynomialRing(len(res))
return A
....:
sage: test()
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<snip>
IndexError: the number of names must equal the number of generators
This is because Sage preparses the invalid Python A.<res> ...
into something else that is valid.
sage: preparse("A.<res> = BooleanPolynomialRing(len(res))")
"A = BooleanPolynomialRing(len(res), names=('res',)); (res,) = A._first_ngens(1)"
This also causes your issue:
sage: res = ['x','y']
sage: A.<res> = BooleanPolynomialRing(len(res))
<snip>
ValueError: variable names must be alphanumeric, but one is 'res[Integer(1)]' which is not.
and I don't see an easy way around it with this syntax. However,
sage: res = [2,['x','y']]
sage: A = BooleanPolynomialRing(names=res[1])
sage: A
Boolean PolynomialRing in x, y
seems like it should do the job. See
sage: BooleanPolynomialRing?
for more info.