Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if inst.size > 0 and self.generic_type:
if isinstance(self.generic_type, tuple):
inst_dtypes = [inst.dtype[name] for name in inst.dtype.names]
cls_dtypes = [np.dtype(typ) for typ in self.generic_type]
result = inst_dtypes == cls_dtypes
else:
result = isinstance(inst[0], self.generic_type)
result |= inst.dtype == np.dtype(self.generic_type)
result &= self.rows is ... or self.rows == rows
result &= self.cols is ... or self.cols == cols
return result
class _Array(metaclass=_ArrayMeta):
# This class exists to keep the Array class as clean as possible.
_ROWCOL_TYPES = [int, Ellipsis_, NoneType]
generic_type = None
rows = ...
cols = ...
def __new__(cls, *args, **kwargs):
raise TypeError("Cannot instantiate abstract class Array")
@classmethod
def _after_subscription(cls, item):
if not isinstance(item, tuple):
cls.generic_type = item
else:
if not len(item):
raise TypeError('Parameter Array[...] cannot be empty')
# Collect all elements in item that are types and keep track of