当前位置: 首页>>代码示例>>Python>>正文


Python dataclasses.replace方法代码示例

本文整理汇总了Python中dataclasses.replace方法的典型用法代码示例。如果您正苦于以下问题:Python dataclasses.replace方法的具体用法?Python dataclasses.replace怎么用?Python dataclasses.replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dataclasses的用法示例。


在下文中一共展示了dataclasses.replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: expr_to_cpp

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def expr_to_cpp(expr: ir0.Expr,
                context: Context) -> str:
    if isinstance(expr, ir0.Literal):
        return literal_to_cpp(expr)
    elif isinstance(expr, ir0.ComparisonExpr):
        return comparison_expr_to_cpp(expr, context)
    elif isinstance(expr, ir0.NotExpr):
        return not_expr_to_cpp(expr, context)
    elif isinstance(expr, ir0.UnaryMinusExpr):
        return unary_minus_expr_to_cpp(expr, context)
    elif isinstance(expr, ir0.Int64BinaryOpExpr):
        return int64_binary_op_expr_to_cpp(expr, context)
    elif isinstance(expr, ir0.BoolBinaryOpExpr):
        return bool_binary_op_expr_to_cpp(expr, context)
    else:
        writer = ExprWriter(context.writer)
        type_expr_to_cpp(expr, dataclasses.replace(context, writer=writer))
        return ''.join(writer.strings) 
开发者ID:google,项目名称:tmppy,代码行数:20,代码来源:_ir0_to_cpp.py

示例2: unwrap_traj

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def unwrap_traj(traj: types.TrajectoryWithRew) -> types.TrajectoryWithRew:
    """Uses `RolloutInfoWrapper`-captured `obs` and `rews` to replace fields.

    This can be useful for bypassing other wrappers to retrieve the original
    `obs` and `rews`.

    Fails if `infos` is None or if the trajectory was generated from an
    environment without imitation.util.rollout.RolloutInfoWrapper

    Args:
      traj: A trajectory generated from `RolloutInfoWrapper`-wrapped Environments.

    Returns:
      A copy of `traj` with replaced `obs` and `rews` fields.
    """
    ep_info = traj.infos[-1]["rollout"]
    res = dataclasses.replace(traj, obs=ep_info["obs"], rews=ep_info["rews"])
    assert len(res.obs) == len(res.acts) + 1
    assert len(res.rews) == len(res.acts)
    return res 
开发者ID:HumanCompatibleAI,项目名称:imitation,代码行数:22,代码来源:rollout.py

示例3: update

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def update(
        self,
        width: int = None,
        min_width: int = None,
        max_width: int = None,
        justify: JustifyMethod = None,
        overflow: OverflowMethod = None,
        no_wrap: bool = None,
    ) -> "ConsoleOptions":
        """Update values, return a copy."""
        options = replace(self)
        if width is not None:
            options.min_width = options.max_width = width
        if min_width is not None:
            options.min_width = min_width
        if max_width is not None:
            options.max_width = max_width
        if justify is not None:
            options.justify = justify
        if overflow is not None:
            options.overflow = overflow
        if no_wrap is not None:
            options.no_wrap = no_wrap
        return options 
开发者ID:willmcgugan,项目名称:rich,代码行数:26,代码来源:console.py

示例4: get_cityscapes_hyperparams_small

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def get_cityscapes_hyperparams_small(width_multiplier=1.0, num_classes=19, init_channels=16, mid_channels=128,
                                     skip_output_block_index=7, last_conv_channels=256):
    block_hyperparams = (InvertResidualNetBlockMetaHyperparameters(num_channels=16, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=24, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=40, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=48, num_repeat=4, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=96, num_repeat=4, stride=1),)
    if width_multiplier != 1.0:
        block_hyperparams = tuple(
            dataclasses.replace(meta_block, num_channels=round(meta_block.num_channels * width_multiplier))
            for meta_block in block_hyperparams)
    hyperparams = SqueezeNASNetCityscapesHyperparameters(init_channels=init_channels, blocks=block_hyperparams,
                                                         num_classes=num_classes,
                                                         skip_output_block_index=skip_output_block_index,
                                                         mid_channels=mid_channels, last_channels=last_conv_channels)
    return hyperparams 
开发者ID:ashaw596,项目名称:squeezenas,代码行数:18,代码来源:hyperparameters.py

示例5: get_cityscapes_hyperparams_large

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def get_cityscapes_hyperparams_large(width_multiplier=1.0, num_classes=19, init_channels=16, mid_channels=128,
                                     final_width_multiplier=0.5, skip_output_block_index=8):
    block_hyperparams = (InvertResidualNetBlockMetaHyperparameters(num_channels=16, num_repeat=1, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=24, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=32, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=64, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=96, num_repeat=4, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=160, num_repeat=4, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=round(320 * final_width_multiplier),
                                                                   num_repeat=1, stride=1),)
    if width_multiplier != 1.0:
        block_hyperparams = tuple(
            dataclasses.replace(meta_block, num_channels=round(meta_block.num_channels * width_multiplier))
            for meta_block in block_hyperparams)
    hyperparams = SqueezeNASNetCityscapesHyperparameters(init_channels=init_channels, blocks=block_hyperparams,
                                                         num_classes=num_classes,
                                                         skip_output_block_index=skip_output_block_index,
                                                         mid_channels=mid_channels)
    return hyperparams 
开发者ID:ashaw596,项目名称:squeezenas,代码行数:21,代码来源:hyperparameters.py

示例6: get_cityscapes_hyperparams_xlarge

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def get_cityscapes_hyperparams_xlarge(width_multiplier=1.0, num_classes=19, init_channels=48, mid_channels=160,
                                      final_width_multiplier=1.0, skip_output_block_index=4):
    block_hyperparams = (InvertResidualNetBlockMetaHyperparameters(num_channels=24, num_repeat=1, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=32, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=48, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=96, num_repeat=4, stride=2),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=144, num_repeat=4, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=240, num_repeat=4, stride=1),
                         InvertResidualNetBlockMetaHyperparameters(num_channels=round(320 * final_width_multiplier),
                                                                   num_repeat=1, stride=1),)
    if width_multiplier != 1.0:
        block_hyperparams = tuple(
            dataclasses.replace(meta_block, num_channels=round(meta_block.num_channels * width_multiplier))
            for meta_block in block_hyperparams)
    hyperparams = SqueezeNASNetCityscapesHyperparameters(init_channels=init_channels, blocks=block_hyperparams,
                                                         num_classes=num_classes,
                                                         skip_output_block_index=skip_output_block_index,
                                                         mid_channels=mid_channels)
    return hyperparams 
开发者ID:ashaw596,项目名称:squeezenas,代码行数:21,代码来源:hyperparameters.py

示例7: mkoverride

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def mkoverride(
        cls,
        other,
        *,
        uuid: uuid.UUID = None,
        name: str = None,
        url: URL = None,
        license: License = None,
        extra: Dict[str, object] = {},
    ):
        new_extra = other.extra.copy()
        new_extra.update(extra)
        return dataclasses.replace(
            other,
            uuid=uuid if uuid else other.uuid,
            name=name if name else other.name,
            url=url if url else other.url,
            license=license if license else other.license,
            extra=new_extra,
        ) 
开发者ID:intel,项目名称:dffml,代码行数:22,代码来源:base.py

示例8: _edit_case

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def _edit_case(case: OeciCase, case_edits) -> Tuple[OeciCase, List[Charge]]:
        case_summary_edits: Dict[str, Any] = {}
        for key, value in case_edits["summary"].items():
            if key == "edit_status":
                case_summary_edits["edit_status"] = EditStatus(value)
            if key == "date":
                case_summary_edits["date"] = date_class.fromdatetime(datetime.strptime(value, "%m/%d/%Y"))
            elif key == "balance_due":
                case_summary_edits["balance_due_in_cents"] = CaseCreator.compute_balance_due_in_cents(value)
            elif key == "birth_year":
                case_summary_edits["birth_year"] = int(value)
            else:
                case_summary_edits[key] = value
        edited_summary = replace(case.summary, **case_summary_edits)
        new_charges: List[Charge] = []
        if case_summary_edits["edit_status"] == EditStatus.DELETE:
            edited_charges = RecordEditor._mark_charges_as_deleted(case.charges)
        elif "charges" in case_edits.keys():
            edited_charges, new_charges = RecordEditor._edit_charges(
                case.summary.case_number, case.charges, case_edits["charges"]
            )
        else:
            edited_charges = case.charges
        return OeciCase(edited_summary, edited_charges), new_charges 
开发者ID:codeforpdx,项目名称:recordexpungPDX,代码行数:26,代码来源:record_editor.py

示例9: _update_or_delete_charge

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def _update_or_delete_charge(charges, case_number, edit_action_ambiguous_charge_id, edit) -> OeciCharge:
        charge = next((charge for charge in charges if charge.ambiguous_charge_id == edit_action_ambiguous_charge_id))
        charge_dict = RecordEditor._parse_charge_edits(edit)
        charge_type_string = charge_dict.pop("charge_type", None)
        edited_oeci_charge = replace(charge, **charge_dict)
        if charge_type_string:
            charge_type_data = {
                "id": f"{charge.ambiguous_charge_id}-0",
                "case_number": case_number,
                "charge_type": RecordEditor._get_charge_type(charge_type_string),
                **asdict(edited_oeci_charge),
            }
            new_charge = from_dict(data_class=Charge, data=charge_type_data)
            return new_charge
        else:
            return edited_oeci_charge 
开发者ID:codeforpdx,项目名称:recordexpungPDX,代码行数:18,代码来源:record_editor.py

示例10: with_context

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def with_context(self, *, collisions: FrozenSet[str]) -> 'Field':
        """Return a derivative of this field with the provided context.

        This method is used to address naming collisions. The returned
        ``Field`` object aliases module names to avoid naming collisions
        in the file being written.
        """
        return dataclasses.replace(
            self,
            message=self.message.with_context(
                collisions=collisions,
                skip_fields=True,
            ) if self.message else None,
            enum=self.enum.with_context(collisions=collisions)
            if self.enum else None,
            meta=self.meta.with_context(collisions=collisions),
        ) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:19,代码来源:wrappers.py

示例11: child

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def child(self, child_name: str, path: Tuple[int, ...]) -> 'Address':
        """Return a new child of the current Address.

        Args:
            child_name (str): The name of the child node.
                This address' name is appended to ``parent``.

        Returns:
            ~.Address: The new address object.
        """
        return dataclasses.replace(
            self,
            module_path=self.module_path + path,
            name=child_name,
            parent=self.parent + (self.name,) if self.name else self.parent,
        ) 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:18,代码来源:metadata.py

示例12: subpackages

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def subpackages(self) -> Mapping[str, 'API']:
        """Return a map of all subpackages, if any.

        Each value in the mapping is another API object, but the ``protos``
        property only shows protos belonging to the subpackage.
        """
        answer: Dict[str, API] = collections.OrderedDict()

        # Get the actual subpackages we have.
        #
        # Note that this intentionally only goes one level deep; nested
        # subpackages can be accessed by requesting subpackages of the
        # derivative API objects returned here.
        level = len(self.subpackage_view)
        for subpkg_name in sorted({p.meta.address.subpackage[0]
                                   for p in self.protos.values()
                                   if len(p.meta.address.subpackage) > level and
                                   p.meta.address.subpackage[:level] == self.subpackage_view}):
            answer[subpkg_name] = dataclasses.replace(self,
                                                      subpackage_view=self.subpackage_view +
                                                      (subpkg_name,),
                                                      )
        return answer 
开发者ID:googleapis,项目名称:gapic-generator-python,代码行数:25,代码来源:api.py

示例13: test_reach_size_from_start

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def test_reach_size_from_start(echoes_game_description, default_layout_configuration):
    # Setup
    layout_configuration = dataclasses.replace(
        default_layout_configuration,
        trick_level_configuration=TrickLevelConfiguration(LayoutTrickLevel.HYPERMODE),
    )
    player_pool = generator.create_player_pool(Random(15000), layout_configuration, 0)

    game, state = logic_bootstrap(layout_configuration, player_pool.game, player_pool.patches)

    # Run
    reach = GeneratorReach.reach_from_state(game, state)

    # Assert
    assert len(list(reach.nodes)) == 44
    assert len(list(reach.safe_nodes)) == 5 
开发者ID:randovania,项目名称:randovania,代码行数:18,代码来源:test_generator_reach.py

示例14: test_add_elevator_connections_to_patches_vanilla

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def test_add_elevator_connections_to_patches_vanilla(echoes_game_data,
                                                     skip_final_bosses: bool,
                                                     default_layout_configuration):
    # Setup
    game = data_reader.decode_data(echoes_game_data)
    expected = dataclasses.replace(game.create_game_patches())
    if skip_final_bosses:
        expected.elevator_connection[136970379] = AreaLocation(1006255871, 1393588666)

    # Run
    result = base_patches_factory.add_elevator_connections_to_patches(
        dataclasses.replace(default_layout_configuration, skip_final_bosses=skip_final_bosses),
        Random(0),
        game.create_game_patches())

    # Assert
    assert result == expected 
开发者ID:randovania,项目名称:randovania,代码行数:19,代码来源:test_base_patches_factory.py

示例15: test_edit_layout_trick_level

# 需要导入模块: import dataclasses [as 别名]
# 或者: from dataclasses import replace [as 别名]
def test_edit_layout_trick_level(editor: PresetEditor,
                                 initial_layout_configuration_params: dict,
                                 default_layout_configuration,
                                 new_trick_level: LayoutTrickLevel):
    # Setup
    editor._layout_configuration = dataclasses.replace(default_layout_configuration,
                                                       **initial_layout_configuration_params)
    editor._nested_autosave_level = 1

    # Run
    initial_layout_configuration_params["trick_level_configuration"] = TrickLevelConfiguration(new_trick_level)
    editor.set_layout_configuration_field("trick_level_configuration", TrickLevelConfiguration(new_trick_level))

    # Assert
    assert editor.layout_configuration == dataclasses.replace(default_layout_configuration,
                                                              **initial_layout_configuration_params) 
开发者ID:randovania,项目名称:randovania,代码行数:18,代码来源:test_preset_editor.py


注:本文中的dataclasses.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。