MCPcopy Create free account
hub / github.com/numpy/numpy / Wrapper

Class Wrapper

numpy/core/tests/test_protocols.py:10–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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"):

Callers 2

test_getattr_warningFunction · 0.85
test_array_calledFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_getattr_warningFunction · 0.68
test_array_calledFunction · 0.68