code: def _componentSortKey(componentAndType):
          
          component, asn1Spec = componentAndType
  
          if asn1Spec is None:
              compType = component
          else:
              compType = asn1Spec
  
          if compType.typeId == univ.Choice.typeId and not compType.tagSet:
              if asn1Spec is None:
                  return component.getComponent().tagSet
              else:
                  # TODO: move out of sorting key function
                  names = [namedType.name for namedType in asn1Spec.componentType.namedTypes
                           if namedType.name in component]
                  if len(names) != 1:
                      raise error.PyAsn1Error(
                          '%s components for Choice at %r' % (len(names) and 'Multiple ' or 'None ', component))
  
                  # TODO: support nested CHOICE ordering
                  return asn1Spec[names[0]].tagSet
  
          else:
              return compType.tagSet
docs: Sort SET components by tag
  
          Sort depending on the actual Choice value (dynamic sort)