Skip to content

Commit 8bd4163

Browse files
committed
Update test to Python 3.10+ syntax
1 parent 80f8986 commit 8bd4163

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

tests/test_pydantic/test_field.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from decimal import Decimal
2-
from typing import Annotated, Any, Literal, Optional, Union
2+
from typing import Annotated, Any, Literal
33

44
import pytest
55
from pydantic import ValidationError
@@ -38,7 +38,7 @@ class Lizard(SQLModel):
3838
scales: bool
3939

4040
class Model(SQLModel):
41-
pet: Union[Cat, Dog, Lizard] = Field(..., discriminator="pet_type")
41+
pet: Cat | Dog | Lizard = Field(..., discriminator="pet_type")
4242
n: int
4343

4444
Model(pet={"pet_type": "dog", "barks": 3.14}, n=1) # type: ignore[arg-type]
@@ -66,10 +66,9 @@ def get_discriminator_value(v: Any) -> str:
6666
return getattr(v, "fruit", getattr(v, "filling", None))
6767

6868
class ThanksgivingDinner(SQLModel):
69-
dessert: Union[
70-
Annotated[ApplePie, Tag("apple")],
71-
Annotated[PumpkinPie, Tag("pumpkin")],
72-
] = Field(
69+
dessert: (
70+
Annotated[ApplePie, Tag("apple")] | Annotated[PumpkinPie, Tag("pumpkin")]
71+
) = Field(
7372
discriminator=Discriminator(get_discriminator_value),
7473
)
7574

@@ -82,7 +81,7 @@ class ThanksgivingDinner(SQLModel):
8281

8382
def test_repr():
8483
class Model(SQLModel):
85-
id: Optional[int] = Field(primary_key=True)
84+
id: int | None = Field(primary_key=True)
8685
foo: str = Field(repr=False)
8786

8887
instance = Model(id=123, foo="bar")

0 commit comments

Comments
 (0)