Get a column subclass for the given `prefix`.
(cls, prefix: str)
| 183 | |
| 184 | @classmethod |
| 185 | def _subclass_from_prefix(cls, prefix: str) -> type[Col]: |
| 186 | """Get a column subclass for the given `prefix`.""" |
| 187 | cname = "%sCol" % prefix |
| 188 | class_from_prefix = cls._class_from_prefix |
| 189 | if cname in class_from_prefix: |
| 190 | return class_from_prefix[cname] |
| 191 | atombase = getattr(atom, "%sAtom" % prefix) |
| 192 | |
| 193 | class NewCol(cls, atombase): |
| 194 | """Defines a non-nested column of a particular type. |
| 195 | |
| 196 | The constructor accepts the same arguments as the equivalent |
| 197 | `Atom` class, plus an additional ``pos`` argument for |
| 198 | position information, which is assigned to the `_v_pos` |
| 199 | attribute and an ``attrs`` argument for storing additional metadata |
| 200 | similar to `table.attrs`, which is assigned to the `_v_col_attrs` |
| 201 | attribute. |
| 202 | |
| 203 | """ |
| 204 | |
| 205 | def __init__(self, *args, **kwargs) -> None: |
| 206 | pos = kwargs.pop("pos", None) |
| 207 | col_attrs = kwargs.pop("attrs", {}) |
| 208 | offset = kwargs.pop("_offset", None) |
| 209 | class_from_prefix = self._class_from_prefix |
| 210 | atombase.__init__(self, *args, **kwargs) |
| 211 | # The constructor of an abstract atom may have changed |
| 212 | # the class of `self` to something different of `NewCol` |
| 213 | # and `atombase` (that's why the prefix map is saved). |
| 214 | if self.__class__ is not NewCol: |
| 215 | colclass = class_from_prefix[self.prefix()] |
| 216 | self.__class__ = colclass |
| 217 | self._v_pos = pos |
| 218 | self._v_offset = offset |
| 219 | self._v_col_attrs = col_attrs |
| 220 | |
| 221 | __eq__ = same_position(atombase.__eq__) |
| 222 | _is_equal_to_atom = same_position(atombase._is_equal_to_atom) |
| 223 | |
| 224 | # XXX: API incompatible change for PyTables 3 line |
| 225 | # Overriding __eq__ blocks inheritance of __hash__ in 3.x |
| 226 | # def __hash__(self): |
| 227 | # return hash((self._v_pos, self.atombase)) |
| 228 | |
| 229 | if prefix == "Enum": |
| 230 | _is_equal_to_enumatom = same_position( |
| 231 | atombase._is_equal_to_enumatom |
| 232 | ) |
| 233 | |
| 234 | NewCol.__name__ = cname |
| 235 | |
| 236 | class_from_prefix[prefix] = NewCol |
| 237 | return NewCol |
| 238 | |
| 239 | def __repr__(self) -> str: |
| 240 | # Reuse the atom representation. |
no outgoing calls
no test coverage detected