(self, attr, val)
| 473 | # Undo any "setting" of the attribute and do a setfield |
| 474 | # Thus, you can't create attributes on-the-fly that are field names. |
| 475 | def __setattr__(self, attr, val): |
| 476 | |
| 477 | # Automatically convert (void) structured types to records |
| 478 | # (but not non-void structures, subarrays, or non-structured voids) |
| 479 | if attr == 'dtype' and issubclass(val.type, nt.void) and val.names is not None: |
| 480 | val = sb.dtype((record, val)) |
| 481 | |
| 482 | newattr = attr not in self.__dict__ |
| 483 | try: |
| 484 | ret = object.__setattr__(self, attr, val) |
| 485 | except Exception: |
| 486 | fielddict = ndarray.__getattribute__(self, 'dtype').fields or {} |
| 487 | if attr not in fielddict: |
| 488 | raise |
| 489 | else: |
| 490 | fielddict = ndarray.__getattribute__(self, 'dtype').fields or {} |
| 491 | if attr not in fielddict: |
| 492 | return ret |
| 493 | if newattr: |
| 494 | # We just added this one or this setattr worked on an |
| 495 | # internal attribute. |
| 496 | try: |
| 497 | object.__delattr__(self, attr) |
| 498 | except Exception: |
| 499 | return ret |
| 500 | try: |
| 501 | res = fielddict[attr][:2] |
| 502 | except (TypeError, KeyError) as e: |
| 503 | raise AttributeError( |
| 504 | "record array has no attribute %s" % attr |
| 505 | ) from e |
| 506 | return self.setfield(val, *res) |
| 507 | |
| 508 | def __getitem__(self, indx): |
| 509 | obj = super().__getitem__(indx) |
nothing calls this directly
no test coverage detected