Skip to content

Commit 28f6e2b

Browse files
chore(internal): fix bug with transform utility & key aliases (#7)
1 parent 1b728b4 commit 28f6e2b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/finch/_utils/_transform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _maybe_transform_key(key: str, type_: type) -> str:
115115
return key
116116

117117
# ignore the first argument as it is the actual type
118-
annotations = get_args(type_)[1:]
118+
annotations = get_args(annotated_type)[1:]
119119
for annotation in annotations:
120120
if isinstance(annotation, PropertyInfo) and annotation.alias is not None:
121121
return annotation.alias

tests/test_transform.py

+9
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,12 @@ def test_datetime_custom_format() -> None:
177177

178178
result = transform(dt, Annotated[datetime, PropertyInfo(format="custom", format_template="%H")])
179179
assert result == "06" # type: ignore[comparison-overlap]
180+
181+
182+
class DateDictWithRequiredAlias(TypedDict, total=False):
183+
required_prop: Required[Annotated[date, PropertyInfo(format="iso8601", alias="prop")]]
184+
185+
186+
def test_datetime_with_alias() -> None:
187+
assert transform({"required_prop": None}, DateDictWithRequiredAlias) == {"prop": None} # type: ignore[comparison-overlap]
188+
assert transform({"required_prop": date.fromisoformat("2023-02-23")}, DateDictWithRequiredAlias) == {"prop": "2023-02-23"} # type: ignore[comparison-overlap]

0 commit comments

Comments
 (0)