Python enum.auto() Examples

The following are 7 code examples of enum.auto(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module enum , or try the search function .
Example #1
Source File: operators.py    From lale with Apache License 2.0 6 votes vote down vote up
def __sort_topologically(self)->None:
        class state(enumeration.Enum):
            TODO=enumeration.auto(), 
            DOING=enumeration.auto(),
            DONE=enumeration.auto()
        
        states:Dict[OpType, state] = { op: state.TODO for op in self._steps }
        result:List[OpType] = [ ]

        def dfs(operator:OpType)->None:
            if states[operator] is state.DONE:
                return
            if states[operator] is state.DOING:
                raise ValueError('Cycle detected.')
            states[operator] = state.DOING
            for pred in self._preds[operator]:
                dfs(pred)
            states[operator] = state.DONE
            result.append(operator)
        
        for operator in self._steps:
            if states[operator] is state.TODO:
                dfs(operator)
        self._steps = result 
Example #2
Source File: utils.py    From vyper with Apache License 2.0 5 votes vote down vote up
def auto():
        return enum.auto()

    # Must be first, or else won't work, specifies what .value is 
Example #3
Source File: util_material.py    From building_tools with MIT License 5 votes vote down vote up
def add_faces_to_map(bm, faces, group, skip=None):
    """ Sets the face_map index of faces to the index of the face_map called
        group.name.lower()

        see map_new_faces for the option *skip*
    """
    face_map = bm.faces.layers.face_map.active
    group_index = face_map_index_from_name(group.name.lower())

    def remove_skipped(f):
        if skip:
            skip_index = face_map_index_from_name(skip.name.lower())
            return not (f[face_map] == skip_index)
        return True

    for face in list(filter(remove_skipped, faces)):
        face[face_map] = group_index

    obj = bpy.context.object

    # -- if auto uv map is set, perform UV Mapping for given faces
    if obj.facemap_materials[group_index].auto_map:
        map_method = obj.facemap_materials[group_index].uv_mapping_method
        uv_map_active_editmesh_selection(faces, map_method)

    # -- if the facemap already has a material assigned, assign the new faces to the material
    mat = obj.facemap_materials[group_index].material
    mat_id = [idx for idx, m in enumerate(obj.data.materials) if m == mat]
    if mat_id:
        for f in faces:
            f.material_index = mat_id[-1] 
Example #4
Source File: cmd_parse.py    From bayesmark with Apache License 2.0 5 votes vote down vote up
def filepath(value):
    """Work around for `pathvalidate` bug."""
    if value == ".":
        return value
    validate_filepath(value, platform="auto")
    return value 
Example #5
Source File: gui.py    From PUBGIS with GNU General Public License v3.0 5 votes vote down vote up
def _set_video_file(self, file_name):
        """
        Given a video file name, set the video_file_edit text to this file name and
        auto-fill the output file name as well.
        """
        if file_name:
            self.last_video_file_dir = os.path.dirname(file_name)
            self.video_file_edit.setText(QDir.toNativeSeparators(file_name))

            video_filename, _ = os.path.splitext(os.path.basename(file_name))

            self._set_output_file(os.path.join(self.last_output_file_dir,
                                               f"{video_filename}.jpg")) 
Example #6
Source File: script_layers.py    From pyrealtime with MIT License 5 votes vote down vote up
def auto() -> int:
        global __my_enum_auto_id
        i = __my_enum_auto_id
        __my_enum_auto_id += 1
        return i 
Example #7
Source File: test_misc.py    From napari with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_string_enum():
    # Make a test StringEnum
    class TestEnum(StringEnum):
        THING = auto()
        OTHERTHING = auto()

    # test setting by value, correct case
    assert TestEnum('thing') == TestEnum.THING

    # test setting by value mixed case
    assert TestEnum('thInG') == TestEnum.THING

    # test setting by instance of self
    assert TestEnum(TestEnum.THING) == TestEnum.THING

    # test setting by name correct case
    assert TestEnum['THING'] == TestEnum.THING

    # test setting by name mixed case
    assert TestEnum['tHiNg'] == TestEnum.THING

    # test setting by value with incorrect value
    with pytest.raises(ValueError):
        TestEnum('NotAThing')

    # test  setting by name with incorrect name
    with pytest.raises(KeyError):
        TestEnum['NotAThing']

    # test creating a StringEnum with the functional API
    animals = StringEnum('Animal', 'AARDVARK BUFFALO CAT DOG')
    assert str(animals.AARDVARK) == 'aardvark'
    assert animals('BUffALO') == animals.BUFFALO
    assert animals['BUffALO'] == animals.BUFFALO

    # test setting by instance of self
    class OtherEnum(StringEnum):
        SOMETHING = auto()

    #  test setting by instance of a different StringEnum is an error
    with pytest.raises(ValueError):
        TestEnum(OtherEnum.SOMETHING)