fix: resolve data keyword conflict in template formatting (#5483)

* fix: resolve data keyword conflict in template formatting

* refactor: simplify code

* test: add unit tests

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Ítalo Johnny 2024-12-31 10:13:31 -03:00 • committed by GitHub
commit c55edcd97f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 120 additions and 1 deletions

View file

@ -49,8 +49,13 @@ def data_to_text_list(template: str, data: Data | list[Data]) -> tuple[list[str]
Data(text=value) if not isinstance(value, Data) else value
for value in data
]
formatted_text = []
for value in data_:
# Prevent conflict with 'data' keyword in template formatting
kwargs = value.data.copy()
data = kwargs.pop("data", value.data)
formatted_text.append(template.format(data=data, **kwargs))
formatted_text = [template.format(data=value.data, **value.data) for value in data_]
return formatted_text, data_