Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/IPython/utils/generics.py: 65%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

1"""Generic functions for extending IPython.""" 

2 

3from __future__ import annotations 

4 

5import warnings 

6from typing import Any 

7 

8from IPython.core.error import TryNext 

9from functools import singledispatch 

10 

11 

12@singledispatch 

13def _inspect_object(obj: Any) -> None: 

14 """Called when you do obj? 

15 

16 .. deprecated:: 9.15 

17 `inspect_object` is deprecated and will be removed in a future 

18 version. It is no longer used within IPython, so registering 

19 handlers on it has no effect. 

20 """ 

21 raise TryNext 

22 

23 

24def __getattr__(name: str) -> Any: 

25 if name == "inspect_object": 

26 warnings.warn( 

27 "inspect_object is deprecated since IPython 9.15 and will be " 

28 "removed in a future version. It is no longer used within " 

29 "IPython, so registering handlers on it has no effect.", 

30 DeprecationWarning, 

31 stacklevel=2, 

32 ) 

33 return _inspect_object 

34 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

35 

36 

37@singledispatch 

38def complete_object(obj: Any, prev_completions: list[str]) -> list[str]: 

39 """Custom completer dispatching for python objects. 

40 

41 Parameters 

42 ---------- 

43 obj : object 

44 The object to complete. 

45 prev_completions : list 

46 List of attributes discovered so far. 

47 This should return the list of attributes in obj. If you only wish to 

48 add to the attributes already discovered normally, return 

49 own_attrs + prev_completions. 

50 """ 

51 raise TryNext