##// END OF EJS Templates
Deprecate some methods the should not be used anymore...
Matthias Bussonnier -
Show More
@@ -76,7 +76,7 b" info_fields = ['type_name', 'base_class', 'string_form', 'namespace',"
76 'call_def', 'call_docstring',
76 'call_def', 'call_docstring',
77 # These won't be printed but will be used to determine how to
77 # These won't be printed but will be used to determine how to
78 # format the object
78 # format the object
79 'ismagic', 'isalias', 'isclass', 'argspec', 'found', 'name'
79 'ismagic', 'isalias', 'isclass', 'found', 'name'
80 ]
80 ]
81
81
82
82
@@ -200,26 +200,39 b' def is_simple_callable(obj):'
200 return (inspect.isfunction(obj) or inspect.ismethod(obj) or \
200 return (inspect.isfunction(obj) or inspect.ismethod(obj) or \
201 isinstance(obj, _builtin_func_type) or isinstance(obj, _builtin_meth_type))
201 isinstance(obj, _builtin_func_type) or isinstance(obj, _builtin_meth_type))
202
202
203
203 @undoc
204 def getargspec(obj):
204 def getargspec(obj):
205 """Wrapper around :func:`inspect.getfullargspec` on Python 3, and
205 """Wrapper around :func:`inspect.getfullargspec` on Python 3, and
206 :func:inspect.getargspec` on Python 2.
206 :func:inspect.getargspec` on Python 2.
207
207
208 In addition to functions and methods, this can also handle objects with a
208 In addition to functions and methods, this can also handle objects with a
209 ``__call__`` attribute.
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 if safe_hasattr(obj, '__call__') and not is_simple_callable(obj):
217 if safe_hasattr(obj, '__call__') and not is_simple_callable(obj):
212 obj = obj.__call__
218 obj = obj.__call__
213
219
214 return inspect.getfullargspec(obj)
220 return inspect.getfullargspec(obj)
215
221
216
222 @undoc
217 def format_argspec(argspec):
223 def format_argspec(argspec):
218 """Format argspect, convenience wrapper around inspect's.
224 """Format argspect, convenience wrapper around inspect's.
219
225
220 This takes a dict instead of ordered arguments and calls
226 This takes a dict instead of ordered arguments and calls
221 inspect.format_argspec with the arguments in the necessary order.
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 return inspect.formatargspec(argspec['args'], argspec['varargs'],
236 return inspect.formatargspec(argspec['args'], argspec['varargs'],
224 argspec['varkw'], argspec['defaults'])
237 argspec['varkw'], argspec['defaults'])
225
238
@@ -916,33 +929,6 b' class Inspector(Colorable):'
916 if call_ds:
929 if call_ds:
917 out['call_docstring'] = call_ds
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 return object_info(**out)
932 return object_info(**out)
947
933
948 @staticmethod
934 @staticmethod
General Comments 0
You need to be logged in to leave comments. Login now