Skip to content

Commit 28d77c4

Browse files
loreyclaude
andcommitted
fix: use Optional[str] for Python 3.9 compatibility
Pydantic evaluates type annotations at runtime, so `str | None` syntax fails on Python 3.9. Use Optional[str] in Pydantic models. Also ignore UP007 lint rule for platforms since this is intentional. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 910700e commit 28d77c4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ ignore = [
8181
"socials/cli.py" = [
8282
"FBT001", # typer requires boolean positional args
8383
]
84+
"socials/platforms/*.py" = [
85+
"UP007", # Pydantic needs Optional[X] for Python 3.9 runtime evaluation
86+
]
8487

8588
[tool.ruff.lint.isort]
8689
known-first-party = ["socials"]

socials/platforms/facebook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import re
6-
from typing import TYPE_CHECKING, ClassVar, Literal
6+
from typing import TYPE_CHECKING, ClassVar, Literal, Optional
77

88
from pydantic import BaseModel
99

@@ -28,8 +28,8 @@ class FacebookProfileURL(BaseModel, frozen=True):
2828
url: str
2929
platform: Literal["facebook"] = "facebook"
3030
entity_type: Literal["profile"] = "profile"
31-
username: str | None = None
32-
user_id: str | None = None
31+
username: Optional[str] = None
32+
user_id: Optional[str] = None
3333

3434
def __hash__(self) -> int:
3535
"""Return hash based on URL."""

socials/platforms/youtube.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import re
6-
from typing import TYPE_CHECKING, ClassVar, Literal
6+
from typing import TYPE_CHECKING, ClassVar, Literal, Optional
77

88
from pydantic import BaseModel
99

@@ -40,9 +40,9 @@ class YouTubeChannelURL(BaseModel, frozen=True):
4040
url: str
4141
platform: Literal["youtube"] = "youtube"
4242
entity_type: Literal["channel"] = "channel"
43-
channel_id: str | None = None
44-
username: str | None = None
45-
custom_url: str | None = None
43+
channel_id: Optional[str] = None
44+
username: Optional[str] = None
45+
custom_url: Optional[str] = None
4646

4747
def __hash__(self) -> int:
4848
"""Return hash based on URL."""

0 commit comments

Comments
 (0)