'Converts ``self`` to a polynomial or returns ``None``.
>>> from sympy import sin
>>> from sympy.abc import x, y
>>> print((x**2 + x*y).as_poly())
Poly(x**2 + x*y, x, y, domain=\'ZZ\')
>>> print((x**2 + x*y).as_poly(x, y))
Poly(x**2 + x*y, x, y, domain=\'ZZ\')
>>> print((x**2 + sin(y)).as_poly(x, y))
None'

def as_poly(self, *gens, **args):

    from sympy.polys import Poly, PolynomialError
    try:
        poly = Poly(self, *gens, **args)
        if (not poly.is_Poly):
            return None
        else:
            return poly
    except PolynomialError:
        return None
