Skip to content

Commit

Permalink
Fix __call__ param completion. Fixes #613.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Jul 31, 2016
1 parent 5f064a2 commit 62e1841
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion jedi/api/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,20 @@ def params(self):
params = followed.params
elif followed.isinstance(er.compiled.CompiledObject):
params = followed.params
else:
elif isinstance(followed, er.Class):
try:
sub = followed.get_subscope_by_name('__init__')
params = sub.params[1:] # ignore self
except KeyError:
return []
elif isinstance(followed, er.Instance):
try:
sub = followed.get_subscope_by_name('__call__')
params = sub.params[1:] # ignore self
except KeyError:
return []
else:
return []
return [_Param(self._evaluator, p.name) for p in params]

def parent(self):
Expand Down
5 changes: 2 additions & 3 deletions jedi/api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"""
import re
from collections import namedtuple
from textwrap import dedent

from jedi._compatibility import u
from jedi.evaluate.helpers import call_of_leaf
from jedi import parser
from jedi.parser import tokenize, token
from jedi.parser import tokenize
from jedi.cache import time_cache
from jedi import common

Expand Down Expand Up @@ -279,7 +278,7 @@ def get_call_signature_details(module, position):
# makes it feel strange to have a call signature.
return None

for n in node.children:
for n in node.children[::-1]:
if n.start_pos < position and n.type == 'error_node':
result = _get_call_signature_details_from_error_node(n, position)
if result is not None:
Expand Down
13 changes: 13 additions & 0 deletions test/completion/named_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ def multiple(foo, bar):
my_lambda = lambda lambda_param: lambda_param + 1
#? 22 ['lambda_param']
my_lambda(lambda_param)

# __call__
class Test(object):
def __init__(self, hello_other):
pass

def __call__(self, hello):
pass

#? 12 ['hello']
Test()(hello=)
#? 11 []
Test()(self=)

0 comments on commit 62e1841

Please sign in to comment.