Replace list comprehension with generator. (#5526)

# Replace list comprehension with generator.

Since these strings can be fairly long, it's best to not construct
unnecessary temporary list just to pass it to `join`. Generators produce
items one-by-one and even though they are slightly more expensive than
lists in terms of CPU they are much more memory-friendly and slightly
more readable.
This commit is contained in:
Taras Tsugrii 2023-05-31 17:10:43 -05:00 committed by GitHub
parent 4c8aad0d1b
commit 359fb8fa3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,10 +35,8 @@ class CombiningOutputParser(BaseOutputParser):
initial = f"For your first output: {self.parsers[0].get_format_instructions()}" initial = f"For your first output: {self.parsers[0].get_format_instructions()}"
subsequent = "\n".join( subsequent = "\n".join(
[
f"Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}" # noqa: E501 f"Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}" # noqa: E501
for p in self.parsers[1:] for p in self.parsers[1:]
]
) )
return f"{initial}\n{subsequent}" return f"{initial}\n{subsequent}"