generics.py 807 B

1234567891011121314151617181920212223242526272829303132
  1. # encoding: utf-8
  2. """Generic functions for extending IPython."""
  3. from __future__ import annotations
  4. from typing import Any
  5. from IPython.core.error import TryNext
  6. from functools import singledispatch
  7. @singledispatch
  8. def inspect_object(obj: Any) -> None:
  9. """Called when you do obj?"""
  10. raise TryNext
  11. @singledispatch
  12. def complete_object(obj: Any, prev_completions: list[str]) -> list[str]:
  13. """Custom completer dispatching for python objects.
  14. Parameters
  15. ----------
  16. obj : object
  17. The object to complete.
  18. prev_completions : list
  19. List of attributes discovered so far.
  20. This should return the list of attributes in obj. If you only wish to
  21. add to the attributes already discovered normally, return
  22. own_attrs + prev_completions.
  23. """
  24. raise TryNext