Show More
@@ -76,7 +76,7 b" info_fields = ['type_name', 'base_class', 'string_form', 'namespace'," | |||
|
76 | 76 | 'call_def', 'call_docstring', |
|
77 | 77 | # These won't be printed but will be used to determine how to |
|
78 | 78 | # format the object |
|
79 |
'ismagic', 'isalias', 'isclass', ' |
|
|
79 | 'ismagic', 'isalias', 'isclass', 'found', 'name' | |
|
80 | 80 | ] |
|
81 | 81 | |
|
82 | 82 | |
@@ -200,26 +200,39 b' def is_simple_callable(obj):' | |||
|
200 | 200 | return (inspect.isfunction(obj) or inspect.ismethod(obj) or \ |
|
201 | 201 | isinstance(obj, _builtin_func_type) or isinstance(obj, _builtin_meth_type)) |
|
202 | 202 | |
|
203 | ||
|
203 | @undoc | |
|
204 | 204 | def getargspec(obj): |
|
205 | 205 | """Wrapper around :func:`inspect.getfullargspec` on Python 3, and |
|
206 | 206 | :func:inspect.getargspec` on Python 2. |
|
207 | 207 | |
|
208 | 208 | In addition to functions and methods, this can also handle objects with a |
|
209 | 209 | ``__call__`` attribute. |
|
210 | ||
|
211 | DEPRECATED: Deprecated since 7.10. Do not use, will be removed. | |
|
210 | 212 | """ |
|
213 | ||
|
214 | warnings.warn('`getargspec` function is deprecated as of IPython 7.10' | |
|
215 | 'and will be removed in future versions.', DeprecationWarning, stacklevel=2) | |
|
216 | ||
|
211 | 217 | if safe_hasattr(obj, '__call__') and not is_simple_callable(obj): |
|
212 | 218 | obj = obj.__call__ |
|
213 | 219 | |
|
214 | 220 | return inspect.getfullargspec(obj) |
|
215 | 221 | |
|
216 | ||
|
222 | @undoc | |
|
217 | 223 | def format_argspec(argspec): |
|
218 | 224 | """Format argspect, convenience wrapper around inspect's. |
|
219 | 225 | |
|
220 | 226 | This takes a dict instead of ordered arguments and calls |
|
221 | 227 | inspect.format_argspec with the arguments in the necessary order. |
|
228 | ||
|
229 | DEPRECATED: Do not use; will be removed in future versions. | |
|
222 | 230 | """ |
|
231 | ||
|
232 | warnings.warn('`format_argspec` function is deprecated as of IPython 7.10' | |
|
233 | 'and will be removed in future versions.', DeprecationWarning, stacklevel=2) | |
|
234 | ||
|
235 | ||
|
223 | 236 | return inspect.formatargspec(argspec['args'], argspec['varargs'], |
|
224 | 237 | argspec['varkw'], argspec['defaults']) |
|
225 | 238 | |
@@ -916,33 +929,6 b' class Inspector(Colorable):' | |||
|
916 | 929 | if call_ds: |
|
917 | 930 | out['call_docstring'] = call_ds |
|
918 | 931 | |
|
919 | # Compute the object's argspec as a callable. The key is to decide | |
|
920 | # whether to pull it from the object itself, from its __init__ or | |
|
921 | # from its __call__ method. | |
|
922 | ||
|
923 | if inspect.isclass(obj): | |
|
924 | # Old-style classes need not have an __init__ | |
|
925 | callable_obj = getattr(obj, "__init__", None) | |
|
926 | elif callable(obj): | |
|
927 | callable_obj = obj | |
|
928 | else: | |
|
929 | callable_obj = None | |
|
930 | ||
|
931 | if callable_obj is not None: | |
|
932 | try: | |
|
933 | argspec = getargspec(callable_obj) | |
|
934 | except Exception: | |
|
935 | # For extensions/builtins we can't retrieve the argspec | |
|
936 | pass | |
|
937 | else: | |
|
938 | # named tuples' _asdict() method returns an OrderedDict, but we | |
|
939 | # we want a normal | |
|
940 | out['argspec'] = argspec_dict = dict(argspec._asdict()) | |
|
941 | # We called this varkw before argspec became a named tuple. | |
|
942 | # With getfullargspec it's also called varkw. | |
|
943 | if 'varkw' not in argspec_dict: | |
|
944 | argspec_dict['varkw'] = argspec_dict.pop('keywords') | |
|
945 | ||
|
946 | 932 | return object_info(**out) |
|
947 | 933 | |
|
948 | 934 | @staticmethod |
General Comments 0
You need to be logged in to leave comments.
Login now