Thanks very much. I imagine in these cases the ValueError would make most 
sense as, for example, we have to check that something is a natural number 
so we must check that it is whole and also that it is non-negative.

On Sunday, March 15, 2015 at 6:07:49 PM UTC, Aaron Meurer wrote:
>
> 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 
>
>
> On Sun, Mar 15, 2015 at 11:44 AM, Jason Moore <[email protected] 
> <javascript:>> wrote: 
> > It typically should raise an error. You can do something like `raise 
> > ValueError('Wrong input!')`. 
> > 
> > 
> > Jason 
> > moorepants.info 
> > +01 530-601-9791 
> > 
> > On Sun, Mar 15, 2015 at 6:38 AM, Jennifer White <[email protected] 
> <javascript:>> 
> > wrote: 
> >> 
> >> Hi, 
> >> I'm new to contributing to SymPy and I'm just starting with fixing some 
> >> simple little TODOs in the code. I'm currently working on some checks 
> that 
> >> are needed for polynomials (things like checking certain values are 
> >> integers). Before I went ahead and changed things I wanted to check: 
> what is 
> >> the preferred action of the code in the event where this condition 
> fails? 
> >> Should it just print out an error message? Return nothing from the 
> current 
> >> function? I just wondered what the standard handling of this was in 
> SymPy. 
> >> Thanks 
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google 
> Groups 
> >> "sympy" group. 
> >> To unsubscribe from this group and stop receiving emails from it, send 
> an 
> >> email to [email protected] <javascript:>. 
> >> To post to this group, send email to [email protected] 
> <javascript:>. 
> >> Visit this group at http://groups.google.com/group/sympy. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/sympy/a617808a-0cf2-4c84-87b9-122fa1bb04c6%40googlegroups.com.
>  
>
> >> For more options, visit https://groups.google.com/d/optout. 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "sympy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > Visit this group at http://groups.google.com/group/sympy. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/sympy/CAP7f1AjJJO0KQdvUkxePRuBMgN2FmOFviy6NRgz8LTyJ-PHqKw%40mail.gmail.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/20f2b073-3258-4e53-aab6-9e20dca5bd2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to