Skip to content

Commit

Permalink
Merge pull request ipython#8795 from tacaswell/fix_kwonly_arg_complete
Browse files Browse the repository at this point in the history
FIX/API: use inspect.signature for python3
  • Loading branch information
minrk committed Sep 12, 2015
2 parents d361893 + 8a95d9a commit 3b2b82f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,22 +839,31 @@ def _default_arguments(self, obj):
# for all others, check if they are __call__able
elif hasattr(obj, '__call__'):
call_obj = obj.__call__

ret += self._default_arguments_from_docstring(
getattr(call_obj, '__doc__', ''))

if PY3:
_keeps = (inspect.Parameter.KEYWORD_ONLY,
inspect.Parameter.POSITIONAL_OR_KEYWORD)
signature = inspect.signature
else:
import IPython.utils.signatures
_keeps = (IPython.utils.signatures.Parameter.KEYWORD_ONLY,
IPython.utils.signatures.Parameter.POSITIONAL_OR_KEYWORD)
signature = IPython.utils.signatures.signature

try:
args,_,_1,defaults = inspect.getargspec(call_obj)
if defaults:
ret+=args[-len(defaults):]
except TypeError:
sig = signature(call_obj)
ret.extend(k for k, v in sig.parameters.items() if
v.kind in _keeps)
except ValueError:
pass

return list(set(ret))

def python_func_kw_matches(self,text):
"""Match named parameters (kwargs) of the last open function"""

if "." in text: # a parameter cannot be dotted
return []
try: regexp = self.__funcParamsRegex
Expand Down

0 comments on commit 3b2b82f

Please sign in to comment.