Skip to content

Commit cd3d61b

Browse files
authored
Merge pull request #35 from franccesco/dream/2026-07-23.1/finding-015
dream: PEP 695 type aliases for pydantic Annotated types
2 parents 997d52b + 6e4e183 commit cd3d61b

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ requires-python = ">=3.12"
88
dependencies = [
99
"httpx>=0.27.0",
1010
"pyyaml>=6.0",
11-
"pydantic>=2.0.0",
11+
"pydantic>=2.11.0",
1212
]
1313

1414
[project.optional-dependencies]

src/bloomy/models.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ def _parse_optional_float(v: Any) -> float | None:
3333
return float(v)
3434

3535

36-
# Reusable annotated types for optional fields that may come as empty strings
37-
OptionalDatetime = Annotated[datetime | None, BeforeValidator(_parse_optional_datetime)]
38-
OptionalFloat = Annotated[float | None, BeforeValidator(_parse_optional_float)]
36+
# Reusable annotated types for optional fields that may come as empty strings.
37+
# PEP 695 named aliases (requires pydantic>=2.11 for full support).
38+
type OptionalDatetime = Annotated[
39+
datetime | None, BeforeValidator(_parse_optional_datetime)
40+
]
41+
type OptionalFloat = Annotated[float | None, BeforeValidator(_parse_optional_float)]
3942
# Coerces a nullable value (e.g. a datetime or None) into a bool (present = True)
40-
IsPresent = Annotated[bool, BeforeValidator(lambda v: v is not None and v != "")]
43+
type IsPresent = Annotated[bool, BeforeValidator(lambda v: v is not None and v != "")]
4144

4245

4346
class GoalStatus(StrEnum):
@@ -371,7 +374,8 @@ class HeadlineDetails(BloomyBaseModel):
371374
closed_at: str | None = None
372375

373376

374-
# HeadlineListItem is identical to HeadlineDetails - use type alias
377+
# HeadlineListItem is identical to HeadlineDetails - use assignment alias so the
378+
# name remains callable (PEP 695 `type` produces a non-callable TypeAliasType).
375379
HeadlineListItem = HeadlineDetails
376380

377381

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)