Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions samtranslator/translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ def _get_function_names(
)
if not resolved_function_name:
continue
self.function_names.setdefault(api_name, "")
self.function_names[api_name] += str(resolved_function_name)
return self.function_names
# OLD APPROACH: String concatenation in loop
# self.function_names.setdefault(api_name, "")
# self.function_names[api_name] += str(resolved_function_name)
# NEW APPROACH: Collect in list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the comment with the old approach.

if api_name not in self.function_names:
self.function_names[api_name]=[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if api_name not in self.function_names:
self.function_names[api_name]=[]
self.function_names.setdefault(api_name, [])

self.function_names[api_name].append(str(resolved_function_name))
#backward compatibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is also probably unnecessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okayy

return {api: "".join(names) for api, names in self.function_names.items()}

def translate( # noqa: PLR0912, PLR0915
self,
Expand All @@ -127,7 +133,9 @@ def translate( # noqa: PLR0912, PLR0915
self.feature_toggle = feature_toggle or FeatureToggle(
FeatureToggleDefaultConfigProvider(), stage=None, account_id=None, region=None
)
self.function_names: Dict[Any, Any] = {}
# OLD: self.function_names: Dict[Any, Any] = {}
# NEW: Use List[str] for efficient accumulation, convert to str when needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion on commenting the old approach.

self.function_names: Dict[str, List[str]] = {}
self.redeploy_restapi_parameters = {}
sam_parameter_values = SamParameterValues(parameter_values)
sam_parameter_values.add_default_parameter_values(sam_template)
Expand Down
Loading