Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First of all, do you really need to? Just allow any input, if it does not have the methods you are calling then you will get a suitable AttributeError exception thrown. AKA duck-typing.

If you are sure that you actually have to check the type, use the convenience functions:

sage: from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
sage: is_PolynomialRing('string')
False
sage: from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
sage: is_MPolynomialRing('string')                                              
False