[NumPy-Tickets] [NumPy] #1667: Provide a context manager for seterr
NumPy Trac
numpy-tickets@scipy....
Mon Nov 8 15:14:27 CST 2010
#1667: Provide a context manager for seterr
--------------------------------------+-------------------------------------
Reporter: warren.weckesser | Owner: somebody
Type: enhancement | Status: new
Priority: normal | Milestone: 2.0.0
Component: Other | Version: 1.5.0
Keywords: setterr, context manager |
--------------------------------------+-------------------------------------
It would be great if there were a context manager for the error settings.
Something as simple as this
{{{
import numpy
class ErrorSettings(object):
def __enter__(self, **kwds):
self.previous = numpy.seterr(**kwds)
def __exit__(self, type, value, traceback):
numpy.seterr(**self.previous)
}}}
would allow code such as this:
{{{
with ErrorSettings(invalid='ignore'):
y = sin(x) / x
}}}
instead of
{{{
oldsettings = np.seterr(invalid='ignore')
y = sin(x) / x
np.seterr(**oldsettings)
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1667>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list