Skip to content

Commit

Permalink
Only import add custom fn when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Sep 11, 2024
1 parent 0c62b0d commit 1a69fc2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion strawberry/experimental/pydantic/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion strawberry/types/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1a69fc2

Please sign in to comment.