Skip to content

Commit 092d881

Browse files
committed
fixup how parts are expanded
1 parent 6fcbf0d commit 092d881

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

duckdb/template.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def param(value: object, name: str | None = None, *, exact: bool = False) -> Par
8080
return Param(value=value, name=name, exact=exact)
8181

8282

83-
def template(*part: str | IntoInterpolation | Param | SupportsDuckdbTemplate | object) -> SqlTemplate:
83+
def template(*parts: str | IntoInterpolation | Param | SupportsDuckdbTemplate | object) -> SqlTemplate:
8484
"""Convert a sequence of things into a SqlTemplate.
8585
8686
We go through the parts and convert it into a sequence of str and Interpolations,
@@ -146,7 +146,9 @@ def template(*part: str | IntoInterpolation | Param | SupportsDuckdbTemplate | o
146146
>>> t.compile()
147147
CompiledSql(sql='SELECT * FROM users WHERE id = $p0_id', params={'p0_id': 123})
148148
""" # noqa: E501
149-
expanded = _expand_part(part)
149+
expanded = []
150+
for part in parts:
151+
expanded.extend(_expand_part(part))
150152
return SqlTemplate(*expanded)
151153

152154

@@ -290,10 +292,7 @@ def assert_param_name_legal(name: str) -> None:
290292
class SqlTemplate:
291293
"""A sequence of strings and Interpolations."""
292294

293-
def __init__(
294-
self,
295-
*parts: str | IntoInterpolation,
296-
) -> None:
295+
def __init__(self, *parts: str | IntoInterpolation) -> None:
297296
self.strings, self.interpolations = parse_parts(parts)
298297

299298
def __iter__(self) -> Iterator[str | IntoInterpolation]:

tests/fast/test_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def test_repr(self):
779779
class TestEndToEndCompile:
780780
def test_plain_sql(self):
781781
result = template("SELECT * FROM users").compile()
782-
assert result == CompiledSql(sql="SELECT * FROM users", params={})
782+
assert result == CompiledSql("SELECT * FROM users", {})
783783

784784
def test_param_in_list(self):
785785
result = template(["SELECT * FROM users WHERE id = ", Param(value=5, name="id")]).compile()

0 commit comments

Comments
 (0)