From 0c6f7f66e9ffe66889e206857423adca15dc6df0 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 3 Mar 2013 15:49:49 +0100 Subject: [PATCH] Document get_names_of_scope with examples --- jedi/evaluate.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 1587ac09..421cc859 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -120,6 +120,39 @@ def get_names_of_scope(scope, position=None, star_search=True, Get all completions (names) possible for the current scope. The star search option is only here to provide an optimization. Otherwise the whole thing would probably start a little recursive madness. + + This function is used to include names from outer scopes. For example, + when the current scope is function: + + >>> from jedi.parsing import Parser + >>> parser = Parser(''' + ... x = ['a', 'b', 'c'] + ... def func(): + ... y = None + ... ''') + >>> scope = parser.scope.subscopes[0] + >>> scope + + + `get_names_of_scope` is a generator. First it yields names from + most inner scope. + + >>> pairs = list(get_names_of_scope(scope)) + >>> pairs[0] + (, []) + + Then it yield the names from one level outer scope. For this + example, this is the most outer scope. + + >>> pairs[1] + (, [, ]) + + Finally, it yields names from builtin, if `include_builtin` is + true (default). + + >>> pairs[2] #doctest: +ELLIPSIS + (, [, ...]) + """ in_func_scope = scope non_flow = scope.get_parent_until(pr.Flow, reverse=True)