Skip to content

Commit 79baef7

Browse files
committed
MAINT: Use property decorators for clarity
1 parent f2d8aab commit 79baef7

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

numpy/core/_internal.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ def strides_as(self, obj):
311311
return None
312312
return (obj*self._arr.ndim)(*self._arr.strides)
313313

314-
def get_data(self):
314+
@property
315+
def data(self):
315316
"""
316317
A pointer to the memory area of the array as a Python integer.
317318
This memory area may contain data that is not aligned, or not in correct
@@ -328,7 +329,8 @@ def get_data(self):
328329
"""
329330
return self._data.value
330331

331-
def get_shape(self):
332+
@property
333+
def shape(self):
332334
"""
333335
(c_intp*self.ndim): A ctypes array of length self.ndim where
334336
the basetype is the C-integer corresponding to ``dtype('p')`` on this
@@ -339,7 +341,8 @@ def get_shape(self):
339341
"""
340342
return self.shape_as(_getintp_ctype())
341343

342-
def get_strides(self):
344+
@property
345+
def strides(self):
343346
"""
344347
(c_intp*self.ndim): A ctypes array of length self.ndim where
345348
the basetype is the same as for the shape attribute. This ctypes array
@@ -349,13 +352,20 @@ def get_strides(self):
349352
"""
350353
return self.strides_as(_getintp_ctype())
351354

352-
def get_as_parameter(self):
355+
@property
356+
def _as_parameter_(self):
357+
"""
358+
Overrides the ctypes semi-magic method
359+
360+
Enables `c_func(some_array.ctypes)`
361+
"""
353362
return self._data
354363

355-
data = property(get_data)
356-
shape = property(get_shape)
357-
strides = property(get_strides)
358-
_as_parameter_ = property(get_as_parameter, None, doc="_as parameter_")
364+
# kept for compatibility
365+
get_data = data.fget
366+
get_shape = shape.fget
367+
get_strides = strides.fget
368+
get_as_parameter = _as_parameter_.fget
359369

360370

361371
def _newnames(datatype, order):

0 commit comments

Comments
 (0)