diff --git a/strawberry/types/info.py b/strawberry/types/info.py index 78626d3ed9..b80a7b85f6 100644 --- a/strawberry/types/info.py +++ b/strawberry/types/info.py @@ -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: diff --git a/strawberry/utils/typing.py b/strawberry/utils/typing.py index 54a7efaf69..0f187fc254 100644 --- a/strawberry/utils/typing.py +++ b/strawberry/utils/typing.py @@ -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: @@ -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