MCPcopy Index your code
hub / github.com/ipython/ipython / _Duck

Class _Duck

IPython/core/guarded_eval.py:513–536  ·  view source on GitHub ↗

A dummy class used to create objects pretending to have given attributes

Source from the content-addressed store, hash-verified

511
512
513class _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
539def _find_dunder(node_op, dunders) -> Union[tuple[str, ...], None]:

Callers 4

_handle_assignFunction · 0.85
eval_nodeFunction · 0.85
_merge_valuesFunction · 0.85
_resolve_annotationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…