1
0
forked from VimPlug/jedi

Fix issues with default parameters in functions and classes

Default parameters were resolved at the wrong starting position. Fixes #1044
This commit is contained in:
Dave Halter
2018-03-08 09:59:09 +01:00
parent 14ac6b11b9
commit 51e0d5d12f
4 changed files with 38 additions and 4 deletions
+20 -1
View File
@@ -95,7 +95,26 @@ class NameFinder(object):
def get_filters(self, search_global=False):
origin_scope = self._get_origin_scope()
if search_global:
return get_global_filters(self._evaluator, self._context, self._position, origin_scope)
position = self._position
# For functions and classes the defaults don't belong to the
# function and get evaluated in the context before the function. So
# make sure to exclude the function/class name.
if origin_scope is not None:
ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef', 'lambdef')
lambdef = None
if ancestor == 'lambdef':
# For lambdas it's even more complicated since parts will
# be evaluated later.
lambdef = ancestor
ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef')
if ancestor is not None:
colon = ancestor.children[-2]
if position < colon.start_pos:
if lambdef is None or position < lambdef.children[-2].start_pos:
position = ancestor.start_pos
return get_global_filters(self._evaluator, self._context, position, origin_scope)
else:
return self._context.get_filters(search_global, self._position, origin_scope=origin_scope)