本文整理匯總了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)