Skip to content

Commit fd10c35

Browse files
committed
📝 Add tests for type alias handling in test_field_sa_type.py
1 parent e4d0d15 commit fd10c35

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

sqlmodel/_compat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Optional,
1616
Set,
1717
Type,
18+
TypeAliasType,
1819
TypeVar,
1920
Union,
2021
)
@@ -74,8 +75,6 @@ def partial_init() -> Generator[None, None, None]:
7475

7576

7677
if IS_PYDANTIC_V2:
77-
from typing import TypeAliasType
78-
7978
from annotated_types import MaxLen
8079
from pydantic import ConfigDict as BaseConfig
8180
from pydantic._internal._fields import PydanticMetadata

tests/test_field_sa_type.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import pytest
55
from sqlmodel import Field, SQLModel
66

7-
Type5: TypeAlias = str
8-
Type6: TypeAlias = Annotated[str, "Just a comment"]
9-
107

118
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
129
def test_sa_type_1() -> None:
@@ -26,33 +23,39 @@ class Hero(SQLModel, table=True):
2623
weapon: Type2 = "sword"
2724

2825

26+
Type3: TypeAlias = str
27+
28+
2929
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
3030
def test_sa_type_3() -> None:
31-
type Type3 = str
32-
3331
class Hero(SQLModel, table=True):
3432
pk: int = Field(primary_key=True)
3533
weapon: Type3 = "sword"
3634

3735

36+
Type4: TypeAlias = Annotated[str, "Just a comment"]
37+
38+
3839
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
3940
def test_sa_type_4() -> None:
40-
type Type4 = Annotated[str, "Just a comment"]
41-
4241
class Hero(SQLModel, table=True):
4342
pk: int = Field(primary_key=True)
4443
weapon: Type4 = "sword"
4544

4645

4746
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
4847
def test_sa_type_5() -> None:
48+
type Type5 = str # type: ignore[invalid-syntax]
49+
4950
class Hero(SQLModel, table=True):
5051
pk: int = Field(primary_key=True)
5152
weapon: Type5 = "sword"
5253

5354

5455
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
5556
def test_sa_type_6() -> None:
57+
type Type6 = Annotated[str, "Just a comment"] # type: ignore[invalid-syntax]
58+
5659
class Hero(SQLModel, table=True):
5760
pk: int = Field(primary_key=True)
5861
weapon: Type6 = "sword"

0 commit comments

Comments
 (0)