diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 6f63acc8..5c327d25 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -322,6 +322,13 @@ class Evaluator(object): # This is the first global lookup. stmt = atom.get_definition() scope = stmt.get_parent_until(tree.IsScope, include_current=True) + if isinstance(scope, (tree.Function, er.FunctionExecution)): + # Adjust scope: If the name is not in the suite, it's a param + # default or annotation and will be resolved as part of the + # parent scope. + colon = scope.children.index(':') + if atom.start_pos < scope.children[colon + 1].start_pos: + scope = scope.get_parent_scope() if isinstance(stmt, tree.CompFor): stmt = stmt.get_parent_until((tree.ClassOrFunc, tree.ExprStmt)) if stmt.type != 'expr_stmt': diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index d8948f47..85ab98b0 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -37,7 +37,9 @@ def _evaluate_for_annotation(evaluator, annotation): if element is None: debug.warning('Annotation not parsed: %s' % definition.obj) else: - element.parent = annotation.parent + module = annotation.get_parent_until() + p.position_modifier.line = module.end_pos[0] + element.parent = module definitions |= evaluator.eval_element(element) else: definitions.add(definition) diff --git a/test/completion/functions.py b/test/completion/functions.py index 6ef20c6b..d444ff97 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -178,6 +178,23 @@ nested_default(a=1.0)[1] #? str() nested_default(a=1.0, b='')[1] +# Defaults should only work if they are defined before - not after. +def default_function(a=default): + #? + return a + +#? +default_function() + +default = int() + +def default_function(a=default): + #? int() + return a + +#? int() +default_function() + # ----------------- # closures diff --git a/test/completion/pep0484.py b/test/completion/pep0484.py index a090b7fa..fc08460f 100644 --- a/test/completion/pep0484.py +++ b/test/completion/pep0484.py @@ -137,9 +137,7 @@ function_with_non_pep_0484_annotation(1, 2, 3, "force string") def function_forward_reference_dynamic( x: return_str_type(), y: "return_str_type()") -> None: - # technically should not be resolvable since out of scope, - # but jedi is not smart enough for that - #? str() + #? x #? str() y