Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: minor

Support for `type[strawberry.UNSET]` in addition to `strawberry.types.unset.UnsetType` for annotations.
4 changes: 3 additions & 1 deletion strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def create_optional(self, evaled_type: Any) -> StrawberryOptional:
types = get_args(evaled_type)
non_optional_types = tuple(
filter(
lambda x: x is not type(None) and x is not type(UNSET),
lambda x: x is not type(None)
and x is not type(UNSET)
and x != type[UNSET],
types,
)
)
Expand Down
11 changes: 11 additions & 0 deletions tests/types/resolving/test_optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def test_optional_with_unset():
assert resolved == Optional[str]


def test_optional_with_type_of_unset():
annotation = StrawberryAnnotation(Union[type[strawberry.UNSET], Optional[str]])
resolved = annotation.resolve()

assert isinstance(resolved, StrawberryOptional)
assert resolved.of_type is str

assert resolved == StrawberryOptional(of_type=str)
assert resolved == Optional[str]


def test_optional_with_unset_as_union():
annotation = StrawberryAnnotation(Union[UnsetType, None, str])
resolved = annotation.resolve()
Expand Down
Loading