Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX/API: use inspect.signature for python3 #8795

Merged
merged 3 commits into from
Sep 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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