Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 20, 2024
1 parent 936a1d1 commit c61f422
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 9 additions & 6 deletions strawberry/relay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from collections import defaultdict
from collections.abc import AsyncIterable
from typing import (
TypeVar,
UnionType,
TYPE_CHECKING,
Any,
AsyncIterator,
Expand All @@ -25,6 +23,7 @@
Tuple,
Type,
Union,
UnionType,
cast,
overload,
)
Expand Down Expand Up @@ -237,15 +236,19 @@ def apply(self, field: StrawberryField) -> None:

# Handle Optional[Connection[T]] and Union[Connection[T], None] cases
type_origin = get_origin(f_type) if is_generic_alias(f_type) else f_type

# If it's Optional or Union, extract the inner type
if type_origin in (Union, UnionType):
types = getattr(f_type, "__args__", ())
# Find the non-None type in the Union
inner_type = next((t for t in types if t is not type(None)), None) # noqa: E721
inner_type = next((t for t in types if t is not type(None)), None)
if inner_type is not None:
type_origin = get_origin(inner_type) if is_generic_alias(inner_type) else inner_type

type_origin = (
get_origin(inner_type)
if is_generic_alias(inner_type)
else inner_type
)

if not isinstance(type_origin, type) or not issubclass(type_origin, Connection):
raise RelayWrongAnnotationError(field.name, cast(type, field.origin))

Expand Down
4 changes: 1 addition & 3 deletions tests/relay/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import List, Optional, Union

import pytest
from typing import Optional, Union

import strawberry
from strawberry.permission import BasePermission
Expand Down

0 comments on commit c61f422

Please sign in to comment.