code: def complete_scopes(cls, scope_infos):
      
      ret = {GlobalOptionsRegistrar.get_scope_info()}
      original_scopes = dict()
      for si in scope_infos:
        ret.add(si)
        if si.scope in original_scopes:
          raise cls.DuplicateScopeError('Scope `{}` claimed by {}, was also claimed by {}.'.format(
              si.scope, si, original_scopes[si.scope]
            ))
        original_scopes[si.scope] = si
        if si.deprecated_scope:
          ret.add(ScopeInfo(si.deprecated_scope, si.category, si.optionable_cls))
          original_scopes[si.deprecated_scope] = si
  
      # TODO: Once scope name validation is enforced (so there can be no dots in scope name
      # components) we can replace this line with `for si in scope_infos:`, because it will
      # not be possible for a deprecated_scope to introduce any new intermediate scopes.
      for si in copy.copy(ret):
        for scope in all_enclosing_scopes(si.scope, allow_global=False):
          if scope not in original_scopes:
            ret.add(ScopeInfo(scope, ScopeInfo.INTERMEDIATE))
      return ret
docs: Expand a set of scopes to include all enclosing scopes.
  
      E.g., if the set contains `foo.bar.baz`, ensure that it also contains `foo.bar` and `foo`.
  
      Also adds any deprecated scopes.