本文整理匯總了Python中typing.NamedTuple方法的典型用法代碼示例。如果您正苦於以下問題:Python typing.NamedTuple方法的具體用法?Python typing.NamedTuple怎麽用?Python typing.NamedTuple使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類typing
的用法示例。
在下文中一共展示了typing.NamedTuple方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def init(settings: NamedTuple) -> None:
"""Initialize settings."""
GuffinRun.max_rb_duration = settings.max_rb_duration
GuffinRun.zone = settings.zone
GuffinRun.gold_zone = settings.gold_zone
GuffinRun.hacks = settings.hacks
GuffinRun.diggers = settings.diggers
GuffinRun.butter = settings.butter
GuffinRun.aug = settings.aug
GuffinRun.allocate_wishes = settings.allocate_wishes
GuffinRun.wandoos_version = settings.wandoos_version
GuffinRun.wish_min_time = settings.wish_min_time
GuffinRun.wish_slots = settings.wish_slots
if GuffinRun.allocate_wishes:
GuffinRun.wishes = Wishes(GuffinRun.wish_slots, GuffinRun.wish_min_time)
lst = [GuffinRun.wishes.epow, GuffinRun.wishes.mpow, GuffinRun.wishes.rpow]
i = 0
while 1 in lst:
print("OCR reading failed for stat breakdowns, trying again...")
GuffinRun.wishes = Wishes(GuffinRun.wish_slots, GuffinRun.wish_min_time)
i += 1
if i > 5:
print("Wishes will be disabled.")
GuffinRun.wishes = None
break
示例2: construct_record_manager
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def construct_record_manager(
self,
record_class: Optional[type],
sequenced_item_class: Optional[Type[NamedTuple]] = None,
**kwargs: Any
) -> AbstractRecordManager:
"""
Constructs SQLAlchemy record manager.
:return: An SQLAlchemy record manager.
:rtype: SQLAlchemyRecordManager
"""
return super(SQLAlchemyInfrastructureFactory, self).construct_record_manager(
record_class,
sequenced_item_class=sequenced_item_class,
session=self.session,
**kwargs
)
示例3: __init__
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def __init__(
self,
record_manager: AbstractRecordManager,
sequence_id: UUID,
gt: Optional[int] = None,
gte: Optional[int] = None,
lt: Optional[int] = None,
lte: Optional[int] = None,
page_size: Optional[int] = None,
is_ascending: bool = True,
*args: Any,
**kwargs: Any
):
super(GetEntityEventsThread, self).__init__(*args, **kwargs)
assert isinstance(record_manager, BaseRecordManager), type(record_manager)
self.record_manager = record_manager
self.stored_entity_id = sequence_id
self.gt = gt
self.gte = gte
self.lt = lt
self.lte = lte
self.page_size = page_size
self.is_ascending = is_ascending
self.stored_events: List[NamedTuple] = []
示例4: construct_record_manager
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def construct_record_manager(
self,
record_class: Optional[type],
sequenced_item_class: Optional[Type[NamedTuple]] = None,
**kwargs: Any
) -> AbstractRecordManager:
"""
Constructs an record manager.
"""
assert self.record_manager_class is not None
return self.record_manager_class(
sequenced_item_class=sequenced_item_class or self.sequenced_item_class,
record_class=record_class,
contiguous_record_ids=self.contiguous_record_ids,
application_name=self.application_name,
pipeline_id=self.pipeline_id,
**kwargs
)
示例5: construct_record_manager
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def construct_record_manager(
self,
record_class: Optional[type],
sequenced_item_class: Optional[Type[NamedTuple]] = None,
**kwargs: Any
) -> AbstractRecordManager:
"""
Constructs Axon record manager.
:return: An Axon record manager.
:rtype: AxonRecordManager
"""
return super(AxonInfrastructureFactory, self).construct_record_manager(
record_class,
sequenced_item_class=sequenced_item_class,
axon_client=self.axon_client,
**kwargs
)
示例6: get_active_project_dirs
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def get_active_project_dirs() -> NamedTuple:
"""
Get activation project directories
Returns
-------
project_dirs
project directories
Raises
------
ValueError
if no project was created
"""
_raise_if_no_active_project()
return _ActiveProject.project_dirs
示例7: _replace_typed_class
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def _replace_typed_class(
tokens: List[Token],
i: int,
call: ast.Call,
types: Dict[str, ast.expr],
) -> None:
if i > 0 and tokens[i - 1].name in {'INDENT', UNIMPORTANT_WS}:
indent = f'{tokens[i - 1].src}{" " * 4}'
else:
indent = ' ' * 4
# NT = NamedTuple("nt", [("a", int)])
# ^i ^end
end = i + 1
while end < len(tokens) and tokens[end].name != 'NEWLINE':
end += 1
attrs = '\n'.join(f'{indent}{k}: {_unparse(v)}' for k, v in types.items())
src = f'class {tokens[i].src}({_unparse(call.func)}):\n{attrs}'
tokens[i:end] = [Token('CODE', src)]
示例8: execute
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def execute(args: typing.NamedTuple):
if not args.toolkit_software:
return print_available_softwares()
if not validate_software(args.toolkit_software):
return None
if not args.version:
return print_available_software_version(args.toolkit_software)
if not args.environment:
print_available_environments(args.toolkit_software)
toolkit = Toolkit(software=args.toolkit_software, version=args.version, environment=args.environment)
toolkit.validate()
log.info("Docker image picked for this toolkit: %s", toolkit.get_docker_repo(args.gpu))
return None
示例9: execute
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def execute(args: typing.NamedTuple):
spark_client = aztk.spark.Client(config.load_aztk_secrets())
cluster_ids = args.cluster_ids
for cluster_id in cluster_ids:
if not args.force:
if not args.keep_logs:
log.warning("All logs persisted for this cluster will be deleted.")
confirmation_cluster_id = input(
"Please confirm the id of the cluster you wish to delete [{}]: ".format(cluster_id))
if confirmation_cluster_id != cluster_id:
log.error("Confirmation cluster id does not match. Please try again.")
return
if spark_client.cluster.delete(id=cluster_id, keep_logs=args.keep_logs):
log.info("Deleting cluster %s", cluster_id)
else:
log.error("Cluster with id '%s' doesn't exist or was already deleted.", cluster_id)
示例10: execute
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def execute(args: typing.NamedTuple):
actions = {}
actions[ClusterAction.create] = cluster_create.execute
actions[ClusterAction.add_user] = cluster_add_user.execute
actions[ClusterAction.delete] = cluster_delete.execute
actions[ClusterAction.get] = cluster_get.execute
actions[ClusterAction.list] = cluster_list.execute
actions[ClusterAction.ssh] = cluster_ssh.execute
actions[ClusterAction.submit] = cluster_submit.execute
actions[ClusterAction.app_logs] = cluster_app_logs.execute
actions[ClusterAction.run] = cluster_run.execute
actions[ClusterAction.copy] = cluster_copy.execute
actions[ClusterAction.debug] = cluster_debug.execute
func = actions[args.cluster_action]
func(args)
示例11: execute
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def execute(args: typing.NamedTuple):
spark_client = aztk.spark.Client(config.load_aztk_secrets())
log.info("-------------------------------------------")
log.info("spark cluster id: %s", args.cluster_id)
log.info("username: %s", args.username)
log.info("-------------------------------------------")
if args.ssh_key:
ssh_key = args.ssh_key
else:
ssh_key = spark_client.secrets_configuration.ssh_pub_key
ssh_key, password = utils.get_ssh_key_or_prompt(ssh_key, args.username, args.password,
spark_client.secrets_configuration)
spark_client.cluster.create_user(id=args.cluster_id, username=args.username, password=password, ssh_key=ssh_key)
if password:
log.info("password: %s", "*" * len(password))
elif ssh_key:
log.info("ssh public key: %s", ssh_key)
log.info("-------------------------------------------")
示例12: task_step
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def task_step(self, sim: Simulation, action: Sequence[float], sim_steps: int) \
-> Tuple[NamedTuple, float, bool, Dict]:
# input actions
for prop, command in zip(self.action_variables, action):
sim[prop] = command
# run simulation
for _ in range(sim_steps):
sim.run()
self._update_custom_properties(sim)
state = self.State(*(sim[prop] for prop in self.state_variables))
done = self._is_terminal(sim)
reward = self.assessor.assess(state, self.last_state, done)
if done:
reward = self._reward_terminal_override(reward, sim)
if self.debug:
self._validate_state(state, done, action, reward)
self._store_reward(reward, sim)
self.last_state = state
info = {'reward': reward}
return state, reward.agent_reward(), done, info
示例13: from_name_behavior_id
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def from_name_behavior_id(name_behavior_id: str) -> "BehaviorIdentifiers":
"""
Parses a name_behavior_id of the form name?team=0
into a BehaviorIdentifiers NamedTuple.
This allows you to access the brain name and team id of an agent
:param name_behavior_id: String of behavior params in HTTP format.
:returns: A BehaviorIdentifiers object.
"""
parsed = urlparse(name_behavior_id)
name = parsed.path
ids = parse_qs(parsed.query)
team_id: int = 0
if "team" in ids:
team_id = int(ids["team"][0])
return BehaviorIdentifiers(
behavior_id=name_behavior_id, brain_name=name, team_id=team_id
)
示例14: should_render_obj
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def should_render_obj(self):
"""Whether the object values should be rendered in the TransactItem"""
return self.type not in {TxType.Check, TxType.Get}
# hack to get around NamedTuple field docstrings renaming:
# https://stackoverflow.com/a/39320627
示例15: construct_sqlalchemy_eventstore
# 需要導入模塊: import typing [as 別名]
# 或者: from typing import NamedTuple [as 別名]
def construct_sqlalchemy_eventstore(
session: Any,
sequenced_item_class: Optional[Type[NamedTuple]] = None,
sequence_id_attr_name: Optional[str] = None,
position_attr_name: Optional[str] = None,
json_encoder_class: Optional[Type[ObjectJSONEncoder]] = None,
json_decoder_class: Optional[Type[ObjectJSONDecoder]] = None,
cipher: Optional[AESCipher] = None,
record_class: Optional[type] = None,
contiguous_record_ids: bool = False,
application_name: Optional[str] = None,
pipeline_id: int = DEFAULT_PIPELINE_ID,
) -> EventStore:
sequenced_item_class = sequenced_item_class or StoredEvent # type: ignore
sequenced_item_mapper = SequencedItemMapper[DomainEvent](
sequenced_item_class=sequenced_item_class,
sequence_id_attr_name=sequence_id_attr_name,
position_attr_name=position_attr_name,
json_encoder_class=json_encoder_class,
json_decoder_class=json_decoder_class,
cipher=cipher,
)
factory = SQLAlchemyInfrastructureFactory(
session=session,
integer_sequenced_record_class=record_class or StoredEventRecord,
sequenced_item_class=sequenced_item_class,
contiguous_record_ids=contiguous_record_ids,
application_name=application_name,
pipeline_id=pipeline_id,
)
record_manager = factory.construct_integer_sequenced_record_manager()
event_store = EventStore[DomainEvent, AbstractRecordManager](
record_manager=record_manager, event_mapper=sequenced_item_mapper
)
return event_store