Skip to content

Commit cd7546c

Browse files
committed
use | syntax
1 parent 03bf134 commit cd7546c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sqlmodel/_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _is_union_type(t: Any) -> bool:
6868

6969
def get_literal_annotation_info(
7070
annotation: Any,
71-
) -> Optional[tuple[type[Any], tuple[Any, ...]]]:
71+
) -> tuple[type[Any], tuple[Any, ...]] | None:
7272
if annotation is None or get_origin(annotation) is None:
7373
return None
7474
origin = get_origin(annotation)

tests/test_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_literal_valid_values(clear_sqlmodel, caplog):
223223
"""Test https://github.com/fastapi/sqlmodel/issues/57"""
224224

225225
class Model(SQLModel, table=True):
226-
id: Optional[int] = Field(default=None, primary_key=True)
226+
id: int | None = Field(default=None, primary_key=True)
227227
all_str: Literal["a", "b", "c"]
228228
mixed: Literal["yes", "no", 1, 0]
229229
all_int: Literal[1, 2, 3]
@@ -270,7 +270,7 @@ def test_literal_constraints_invalid_values(clear_sqlmodel):
270270
"""DB should reject values that are not part of the Literal choices."""
271271

272272
class Model(SQLModel, table=True):
273-
id: Optional[int] = Field(default=None, primary_key=True)
273+
id: int | None = Field(default=None, primary_key=True)
274274
all_str: Literal["a", "b", "c"]
275275
mixed: Literal["yes", "no", 1, 0]
276276
all_int: Literal[1, 2, 3]
@@ -330,8 +330,8 @@ def test_literal_optional_and_union_constraints(clear_sqlmodel):
330330
"""Literals inside Optional/Union should also be enforced at the DB level."""
331331

332332
class Model(SQLModel, table=True):
333-
id: Optional[int] = Field(default=None, primary_key=True)
334-
opt_str: Optional[Literal["x", "y"]] = None
333+
id: int | None = Field(default=None, primary_key=True)
334+
opt_str: Literal["x", "y"] | None = None
335335
union_int: Union[Literal[10, 20], None] = None
336336

337337
engine = create_engine("sqlite://")

0 commit comments

Comments
 (0)