On 11 October 2012 14:18, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, Oct 11, 2012 at 11:31 PM, Sturla Molden <sturla@molden.no> wrote:
A global switch in the sys module would make life a lot easier. Even better would be a context manager that allows us to set up a "numerical" context for local expressions using a with statement. That would not have a lasting effect, but just affect the context. Preferably it should not even propagate across function calls. Something like this:
def foobar(): 1/0.0 # raise an exception 1/0 # raise an exception
with sys.numerical: 1/0.0 # return inf 1/0 # return 0 foobar()
Not propagating across function calls strikes me as messy, but I see why you'd want it. Would this be better as a __future__ directive? There's already the concept that they apply to a module but not to what that module calls.
__future__ directives are for situations in which the default behaviour will be changed in the future but you want to get the new behaviour now. The proposal is to always have widely supported, convenient ways to switch between different handling modes for numerical operations. The default Python behaviour would be unchanged by this. Oscar