`if not eq.is_polynomial():` should be dedented. If I understand correctly, you need to check all input, not only input that is an Expr.

So

```
try:
    eq = Poly(eq).as_expr()
    if eq.is_number:
        raise TypeError
except TypeError, GeneratorsNeeded:
    raise TypeError('equation should contain free_symbols')
except PolynomialError:
    raise TypeError('equation should be a polynomial')
```