From a054ffd20ba2cd865a53e6ab149ae7d24acc97d9 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Wed, 20 Jan 2021 15:29:21 -0600 Subject: BUG: Keep ignoring most errors during array-protocol lookup Closes (the later point) in gh-17965 and reverts parts of gh-17817. Shapely did rely on being able to raise a NotImplementedError which then got ignored in the attribute lookup. Arguably, this should probably just raise an AttributeError to achieve that behaviour, but it means we can't just rip the band-aid off here. Since 1.20 is practically released, just reverting most of the change (leaving only recursion and memory error which are both arguably pretty fatal). Ignoring most errors should be deprecated (and I am happy to do so), but it is not important enough for 1.20 or very important in itself. Closes gh-17965 --- numpy/core/tests/test_array_coercion.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'numpy/core/tests') diff --git a/numpy/core/tests/test_array_coercion.py b/numpy/core/tests/test_array_coercion.py index 08b32dfcc..8f709dbe1 100644 --- a/numpy/core/tests/test_array_coercion.py +++ b/numpy/core/tests/test_array_coercion.py @@ -702,17 +702,19 @@ class TestArrayLikes: @pytest.mark.parametrize("attribute", ["__array_interface__", "__array__", "__array_struct__"]) - def test_bad_array_like_attributes(self, attribute): - # Check that errors during attribute retrieval are raised unless - # they are Attribute errors. + @pytest.mark.parametrize("error", [RecursionError, MemoryError]) + def test_bad_array_like_attributes(self, attribute, error): + # RecursionError and MemoryError are considered fatal. All errors + # (except AttributeError) should probably be raised in the future, + # but shapely made use of it, so it will require a deprecation. class BadInterface: def __getattr__(self, attr): if attr == attribute: - raise RuntimeError + raise error super().__getattr__(attr) - with pytest.raises(RuntimeError): + with pytest.raises(error): np.array(BadInterface()) @pytest.mark.parametrize("error", [RecursionError, MemoryError]) -- cgit v1.2.1