def iter_visible_scopes(self):
        outerScopes = itertools.islice(self.scope_stack, len(self.scope_stack) - 1)
        scopes = [scope for scope in outerScopes
                  if isinstance(scope, (FunctionScope, ModuleScope))]
        if (isinstance(self.scope, GeneratorScope)
            and scopes[-1] != self.scope_stack[-2]):
            scopes.append(self.scope_stack[-2])
        scopes.append(self.scope_stack[-1])
        return iter(reversed(scopes))