本文整理汇总了Python中enum.auto方法的典型用法代码示例。如果您正苦于以下问题:Python enum.auto方法的具体用法?Python enum.auto怎么用?Python enum.auto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enum
的用法示例。
在下文中一共展示了enum.auto方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __sort_topologically
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
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
示例2: auto
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
def auto():
return enum.auto()
# Must be first, or else won't work, specifies what .value is
示例3: add_faces_to_map
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
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]
示例4: filepath
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
def filepath(value):
"""Work around for `pathvalidate` bug."""
if value == ".":
return value
validate_filepath(value, platform="auto")
return value
示例5: _set_video_file
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
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"))
示例6: auto
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
def auto() -> int:
global __my_enum_auto_id
i = __my_enum_auto_id
__my_enum_auto_id += 1
return i
示例7: test_string_enum
# 需要导入模块: import enum [as 别名]
# 或者: from enum import auto [as 别名]
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)