From 1a69fc2dec6c6ca0d5185a4be07505beb2ecc2d1 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Wed, 11 Sep 2024 18:41:14 +0200 Subject: [PATCH] Only import add custom fn when needed --- strawberry/experimental/pydantic/object_type.py | 3 ++- strawberry/types/object_type.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/strawberry/experimental/pydantic/object_type.py b/strawberry/experimental/pydantic/object_type.py index caed153c9b..c153b84a0b 100644 --- a/strawberry/experimental/pydantic/object_type.py +++ b/strawberry/experimental/pydantic/object_type.py @@ -37,7 +37,6 @@ from strawberry.types.field import StrawberryField from strawberry.types.object_type import _process_type, _wrap_dataclass from strawberry.types.type_resolver import _get_fields -from strawberry.utils.dataclasses import add_custom_init_fn if TYPE_CHECKING: from graphql import GraphQLResolveInfo @@ -254,6 +253,8 @@ def is_type_of(cls: Type, obj: Any, _info: GraphQLResolveInfo) -> bool: ) if sys.version_info < (3, 10, 1): + from strawberry.utils.dataclasses import add_custom_init_fn + add_custom_init_fn(cls) _process_type( diff --git a/strawberry/types/object_type.py b/strawberry/types/object_type.py index 5a9cea739e..c6120763aa 100644 --- a/strawberry/types/object_type.py +++ b/strawberry/types/object_type.py @@ -22,7 +22,6 @@ ObjectIsNotClassError, ) from strawberry.types.base import get_object_definition -from strawberry.utils.dataclasses import add_custom_init_fn from strawberry.utils.deprecations import DEPRECATION_MESSAGES, DeprecatedDescriptor from strawberry.utils.str_converters import to_camel_case @@ -118,6 +117,8 @@ def _wrap_dataclass(cls: Type[T]) -> Type[T]: dclass = dataclasses.dataclass(cls, **dclass_kwargs) if sys.version_info < (3, 10): + from strawberry.utils.dataclasses import add_custom_init_fn + add_custom_init_fn(dclass) return dclass