return super().__new__(metacls, clsname, bases, ns)
- def __getitem__(cls, size):
- clsname = f"{cls.__name__}[{size}]"
- items = ((Field,) * size)
- return ArrayMeta(clsname, (Array,), {}, items=items)
-
def __repr__(cls):
if not cls.__members__:
return cls.__name__
def __len__(cls):
return len(cls.__members__)
+ def __getitem__(cls, selector):
+ if isinstance(selector, int):
+ selector = (selector,)
+
+ items = []
+ for idx in selector:
+ if not isinstance(idx, int):
+ raise ValueError(selector)
+ item = cls.__members__[idx]
+ items.append(item)
+
+ return cls.__class__(cls.__name__, (Field,), {}, items=items)
+
def remap(cls, scheme):
if isinstance(scheme, type) and issubclass(scheme, Mapping):
scheme = range(len(scheme))
length += len(field)
return length
+ def __getitem__(cls, size):
+ clsname = f"{cls.__name__}[{size}]"
+ items = ((Field,) * size)
+ return ArrayMeta(clsname, (Array,), {}, items=items)
+
def remap(cls, scheme):
scheme_md = []
scheme_sd = []
length = max(length, len(field))
return length
+ def __getitem__(cls, selector):
+ best_min = 0
+ best_max = 0
+ for field in cls.__members__.values():
+ length = len(field)
+ best_min = min(best_min, length)
+ best_max = max(best_max, length)
+
+ items = tuple(range(best_min, best_max))
+ field = FieldMeta(cls.__name__, (Field,), {}, items=items)
+
+ return field[selector]
+
def remap(cls, scheme):
ns = {}
annotations = {}