| 8 | # issue gh-14735: make sure we clear only getattr errors, and let warnings |
| 9 | # through |
| 10 | class Wrapper: |
| 11 | def __init__(self, array): |
| 12 | self.array = array |
| 13 | |
| 14 | def __len__(self): |
| 15 | return len(self.array) |
| 16 | |
| 17 | def __getitem__(self, item): |
| 18 | return type(self)(self.array[item]) |
| 19 | |
| 20 | def __getattr__(self, name): |
| 21 | if name.startswith("__array_"): |
| 22 | warnings.warn("object got converted", UserWarning, stacklevel=1) |
| 23 | |
| 24 | return getattr(self.array, name) |
| 25 | |
| 26 | def __repr__(self): |
| 27 | return "<Wrapper({self.array})>".format(self=self) |
| 28 | |
| 29 | array = Wrapper(np.arange(10)) |
| 30 | with pytest.raises(UserWarning, match="object got converted"): |
no outgoing calls