Right, the typical Pythonic way to handle this situation is to raise
an exception. The most common exceptions for SymPy are
- TypeError: The input type does not make sense. This is the error
that likely makes sense for your example.
- ValueError: The input type is OK, but the value doesn't make sense.
The difference between ValueError and TypeError can sometimes be
subtle.
- NotImplementedError: The result should work, but it hasn't been
implemented yet.
- A custom exception: Many modules have custom exception subclasses
that are used in that module, like PolynomialError and MatrixError.
It's best to search the code you're changing to see if there are any
exception subclasses you should be using.
It's also worth keeping in mind with SymPy that there is a second way
of approaching this situation, which is to leave the expression
unevaluated. Or if the input makes no mathematical sense, returning
nan is also sometimes used.
I hope that helps. I can't say specifically what your code should do
without knowing more about what it is.
Aaron Meurer
>
https://groups.google.com/d/msgid/sympy/CAP7f1AjJJO0KQdvUkxePRuBMgN2FmOFviy6NRgz8LTyJ-PHqKw%40mail.gmail.com.