Return a constructor for an abstract `Atom` class.
(
deftype: str, defvalue: Any
)
| 607 | |
| 608 | |
| 609 | def _abstract_atom_init( |
| 610 | deftype: str, defvalue: Any |
| 611 | ) -> Callable[[Atom, int | None, Shape, Any], None]: |
| 612 | """Return a constructor for an abstract `Atom` class.""" |
| 613 | defitemsize = split_type(deftype)[1] |
| 614 | |
| 615 | def __init__( # noqa: N807 |
| 616 | self: Atom, |
| 617 | itemsize: int | None = defitemsize, |
| 618 | shape: Shape = (), |
| 619 | dflt: Any = defvalue, |
| 620 | ) -> None: |
| 621 | assert self.kind in atom_map |
| 622 | try: |
| 623 | atomclass = atom_map[self.kind][itemsize] |
| 624 | except KeyError: |
| 625 | raise _invalid_itemsize_error( |
| 626 | self.kind, itemsize, atom_map[self.kind] |
| 627 | ) |
| 628 | self.__class__ = atomclass |
| 629 | atomclass.__init__(self, shape, dflt) |
| 630 | |
| 631 | return __init__ |
| 632 | |
| 633 | |
| 634 | class StringAtom(Atom): # type: ignore[misc] |
no test coverage detected