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:
parent
52b2913abe
commit
c55edcd97f
2 changed files with 120 additions and 1 deletions
|
|
@ -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_
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue