[Python-ideas] Floating point contexts in Python core
Chris Angelico
rosuav at gmail.com
Thu Oct 11 15:18:20 CEST 2012
On Thu, Oct 11, 2012 at 11:31 PM, Sturla Molden <sturla at 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.
ChrisA
More information about the Python-ideas
mailing list