[NumPy-Tickets] [NumPy] #1667: Provide a context manager for seterr

NumPy Trac numpy-tickets@scipy....
Mon Nov 8 15:43:37 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  |  
--------------------------------------+-------------------------------------

Comment(by warren.weckesser):

 The suggested code above is not correct.  This should do it:
 {{{
 import numpy

 class ErrorSettings(object):

     def __init__(self, **kwds):
         self.new_settings = kwds

     def __enter__(self):
         self.old_settings = numpy.seterr(**self.new_settings)

     def __exit__(self, type, value, traceback):
         numpy.seterr(**self.old_settings)
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1667#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list