Skip to content

Commit

Permalink
refactor(typing): Remove "unpacking" of annotated_types (#3716)
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzkraut authored Sep 4, 2024
1 parent c6173a3 commit 6d49fc2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 0 additions & 8 deletions litestar/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from litestar.types import Empty
from litestar.types.builtin_types import NoneType, UnionTypes
from litestar.utils.predicates import (
is_annotated_type,
is_any,
is_class_and_subclass,
is_generic,
Expand Down Expand Up @@ -150,13 +149,6 @@ def _traverse_metadata(
metadata=cast("Sequence[Any]", value), is_sequence_container=is_sequence_container, extra=extra
)
)
elif is_annotated_type(value) and (type_args := [v for v in get_args(value) if v is not None]):
# annotated values can be nested inside other annotated values
# this behaviour is buggy in python 3.8, hence we need to guard here.
if len(type_args) > 1:
constraints.update(
_traverse_metadata(metadata=type_args[1:], is_sequence_container=is_sequence_container, extra=extra)
)
elif unpacked_predicate := _unpack_predicate(value):
constraints.update(unpacked_predicate)
else:
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_openapi/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ class MyDataclass:
constrained_int: Annotated[int, annotated_types.Gt(1), annotated_types.Lt(10)]
constrained_float: Annotated[float, annotated_types.Ge(1), annotated_types.Le(10)]
constrained_date: Annotated[date, annotated_types.Interval(gt=historical_date, lt=today)]
constrained_lower_case: Annotated[str, annotated_types.LowerCase]
constrained_upper_case: Annotated[str, annotated_types.UpperCase]
constrained_is_ascii: Annotated[str, annotated_types.IsAscii]
constrained_is_digit: Annotated[str, annotated_types.IsDigits]
constrained_lower_case: annotated_types.LowerCase[str]
constrained_upper_case: annotated_types.UpperCase[str]
constrained_is_ascii: annotated_types.IsAscii[str]
constrained_is_digit: annotated_types.IsDigit[str]

schema = get_schema_for_field_definition(FieldDefinition.from_kwarg(name="MyDataclass", annotation=MyDataclass))

Expand Down

0 comments on commit 6d49fc2

Please sign in to comment.