Show More
@@ -24,7 +24,18 b' import os' | |||
|
24 | 24 | import types |
|
25 | 25 | import warnings |
|
26 | 26 | |
|
27 | from typing import cast, Any, Optional, Dict, Union, List, TypedDict, TypeAlias, Tuple | |
|
27 | ||
|
28 | from typing import ( | |
|
29 | cast, | |
|
30 | Any, | |
|
31 | Optional, | |
|
32 | Dict, | |
|
33 | Union, | |
|
34 | List, | |
|
35 | TypedDict, | |
|
36 | TypeAlias, | |
|
37 | Tuple, | |
|
38 | ) | |
|
28 | 39 | |
|
29 | 40 | import traitlets |
|
30 | 41 | |
@@ -32,13 +43,11 b' import traitlets' | |||
|
32 | 43 | from IPython.core import page |
|
33 | 44 | from IPython.lib.pretty import pretty |
|
34 | 45 | from IPython.testing.skipdoctest import skip_doctest |
|
35 | from IPython.utils import PyColorize | |
|
36 | from IPython.utils import openpy | |
|
46 | from IPython.utils import PyColorize, openpy | |
|
37 | 47 | from IPython.utils.dir2 import safe_hasattr |
|
38 | 48 | from IPython.utils.path import compress_user |
|
39 | 49 | from IPython.utils.text import indent |
|
40 | from IPython.utils.wildcard import list_namespace | |
|
41 | from IPython.utils.wildcard import typestr2type | |
|
50 | from IPython.utils.wildcard import list_namespace, typestr2type | |
|
42 | 51 | from IPython.utils.coloransi import TermColors |
|
43 | 52 | from IPython.utils.colorable import Colorable |
|
44 | 53 | from IPython.utils.decorators import undoc |
@@ -129,7 +138,19 b' class InfoDict(TypedDict):' | |||
|
129 | 138 | name: str |
|
130 | 139 | |
|
131 | 140 | |
|
132 | info_fields = list(InfoDict.__annotations__.keys()) | |
|
141 | _info_fields = list(InfoDict.__annotations__.keys()) | |
|
142 | ||
|
143 | ||
|
144 | def __getattr__(name): | |
|
145 | if name == "info_fields": | |
|
146 | warnings.warn( | |
|
147 | "IPython.core.oinspect's `info_fields` is considered for deprecation and may be removed in the Future. ", | |
|
148 | DeprecationWarning, | |
|
149 | stacklevel=2, | |
|
150 | ) | |
|
151 | return _info_fields | |
|
152 | ||
|
153 | raise AttributeError(f"module {__name__!r} has no attribute {name!r}") | |
|
133 | 154 | |
|
134 | 155 | |
|
135 | 156 | @dataclass |
@@ -144,11 +165,25 b' class InspectorHookData:' | |||
|
144 | 165 | |
|
145 | 166 | |
|
146 | 167 | @undoc |
|
147 |
def object_info( |
|
|
168 | def object_info( | |
|
169 | *, | |
|
170 | name: str, | |
|
171 | found: bool, | |
|
172 | isclass: bool = False, | |
|
173 | isalias: bool = False, | |
|
174 | ismagic: bool = False, | |
|
175 | **kw, | |
|
176 | ) -> InfoDict: | |
|
148 | 177 | """Make an object info dict with all fields present.""" |
|
149 | infodict = {k: None for k in info_fields} | |
|
150 | infodict.update(kw) | |
|
151 | return infodict | |
|
178 | infodict = kw | |
|
179 | infodict = {k: None for k in _info_fields if k not in infodict} | |
|
180 | infodict["name"] = name # type: ignore | |
|
181 | infodict["found"] = found # type: ignore | |
|
182 | infodict["isclass"] = isclass # type: ignore | |
|
183 | infodict["isalias"] = isalias # type: ignore | |
|
184 | infodict["ismagic"] = ismagic # type: ignore | |
|
185 | ||
|
186 | return InfoDict(**infodict) # type:ignore | |
|
152 | 187 | |
|
153 | 188 | |
|
154 | 189 | def get_encoding(obj): |
@@ -175,7 +210,7 b' def get_encoding(obj):' | |||
|
175 | 210 | return encoding |
|
176 | 211 | |
|
177 | 212 | |
|
178 | def getdoc(obj) -> Union[str,None]: | |
|
213 | def getdoc(obj) -> Union[str, None]: | |
|
179 | 214 | """Stable wrapper around inspect.getdoc. |
|
180 | 215 | |
|
181 | 216 | This can't crash because of attribute problems. |
@@ -581,8 +616,10 b' class Inspector(Colorable):' | |||
|
581 | 616 | # run contents of file through pager starting at line where the object |
|
582 | 617 | # is defined, as long as the file isn't binary and is actually on the |
|
583 | 618 | # filesystem. |
|
584 | if ofile.endswith(('.so', '.dll', '.pyd')): | |
|
585 | print('File %r is binary, not printing.' % ofile) | |
|
619 | if ofile is None: | |
|
620 | print("Could not find file for object") | |
|
621 | elif ofile.endswith((".so", ".dll", ".pyd")): | |
|
622 | print("File %r is binary, not printing." % ofile) | |
|
586 | 623 | elif not os.path.isfile(ofile): |
|
587 | 624 | print('File %r does not exist, not printing.' % ofile) |
|
588 | 625 | else: |
@@ -670,7 +707,7 b' class Inspector(Colorable):' | |||
|
670 | 707 | title: str, |
|
671 | 708 | key: str, |
|
672 | 709 | info, |
|
673 | omit_sections, | |
|
710 | omit_sections: List[str], | |
|
674 | 711 | formatter, |
|
675 | 712 | ): |
|
676 | 713 | """Append an info value to the unformatted mimebundle being constructed by _make_info_unformatted""" |
@@ -767,8 +804,8 b' class Inspector(Colorable):' | |||
|
767 | 804 | oname: str = "", |
|
768 | 805 | formatter=None, |
|
769 | 806 | info: Optional[OInfo] = None, |
|
770 | detail_level=0, | |
|
771 | omit_sections=(), | |
|
807 | detail_level: int = 0, | |
|
808 | omit_sections: Union[List[str], Tuple[()]] = (), | |
|
772 | 809 | ) -> Bundle: |
|
773 | 810 | """Retrieve an info dict and format it. |
|
774 | 811 | |
@@ -783,11 +820,12 b' class Inspector(Colorable):' | |||
|
783 | 820 | already computed information |
|
784 | 821 | detail_level : integer |
|
785 | 822 | Granularity of detail level, if set to 1, give more information. |
|
786 |
omit_sections : |
|
|
823 | omit_sections : list[str] | |
|
787 | 824 | Titles or keys to omit from output (can be set, tuple, etc., anything supporting `in`) |
|
788 | 825 | """ |
|
789 | 826 | |
|
790 | 827 | info_dict = self.info(obj, oname=oname, info=info, detail_level=detail_level) |
|
828 | omit_sections = list(omit_sections) | |
|
791 | 829 | |
|
792 | 830 | bundle = self._make_info_unformatted( |
|
793 | 831 | obj, |
@@ -804,7 +842,7 b' class Inspector(Colorable):' | |||
|
804 | 842 | detail_level=detail_level, |
|
805 | 843 | omit_sections=omit_sections, |
|
806 | 844 | ) |
|
807 | for key, hook in self.mime_hooks.items(): | |
|
845 | for key, hook in self.mime_hooks.items(): # type:ignore | |
|
808 | 846 | required_parameters = [ |
|
809 | 847 | parameter |
|
810 | 848 | for parameter in inspect.signature(hook).parameters.values() |
@@ -920,7 +958,7 b' class Inspector(Colorable):' | |||
|
920 | 958 | out: InfoDict = cast( |
|
921 | 959 | InfoDict, |
|
922 | 960 | { |
|
923 | **{field: None for field in info_fields}, | |
|
961 | **{field: None for field in _info_fields}, | |
|
924 | 962 | **{ |
|
925 | 963 | "name": oname, |
|
926 | 964 | "found": True, |
General Comments 0
You need to be logged in to leave comments.
Login now