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 2 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
26 changes: 17 additions & 9 deletions IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,22 +839,30 @@ 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__', ''))

try:
args,_,_1,defaults = inspect.getargspec(call_obj)
if defaults:
ret+=args[-len(defaults):]
except TypeError:
pass

if PY3:
_keepers = (inspect.Parameter.KEYWORD_ONLY,
inspect.Parameter.POSITIONAL_OR_KEYWORD)
try:
sig = inspect.signature(call_obj)
ret.extend(k for k, v in sig.parameters.items() if
v.kind in _keepers)
except ValueError:
pass
else:
try:
args, _, _1, defaults = inspect.getargspec(call_obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what would happen if on py2, this could a) unwrap (signature does unwrap until a "signature" is found, getargspec does not) and b) check for a simple get_additional_completions(...) function which we could then set in out decorator. getdoc() already does something similar...

so:

addons = []
while true:
    if hasattr(call_obj, "get_additional_completions"):
        addons.extend(call_obj.get_additional_completitions())
        break
    if hasattr(call_obj, "__wrapped__"):
        call_obj = call_obj.__wrapped__
    else:
        break
[...]
ret.extend(addons)

if defaults:
ret += args[-len(defaults):]
except TypeError:
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