Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions strawberry/types/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ def __class_getitem__(cls, types: Union[type, tuple[type, ...]]) -> type[Info]:
See:
https://discuss.python.org/t/passing-only-one-typevar-of-two-when-using-defaults/49134
"""
if not isinstance(types, tuple):
types = (types, Any) # type: ignore

return super().__class_getitem__(types) # type: ignore
# Fast path: if types is already a tuple of length 2, avoid allocation/modification
if isinstance(types, tuple):
# Only coerce if it's a tuple of length 1 (for legacy compatibility); else, pass as-is
if len(types) == 1:
types = (types[0], Any)
return super().__class_getitem__(types) # type: ignore
return super().__class_getitem__((types, Any)) # type: ignore

@property
def field_name(self) -> str:
Expand Down
7 changes: 2 additions & 5 deletions strawberry/utils/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ def is_concrete_generic(annotation: type) -> bool:


def is_generic_subclass(annotation: type) -> bool:
return isinstance(annotation, type) and issubclass(
annotation,
Generic, # type:ignore
)
return isinstance(annotation, type) and issubclass(annotation, Generic)


def is_generic(annotation: type) -> bool:
Expand Down Expand Up @@ -185,7 +182,7 @@ def get_parameters(annotation: type) -> Union[tuple[object], tuple[()]]:
and issubclass(annotation, Generic) # type:ignore
and annotation is not Generic
):
return annotation.__parameters__ # type: ignore[union-attr]
return annotation.__parameters__
return () # pragma: no cover


Expand Down