From 470d53fc6bc8267fec7d7cf5c7116d5e7437d789 Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Tue, 13 Nov 2018 14:08:19 -0800 Subject: BUG: improve DataSource __del__ * DataSource __del__ could raise an AttributeError if __init__ failed for any reason; __del__ now gracefully handles the case where __init__ fails, as happens in the internals of refguide_check when handling DataSource with an unexpected kwarg --- numpy/lib/tests/test__datasource.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'numpy/lib/tests') diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py index 1df8bebf6..8eac16b58 100644 --- a/numpy/lib/tests/test__datasource.py +++ b/numpy/lib/tests/test__datasource.py @@ -361,3 +361,18 @@ class TestOpenFunc(object): fp = datasource.open(local_file) assert_(fp) fp.close() + +def test_del_attr_handling(): + # DataSource __del__ can be called + # even if __init__ fails when the + # Exception object is caught by the + # caller as happens in refguide_check + # is_deprecated() function + + ds = datasource.DataSource() + # simulate failed __init__ by removing key attribute + # produced within __init__ and expected by __del__ + del ds._istmpdest + # should not raise an AttributeError if __del__ + # gracefully handles failed __init__: + ds.__del__() -- cgit v1.2.1