Skip to content

Commit a86418c

Browse files
committed
📝 Update tests to conditionally define type aliases based on availability of Annotated
1 parent 563fa92 commit a86418c

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

tests/test_field_sa_type.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ class Hero1(SQLModel, table=True):
1616
weapon: Type1_t = "sword"
1717

1818

19-
def test_sa_type_typing_2() -> None:
20-
Type2_t = t.Annotated[str, "Just a comment"]
19+
if hasattr(t, "Annotated"):
2120

22-
class Hero(SQLModel, table=True):
23-
pk: int = Field(primary_key=True)
24-
weapon: Type2_t = "sword"
21+
def test_sa_type_typing_2() -> None:
22+
Type2_t = t.Annotated[str, "Just a comment"]
23+
24+
class Hero(SQLModel, table=True):
25+
pk: int = Field(primary_key=True)
26+
weapon: Type2_t = "sword"
2527

2628

2729
if hasattr(t, "TypeAlias"):
@@ -32,12 +34,13 @@ class Hero(SQLModel, table=True):
3234
pk: int = Field(primary_key=True)
3335
weapon: Type3_t = "sword"
3436

35-
Type4_t: t.TypeAlias = t.Annotated[str, "Just a comment"]
37+
if hasattr(t, "Annotated"):
38+
Type4_t: t.TypeAlias = t.Annotated[str, "Just a comment"]
3639

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"
40+
def test_sa_type_typing_4() -> None:
41+
class Hero(SQLModel, table=True):
42+
pk: int = Field(primary_key=True)
43+
weapon: Type4_t = "sword"
4144

4245

4346
@needs_py312
@@ -98,12 +101,14 @@ class Hero1(SQLModel, table=True):
98101
weapon: Type1_te = "sword"
99102

100103

101-
def test_sa_type_typing_extensions_2() -> None:
102-
Type2_te = te.Annotated[str, "Just a comment"]
104+
if hasattr(te, "Annotated"):
103105

104-
class Hero(SQLModel, table=True):
105-
pk: int = Field(primary_key=True)
106-
weapon: Type2_te = "sword"
106+
def test_sa_type_typing_extensions_2() -> None:
107+
Type2_te = te.Annotated[str, "Just a comment"]
108+
109+
class Hero(SQLModel, table=True):
110+
pk: int = Field(primary_key=True)
111+
weapon: Type2_te = "sword"
107112

108113

109114
if hasattr(te, "TypeAlias"):
@@ -114,12 +119,13 @@ class Hero(SQLModel, table=True):
114119
pk: int = Field(primary_key=True)
115120
weapon: Type3_te = "sword"
116121

117-
Type4_te: te.TypeAlias = te.Annotated[str, "Just a comment"]
122+
if hasattr(te, "Annotated"):
123+
Type4_te: te.TypeAlias = te.Annotated[str, "Just a comment"]
118124

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"
125+
def test_sa_type_typing_extensions_4() -> None:
126+
class Hero(SQLModel, table=True):
127+
pk: int = Field(primary_key=True)
128+
weapon: Type4_te = "sword"
123129

124130

125131
@needs_py312

0 commit comments

Comments
 (0)