Skip to content

Commit 4605df6

Browse files
committed
Fix Python 3.10+ syntax in test
1 parent 20778eb commit 4605df6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tests/test_pydantic/test_field.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Model(SQLModel):
6565

6666

6767
@pytest.mark.parametrize("coerce_numbers_to_str", [None, False])
68-
def test_coerce_numbers_to_str_false(coerce_numbers_to_str: Optional[bool]):
68+
def test_coerce_numbers_to_str_false(coerce_numbers_to_str: bool | None):
6969
class Model2(SQLModel):
7070
val: str = Field(coerce_numbers_to_str=coerce_numbers_to_str)
7171

@@ -104,7 +104,7 @@ class Model2(SQLModel):
104104

105105
def test_validate_default_table_model():
106106
class Model(SQLModel):
107-
id: Optional[int] = Field(default=None, primary_key=True)
107+
id: int | None = Field(default=None, primary_key=True)
108108
val: int = Field(default="123", validate_default=True)
109109

110110
class ModelDB(Model, table=True):
@@ -124,7 +124,7 @@ class ModelDB(Model, table=True):
124124

125125

126126
@pytest.mark.parametrize("validate_default", [None, False])
127-
def test_validate_default_false(validate_default: Optional[bool]):
127+
def test_validate_default_false(validate_default: bool | None):
128128
class Model3(SQLModel):
129129
val: int = Field(default="123", validate_default=validate_default)
130130

@@ -147,9 +147,9 @@ class Model(SQLModel):
147147

148148

149149
@pytest.mark.parametrize("union_mode", [None, "smart"])
150-
def test_union_mode_smart(union_mode: Optional[Literal["smart"]]):
150+
def test_union_mode_smart(union_mode: Literal["smart"] | None):
151151
class Model(SQLModel):
152-
val: Union[float, int] = Field(union_mode=union_mode)
152+
val: float | int = Field(union_mode=union_mode)
153153

154154
a = Model.model_validate({"val": 123})
155155
assert isinstance(a.val, int) # float is first, but int is more precise
@@ -163,7 +163,7 @@ class Model(SQLModel):
163163

164164
def test_union_mode_left_to_right():
165165
class Model(SQLModel):
166-
val: Union[float, int] = Field(union_mode="left_to_right")
166+
val: float | int = Field(union_mode="left_to_right")
167167

168168
a = Model.model_validate({"val": 123})
169169
assert isinstance(a.val, float)
@@ -185,7 +185,7 @@ def test_union_mode_via_schema_extra(): # Current workaround. Remove after some
185185
):
186186

187187
class Model(SQLModel):
188-
val: Union[float, int] = Field(schema_extra={"union_mode": "smart"})
188+
val: float | int = Field(schema_extra={"union_mode": "smart"})
189189

190190
a = Model.model_validate({"val": 123})
191191
assert isinstance(a.val, int) # float is first, but int is more precise
@@ -210,7 +210,7 @@ class Model(SQLModel):
210210

211211

212212
@pytest.mark.parametrize("fail_fast", [None, False])
213-
def test_fail_fast_false(fail_fast: Optional[bool]):
213+
def test_fail_fast_false(fail_fast: bool | None):
214214
class Model(SQLModel):
215215
val: list[int] = Field(fail_fast=fail_fast)
216216

0 commit comments

Comments
 (0)