Skip to content

Commit

Permalink
Add 2 passing and 1 failing Annotated test
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHayes committed Nov 27, 2020
1 parent bed794f commit b183faa
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_main.py
Expand Up @@ -18,7 +18,8 @@
root_validator,
validator,
)
from pydantic.typing import Literal
from pydantic.fields import Undefined
from pydantic.typing import Annotated, Literal


def test_success():
Expand Down Expand Up @@ -1374,3 +1375,25 @@ class M(BaseModel):
a: int

get_type_hints(M.__config__)


@pytest.mark.parametrize(
["value"],
[(Undefined,), (Field(default=5),), (Field(default=5, ge=0),)]
)
def test_annotated(value):
x_hint = Annotated[int, 5]

class M(BaseModel):
x: x_hint = value

assert M(x=5).x == 5

# get_type_hints doesn't recognize typing_extensions.Annotated, so will return the full
# annotation. 3.9 w/ stock Annotated will return the wrapped type by default, but return the
# full thing with the new include_extras flag.
if sys.version_info >= (3, 9):
assert get_type_hints(M)["x"] is int
assert get_type_hints(M, include_extras=True)["x"] == x_hint
else:
assert get_type_hints(M)["x"] == x_hint

0 comments on commit b183faa

Please sign in to comment.