Skip to content

Commit 563fa92

Browse files
committed
📝 Update type alias definitions to support conditional assignment for Python 3.10
1 parent 8fe139b commit 563fa92

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

‎tests/test_field_sa_type.py‎

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@ class Hero(SQLModel, table=True):
2424
weapon: Type2_t = "sword"
2525

2626

27-
Type3_t: t.TypeAlias = str
27+
if hasattr(t, "TypeAlias"):
28+
Type3_t: t.TypeAlias = str
2829

30+
def test_sa_type_typing_3() -> None:
31+
class Hero(SQLModel, table=True):
32+
pk: int = Field(primary_key=True)
33+
weapon: Type3_t = "sword"
2934

30-
def test_sa_type_typing_3() -> None:
31-
class Hero(SQLModel, table=True):
32-
pk: int = Field(primary_key=True)
33-
weapon: Type3_t = "sword"
34-
35-
36-
Type4_t: t.TypeAlias = t.Annotated[str, "Just a comment"]
37-
35+
Type4_t: t.TypeAlias = t.Annotated[str, "Just a comment"]
3836

39-
def test_sa_type_typing_4() -> None:
40-
class Hero(SQLModel, table=True):
41-
pk: int = Field(primary_key=True)
42-
weapon: Type4_t = "sword"
37+
def test_sa_type_typing_4() -> None:
38+
class Hero(SQLModel, table=True):
39+
pk: int = Field(primary_key=True)
40+
weapon: Type4_t = "sword"
4341

4442

4543
@needs_py312
@@ -108,22 +106,20 @@ class Hero(SQLModel, table=True):
108106
weapon: Type2_te = "sword"
109107

110108

111-
Type3_te: te.TypeAlias = str
109+
if hasattr(te, "TypeAlias"):
110+
Type3_te: te.TypeAlias = str
112111

112+
def test_sa_type_typing_extensions_3() -> None:
113+
class Hero(SQLModel, table=True):
114+
pk: int = Field(primary_key=True)
115+
weapon: Type3_te = "sword"
113116

114-
def test_sa_type_typing_extensions_3() -> None:
115-
class Hero(SQLModel, table=True):
116-
pk: int = Field(primary_key=True)
117-
weapon: Type3_te = "sword"
118-
119-
120-
Type4_te: te.TypeAlias = te.Annotated[str, "Just a comment"]
121-
117+
Type4_te: te.TypeAlias = te.Annotated[str, "Just a comment"]
122118

123-
def test_sa_type_typing_extensions_4() -> None:
124-
class Hero(SQLModel, table=True):
125-
pk: int = Field(primary_key=True)
126-
weapon: Type4_te = "sword"
119+
def test_sa_type_typing_extensions_4() -> None:
120+
class Hero(SQLModel, table=True):
121+
pk: int = Field(primary_key=True)
122+
weapon: Type4_te = "sword"
127123

128124

129125
@needs_py312

0 commit comments

Comments
 (0)