diff --git a/jedi/helpers.py b/jedi/helpers.py index a61027c5..6f748c8a 100644 --- a/jedi/helpers.py +++ b/jedi/helpers.py @@ -68,13 +68,19 @@ def check_arr_index(arr, pos): def array_for_pos(stmt, pos, array_types=None): """Searches for the array and position of a tuple""" def search_array(arr, pos): - for i, stmt in enumerate(arr): - new_arr, index = array_for_pos(stmt, pos, array_types) - if new_arr is not None: - return new_arr, index - if arr.start_pos < pos <= stmt.end_pos: - if not array_types or arr.type in array_types: - return arr, i + if arr.type == 'dict': + for stmt in arr.values + arr.keys: + new_arr, index = array_for_pos(stmt, pos, array_types) + if new_arr is not None: + return new_arr, index + else: + for i, stmt in enumerate(arr): + new_arr, index = array_for_pos(stmt, pos, array_types) + if new_arr is not None: + return new_arr, index + if arr.start_pos < pos <= stmt.end_pos: + if not array_types or arr.type in array_types: + return arr, i if len(arr) == 0 and arr.start_pos < pos < arr.end_pos: if not array_types or arr.type in array_types: return arr, 0 diff --git a/test/completion/arrays.py b/test/completion/arrays.py index 97d00ba4..5ab96cae 100644 --- a/test/completion/arrays.py +++ b/test/completion/arrays.py @@ -181,6 +181,11 @@ def f(): #? dict() f() + +# completion within dicts +#? 9 ['str'] +{str: str} + # ----------------- # with variable as index # -----------------