(cls, name, module, filter, source=None)
return cls
Create a new Enum subclass that replaces a collection of global constants
Create a new Enum subclass that replaces a collection of global constants
Create a new Enum subclass that replaces a collection of global constants
def _convert_(cls, name, module, filter, source=None):
        """
        Create a new Enum subclass that replaces a collection of global constants
        """
        # convert all constants from source (or module) that pass filter() to
        # a new Enum called name, and export the enum and its members back to
        # module;
        # also, replace the __reduce_ex__ method so unpickling works in
        # previous Python versions
        module_globals = vars(sys.modules[module])
        if source:
            source = vars(source)
        else:
            source = module_globals
        # _value2member_map_ is populated in the same order every time
        # for a consistent reverse mapping of number to name when there
        # are multiple names for the same number.
        members = [
                (name, value)
                for name, value in source.items()
                if filter(name)]
        try:
            # sort by value
            members.sort(key=lambda t: (t[1], t[0]))
        except TypeError:
            # unless some values aren't comparable, in which case sort by name
            members.sort(key=lambda t: t[0])
        cls = cls(name, members, module=module)
        cls.__reduce_ex__ = _reduce_ex_by_name
        module_globals.update(cls.__members__)
        module_globals[name] = cls
        return cls
def _convert_ ( cls , name , module , filter , source = None ) : # convert all constants from source (or module) that pass filter() to # a new Enum called name, and export the enum and its members back to # module; # also, replace the __reduce_ex__ method so unpickling works in # previous Python versions module_globals = vars ( sys . modules [ module ] ) if source : source = vars ( source ) else : source = module_globals # _value2member_map_ is populated in the same order every time # for a consistent reverse mapping of number to name when there # are multiple names for the same number. members = [ ( name , value ) for name , value in source . items ( ) if filter ( name ) ] try : # sort by value members . sort ( key = lambda t : ( t [ 1 ] , t [ 0 ] ) ) except TypeError : # unless some values aren't comparable, in which case sort by name members . sort ( key = lambda t : t [ 0 ] ) cls = cls ( name , members , module = module ) cls . __reduce_ex__ = _reduce_ex_by_name module_globals . update ( cls . __members__ ) module_globals [ name ] = cls return cls