Skip to content

Commit 105a8e5

Browse files
committed
📝 Update type alias definitions in tests and compatibility module for Python 3.12
1 parent a7615de commit 105a8e5

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

‎sqlmodel/_compat.py‎

Lines changed: 1 addition & 1 deletion
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
)
@@ -81,7 +82,6 @@ def partial_init() -> Generator[None, None, None]:
8182
from pydantic._internal._repr import Representation as Representation
8283
from pydantic_core import PydanticUndefined as Undefined
8384
from pydantic_core import PydanticUndefinedType as UndefinedType
84-
from typing import TypeAliasType
8585

8686
# Dummy for types, to make it importable
8787
class ModelField:

‎tests/test_field_sa_type.py‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,58 @@
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:
1310
Type1 = str
1411

1512
class Hero1(SQLModel, table=True):
1613
pk: int = Field(primary_key=True)
17-
weapon: Type1 = 'sword'
14+
weapon: Type1 = "sword"
15+
1816

1917
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
2018
def test_sa_type_2() -> None:
2119
Type2 = Annotated[str, "Just a comment"]
2220

2321
class Hero(SQLModel, table=True):
2422
pk: int = Field(primary_key=True)
25-
weapon: Type2 = 'sword'
23+
weapon: Type2 = "sword"
24+
25+
26+
Type3: TypeAlias = str
27+
2628

2729
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
2830
def test_sa_type_3() -> None:
29-
type Type3 = str
30-
3131
class Hero(SQLModel, table=True):
3232
pk: int = Field(primary_key=True)
33-
weapon: Type3 = 'sword'
33+
weapon: Type3 = "sword"
34+
35+
36+
Type4: TypeAlias = Annotated[str, "Just a comment"]
37+
3438

3539
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
3640
def test_sa_type_4() -> None:
37-
type Type4 = Annotated[str, "Just a comment"]
38-
3941
class Hero(SQLModel, table=True):
4042
pk: int = Field(primary_key=True)
41-
weapon: Type4 = 'sword'
43+
weapon: Type4 = "sword"
44+
4245

4346
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
4447
def test_sa_type_5() -> None:
48+
type Type5 = str
4549

4650
class Hero(SQLModel, table=True):
4751
pk: int = Field(primary_key=True)
48-
weapon: Type5 = 'sword'
52+
weapon: Type5 = "sword"
53+
4954

5055
@pytest.mark.skipif(version_info[1] < 12, reason="Language feature of Python 3.12+")
5156
def test_sa_type_6() -> None:
57+
type Type6 = Annotated[str, "Just a comment"]
58+
5259
class Hero(SQLModel, table=True):
5360
pk: int = Field(primary_key=True)
54-
weapon: Type6 = 'sword'
61+
weapon: Type6 = "sword"

0 commit comments

Comments
 (0)