Carl Witty wrote: > On Apr 10, 1:41 am, Simon King <[EMAIL PROTECTED]> wrote: >> On Apr 10, 4:18 am, Carl Witty <[EMAIL PROTECTED]> wrote: >> >>> I like the "raise an exception" behavior, because it would eliminate >>> questions asking why form1 and form2 below are different (from this >>> sage-support >>> threadhttp://groups.google.com/group/sage-support/browse_thread/thread/79d0...). >>> (I have seen this exact problem at least twice on sage-support.) What >>> do you think? >> I guess what i suggest wouldn't solve the plot-issue. However, i think >> if one doesn't know whether an inequality holds, or if the inequality >> simply makes no sense (such as in the case of an unordered field) then >> bool() should neither raise an exception nor return False but return >> None. I think it is much simpler to have > > bool() is a Python builtin that cannot return None. bool(x) calls > x.__nonzero__(); but if you try to make __nonzero__() return None, you > get: > <type 'exceptions.TypeError'>: __nonzero__ should return an int > > Chris's suggestion of making if: sometimes return an "unevaluated if" > is also impossible in Python. > > Of course, we can (and probably should) make a new method on > SymbolicEquation that returns True/False/None; we could also add > support for a symbolic "unevaluated if" if we wanted. But since we > use Python, we're stuck with: bool(x > 0) must return True, False, or > raise an exception; and this controls what "if x > 0:" will do. >
The reason why I eventually decided that throwing an exception was unpythonic was that I could not find a single case of current python code which did that. Actually, the one reference I did find was a bugfix to a project (I think SQLAlchemy), in which they changed __nonzero__ to not raise an exception since it was inconsistent with other behavior. That, and the fact that Python by default returns True for objects instead of raising exceptions, tells me that raising exceptions would also raise an exceptional number of eyebrows and probably voices too. I think we ought to have a different function for testing true/false and would return a third value (None? an exception?) if the value was not known. Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
