Skip to content

Commit 7c9e94b

Browse files
committed
style: use is_foreach_key() consistently in build_context
Three sites in build_context.py used hardcoded startswith("Fn::ForEach::") instead of the shared is_foreach_key() utility. Replaced for consistency with the rest of the codebase.
1 parent daf5a19 commit 7c9e94b

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

samcli/commands/build/build_context.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
sanitize_resource_key_for_mapping,
4242
substitute_loop_variable,
4343
)
44+
from samcli.lib.cfn_language_extensions.utils import is_foreach_key
4445
from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable
4546
from samcli.lib.providers.provider import LayerVersion, ResourcesToBuildCollector, Stack
4647
from samcli.lib.providers.sam_api_provider import SamApiProvider
@@ -493,7 +494,7 @@ def _update_original_template_paths(self, original_template: Dict, modified_temp
493494
# Process each resource in the original template
494495
for resource_key, resource_value in original_resources.items():
495496
# Check if this is a Fn::ForEach construct
496-
if resource_key.startswith("Fn::ForEach::"):
497+
if is_foreach_key(resource_key):
497498
generated_mappings = self._update_foreach_artifact_paths(
498499
resource_key,
499500
resource_value,
@@ -579,7 +580,7 @@ def _update_foreach_artifact_paths(
579580
dynamic_props_count = self._count_dynamic_properties(body, loop_variable, collection_values)
580581

581582
for resource_template_key, resource_template in body.items():
582-
if isinstance(resource_template_key, str) and resource_template_key.startswith("Fn::ForEach::"):
583+
if is_foreach_key(resource_template_key):
583584
nested_mappings = self._update_foreach_artifact_paths(
584585
resource_template_key,
585586
resource_template,
@@ -711,7 +712,7 @@ def _count_dynamic_properties(
711712

712713
count: Counter = Counter()
713714
for rtk, rt in body.items():
714-
if isinstance(rtk, str) and rtk.startswith("Fn::ForEach::"):
715+
if is_foreach_key(rtk):
715716
continue
716717
if not isinstance(rt, dict):
717718
continue

0 commit comments

Comments
 (0)