A dummy class used to create objects pretending to have given attributes
| 511 | |
| 512 | |
| 513 | class _Duck: |
| 514 | """A dummy class used to create objects pretending to have given attributes""" |
| 515 | |
| 516 | def __init__(self, attributes: Optional[dict] = None, items: Optional[dict] = None): |
| 517 | self.attributes = attributes if attributes is not None else {} |
| 518 | self.items = items if items is not None else {} |
| 519 | |
| 520 | def __getattr__(self, attr: str): |
| 521 | return self.attributes[attr] |
| 522 | |
| 523 | def __hasattr__(self, attr: str): |
| 524 | return attr in self.attributes |
| 525 | |
| 526 | def __dir__(self): |
| 527 | return [*dir(super), *self.attributes] |
| 528 | |
| 529 | def __getitem__(self, key: str): |
| 530 | return self.items[key] |
| 531 | |
| 532 | def __hasitem__(self, key: str): |
| 533 | return self.items[key] |
| 534 | |
| 535 | def _ipython_key_completions_(self): |
| 536 | return self.items.keys() |
| 537 | |
| 538 | |
| 539 | def _find_dunder(node_op, dunders) -> Union[tuple[str, ...], None]: |
no outgoing calls
no test coverage detected
searching dependent graphs…