code: def all_enclosing_scopes(scope, allow_global=True):
    
  
    _validate_full_scope(scope)
  
    # TODO: validate scopes here and/or in `enclosing_scope()` instead of assuming correctness.
    def scope_within_range(tentative_scope):
      if tentative_scope is None:
        return False
      if not allow_global and tentative_scope == GLOBAL_SCOPE:
        return False
      return True
  
    while scope_within_range(scope):
      yield scope
      scope = (None if scope == GLOBAL_SCOPE else enclosing_scope(scope))
docs: Utility function to return all scopes up to the global scope enclosing a
    given scope.