本文整理匯總了Python中enum.Flag方法的典型用法代碼示例。如果您正苦於以下問題:Python enum.Flag方法的具體用法?Python enum.Flag怎麽用?Python enum.Flag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類enum
的用法示例。
在下文中一共展示了enum.Flag方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wait_flag
# 需要導入模塊: import enum [as 別名]
# 或者: from enum import Flag [as 別名]
def wait_flag(
flag: Optional[Flag],
) -> Any:
"""
Wait for a flag to be raised.
Non-asyncio primitives are generally not our worry,
but we support them for convenience.
"""
if flag is None:
pass
elif isinstance(flag, asyncio.Future):
return await flag
elif isinstance(flag, asyncio.Event):
return await flag.wait()
elif isinstance(flag, concurrent.futures.Future):
loop = asyncio.get_running_loop()
return await loop.run_in_executor(None, flag.result)
elif isinstance(flag, threading.Event):
loop = asyncio.get_running_loop()
return await loop.run_in_executor(None, flag.wait)
else:
raise TypeError(f"Unsupported type of a flag: {flag!r}")
示例2: raise_flag
# 需要導入模塊: import enum [as 別名]
# 或者: from enum import Flag [as 別名]
def raise_flag(
flag: Optional[Flag],
) -> None:
"""
Raise a flag.
Non-asyncio primitives are generally not our worry,
but we support them for convenience.
"""
if flag is None:
pass
elif isinstance(flag, asyncio.Future):
flag.set_result(None)
elif isinstance(flag, asyncio.Event):
flag.set()
elif isinstance(flag, concurrent.futures.Future):
flag.set_result(None)
elif isinstance(flag, threading.Event):
flag.set()
else:
raise TypeError(f"Unsupported type of a flag: {flag!r}")
示例3: group_by_contract
# 需要導入模塊: import enum [as 別名]
# 或者: from enum import Flag [as 別名]
def group_by_contract(plugins: Iterable[Plugin]) -> DefaultDict[Contract, List[Plugin]]:
"""
Groups plugins in lists according to their contracts.
Each plugin is found in as many lists as it implements base contracts.
Lists keep the order of the original plugins iterable.
"""
res = defaultdict(list)
for p in plugins:
c = contract(p)
for bc in _BASE_CONTRACTS:
if c & bc: # Contract is an enum.Flag: & computes the intersection.
res[bc].append(p)
return res