diff --git a/examples/testapp/testapp/app.py b/examples/testapp/testapp/app.py index 0cdb71c5..e6694d2b 100644 --- a/examples/testapp/testapp/app.py +++ b/examples/testapp/testapp/app.py @@ -6,8 +6,8 @@ from litestar.plugins.sqlalchemy import EngineConfig, SQLAlchemyAsyncConfig, SQLAlchemyPlugin from strawberry.litestar import BaseContext, make_graphql_controller -from .models import Base -from .schema import schema +from testapp.models import Base +from testapp.schema import schema if TYPE_CHECKING: from sqlalchemy.ext.asyncio import AsyncSession diff --git a/examples/testapp/testapp/schema.py b/examples/testapp/testapp/schema.py index 0fb619fd..38d9da4e 100644 --- a/examples/testapp/testapp/schema.py +++ b/examples/testapp/testapp/schema.py @@ -4,8 +4,7 @@ import strawberry from strawchemy.validation.pydantic import PydanticValidation - -from .types import ( +from testapp.types import ( CustomerCreate, CustomerType, MilestoneCreate, diff --git a/examples/testapp/testapp/types.py b/examples/testapp/testapp/types.py index 5fcc8e78..27d9f3d1 100644 --- a/examples/testapp/testapp/types.py +++ b/examples/testapp/testapp/types.py @@ -5,8 +5,7 @@ from pydantic import AfterValidator from strawchemy import Strawchemy, StrawchemyAsyncRepository, StrawchemyConfig - -from .models import Customer, Milestone, Project, Ticket +from testapp.models import Customer, Milestone, Project, Ticket strawchemy = Strawchemy(StrawchemyConfig("sqlite", repository_type=StrawchemyAsyncRepository)) diff --git a/pyproject.toml b/pyproject.toml index bfae8721..3be715e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "msgspec", + "msgspec>=0.4.2", "sqlalchemy>=2.0.10", "strawberry-graphql", "typing-extensions" @@ -370,10 +370,13 @@ convention = "google" [tool.ruff.lint.per-file-ignores] "tests/*" = ["TC001", "UP037", "PLR2004", "PLC0415"] +"src/strawchemy/strawberry/factories/*" = ["UP007", "UP045"] [tool.ruff.lint.isort] known-first-party = ["strawchemy", "tests"] +[tool.ruff.lint.flake8-tidy-imports] +ban-relative-imports = "all" [tool.unasyncd] add_editors_note = true diff --git a/src/strawchemy/__init__.py b/src/strawchemy/__init__.py index fed100e2..204383a0 100644 --- a/src/strawchemy/__init__.py +++ b/src/strawchemy/__init__.py @@ -2,12 +2,12 @@ from __future__ import annotations -from .config.base import StrawchemyConfig -from .mapper import Strawchemy -from .sqlalchemy.hook import QueryHook -from .strawberry import ModelInstance -from .strawberry.mutation.input import Input -from .strawberry.mutation.types import ( +from strawchemy.config.base import StrawchemyConfig +from strawchemy.mapper import Strawchemy +from strawchemy.sqlalchemy.hook import QueryHook +from strawchemy.strawberry import ModelInstance +from strawchemy.strawberry.mutation.input import Input +from strawchemy.strawberry.mutation.types import ( ErrorType, RequiredToManyUpdateInput, RequiredToOneInput, @@ -16,8 +16,8 @@ ToOneInput, ValidationErrorType, ) -from .strawberry.repository import StrawchemyAsyncRepository, StrawchemySyncRepository -from .validation.base import InputValidationError +from strawchemy.strawberry.repository import StrawchemyAsyncRepository, StrawchemySyncRepository +from strawchemy.validation.base import InputValidationError __all__ = ( "ErrorType", diff --git a/src/strawchemy/dto/__init__.py b/src/strawchemy/dto/__init__.py index 5a040750..f111c82c 100644 --- a/src/strawchemy/dto/__init__.py +++ b/src/strawchemy/dto/__init__.py @@ -2,9 +2,9 @@ from __future__ import annotations -from .base import DTOFieldDefinition, ModelFieldT, ModelInspector, ModelT -from .types import DTOConfig, Purpose, PurposeConfig -from .utils import config, field +from strawchemy.dto.base import DTOFieldDefinition, ModelFieldT, ModelInspector, ModelT +from strawchemy.dto.types import DTOConfig, Purpose, PurposeConfig +from strawchemy.dto.utils import config, field __all__ = ( "DTOConfig", diff --git a/src/strawchemy/dto/base.py b/src/strawchemy/dto/base.py index 8566b25d..ab3321f8 100644 --- a/src/strawchemy/dto/base.py +++ b/src/strawchemy/dto/base.py @@ -29,10 +29,7 @@ from typing_extensions import Self, override from strawchemy.dto.exceptions import DTOError, EmptyDTOError -from strawchemy.graph import Node -from strawchemy.utils import is_type_hint_optional, non_optional_type_hint - -from .types import ( +from strawchemy.dto.types import ( DTOAuto, DTOConfig, DTOFieldConfig, @@ -44,7 +41,9 @@ Purpose, PurposeConfig, ) -from .utils import config +from strawchemy.dto.utils import config +from strawchemy.graph import Node +from strawchemy.utils import is_type_hint_optional, non_optional_type_hint if TYPE_CHECKING: from collections.abc import Callable, Generator, Hashable, Iterable, Mapping diff --git a/src/strawchemy/dto/pydantic.py b/src/strawchemy/dto/pydantic.py index 5aef8c4d..9502c57f 100644 --- a/src/strawchemy/dto/pydantic.py +++ b/src/strawchemy/dto/pydantic.py @@ -4,9 +4,9 @@ from sqlalchemy.orm import DeclarativeBase, QueryableAttribute -from .backend.pydantic import MappedPydanticDTO, PydanticDTOBackend -from .base import DTOFactory -from .inspectors.sqlalchemy import SQLAlchemyInspector +from strawchemy.dto.backend.pydantic import MappedPydanticDTO, PydanticDTOBackend +from strawchemy.dto.base import DTOFactory +from strawchemy.dto.inspectors.sqlalchemy import SQLAlchemyInspector __all__ = ("factory", "pydantic_dto") diff --git a/src/strawchemy/dto/types.py b/src/strawchemy/dto/types.py index 51760aba..7b3f9722 100644 --- a/src/strawchemy/dto/types.py +++ b/src/strawchemy/dto/types.py @@ -5,7 +5,7 @@ import dataclasses from dataclasses import dataclass, field from enum import Enum -from typing import TYPE_CHECKING, Any, Literal, TypeAlias, Union, final, get_type_hints +from typing import TYPE_CHECKING, Any, Literal, TypeAlias, final, get_type_hints from typing_extensions import override @@ -20,8 +20,8 @@ DTOScope: TypeAlias = Literal["global", "dto"] -IncludeFields: TypeAlias = Union[list[str], set[str], Literal["all"]] -ExcludeFields: TypeAlias = Union[list[str], set[str]] +IncludeFields: TypeAlias = "list[str] | set[str] | Literal['all']" +ExcludeFields: TypeAlias = "list[str] | set[str]" @final diff --git a/src/strawchemy/dto/utils.py b/src/strawchemy/dto/utils.py index 55b80e5e..cd53c789 100644 --- a/src/strawchemy/dto/utils.py +++ b/src/strawchemy/dto/utils.py @@ -14,8 +14,16 @@ from typing import TYPE_CHECKING, Any -from .constants import DTO_INFO_KEY -from .types import DTOConfig, DTOFieldConfig, DTOScope, ExcludeFields, IncludeFields, Purpose, PurposeConfig +from strawchemy.dto.constants import DTO_INFO_KEY +from strawchemy.dto.types import ( + DTOConfig, + DTOFieldConfig, + DTOScope, + ExcludeFields, + IncludeFields, + Purpose, + PurposeConfig, +) if TYPE_CHECKING: from collections.abc import Callable, Mapping diff --git a/src/strawchemy/mapper.py b/src/strawchemy/mapper.py index e4687145..c75a3480 100644 --- a/src/strawchemy/mapper.py +++ b/src/strawchemy/mapper.py @@ -7,23 +7,22 @@ from strawberry.annotation import StrawberryAnnotation from strawberry.schema.config import StrawberryConfig -from strawchemy.strawberry.factories.aggregations import EnumDTOFactory -from strawchemy.strawberry.factories.enum import EnumDTOBackend, UpsertConflictFieldsEnumDTOBackend - -from .config.base import StrawchemyConfig -from .dto.backend.strawberry import StrawberrryDTOBackend -from .dto.base import TYPING_NS -from .strawberry._field import ( +from strawchemy.config.base import StrawchemyConfig +from strawchemy.dto.backend.strawberry import StrawberrryDTOBackend +from strawchemy.dto.base import TYPING_NS +from strawchemy.strawberry._field import ( StrawchemyCreateMutationField, StrawchemyDeleteMutationField, StrawchemyField, StrawchemyUpdateMutationField, StrawchemyUpsertMutationField, ) -from .strawberry._registry import StrawberryRegistry -from .strawberry.dto import BooleanFilterDTO, EnumDTO, MappedStrawberryGraphQLDTO, OrderByDTO, OrderByEnum -from .strawberry.factories.inputs import AggregateFilterDTOFactory, BooleanFilterDTOFactory -from .strawberry.factories.types import ( +from strawchemy.strawberry._registry import StrawberryRegistry +from strawchemy.strawberry.dto import BooleanFilterDTO, EnumDTO, MappedStrawberryGraphQLDTO, OrderByDTO, OrderByEnum +from strawchemy.strawberry.factories.aggregations import EnumDTOFactory +from strawchemy.strawberry.factories.enum import EnumDTOBackend, UpsertConflictFieldsEnumDTOBackend +from strawchemy.strawberry.factories.inputs import AggregateFilterDTOFactory, BooleanFilterDTOFactory +from strawchemy.strawberry.factories.types import ( DistinctOnFieldsDTOFactory, InputFactory, OrderByDTOFactory, @@ -31,8 +30,8 @@ TypeDTOFactory, UpsertConflictFieldsDTOFactory, ) -from .strawberry.mutation import types -from .types import DefaultOffsetPagination +from strawchemy.strawberry.mutation import types +from strawchemy.types import DefaultOffsetPagination if TYPE_CHECKING: from collections.abc import Callable, Mapping, Sequence @@ -43,13 +42,12 @@ from strawberry import BasePermission from strawchemy.sqlalchemy.hook import QueryHook + from strawchemy.sqlalchemy.typing import QueryHookCallable + from strawchemy.strawberry.typing import FilterStatementCallable, MappedGraphQLDTO + from strawchemy.typing import AnyRepository, SupportedDialect + from strawchemy.validation.base import ValidationProtocol from strawchemy.validation.pydantic import PydanticMapper - from .sqlalchemy.typing import QueryHookCallable - from .strawberry.typing import FilterStatementCallable, MappedGraphQLDTO - from .typing import AnyRepository, SupportedDialect - from .validation.base import ValidationProtocol - T = TypeVar("T", bound="DeclarativeBase") @@ -158,7 +156,7 @@ def pydantic(self) -> PydanticMapper: Returns: An instance of PydanticMapper. """ - from .validation.pydantic import PydanticMapper # noqa: PLC0415 + from strawchemy.validation.pydantic import PydanticMapper # noqa: PLC0415 return PydanticMapper(self) diff --git a/src/strawchemy/sqlalchemy/__init__.py b/src/strawchemy/sqlalchemy/__init__.py index 763bfff2..591a708e 100644 --- a/src/strawchemy/sqlalchemy/__init__.py +++ b/src/strawchemy/sqlalchemy/__init__.py @@ -6,6 +6,10 @@ from __future__ import annotations -from .repository import SQLAlchemyGraphQLAsyncRepository, SQLAlchemyGraphQLRepository, SQLAlchemyGraphQLSyncRepository +from strawchemy.sqlalchemy.repository import ( + SQLAlchemyGraphQLAsyncRepository, + SQLAlchemyGraphQLRepository, + SQLAlchemyGraphQLSyncRepository, +) __all__ = ("SQLAlchemyGraphQLAsyncRepository", "SQLAlchemyGraphQLRepository", "SQLAlchemyGraphQLSyncRepository") diff --git a/src/strawchemy/sqlalchemy/_executor.py b/src/strawchemy/sqlalchemy/_executor.py index f67fc4bc..5326dc01 100644 --- a/src/strawchemy/sqlalchemy/_executor.py +++ b/src/strawchemy/sqlalchemy/_executor.py @@ -15,18 +15,16 @@ from typing_extensions import Self from strawchemy.dto import ModelT - -from .exceptions import QueryResultError -from .typing import AnyAsyncSession, AnySyncSession, DeclarativeT +from strawchemy.sqlalchemy.exceptions import QueryResultError +from strawchemy.sqlalchemy.typing import AnyAsyncSession, AnySyncSession, DeclarativeT if TYPE_CHECKING: from collections.abc import Callable, Generator, Sequence from sqlalchemy import Label, Result, Select, StatementLambdaElement + from strawchemy.sqlalchemy._scope import QueryScope from strawchemy.strawberry.typing import QueryNodeType - from ._scope import QueryScope - __all__ = ("AsyncQueryExecutor", "NodeResult", "QueryExecutor", "SyncQueryExecutor") diff --git a/src/strawchemy/sqlalchemy/_query.py b/src/strawchemy/sqlalchemy/_query.py index ec42d425..af633614 100644 --- a/src/strawchemy/sqlalchemy/_query.py +++ b/src/strawchemy/sqlalchemy/_query.py @@ -34,6 +34,8 @@ ) from strawchemy.constants import AGGREGATIONS_KEY, NODES_KEY from strawchemy.graph import merge_trees +from strawchemy.sqlalchemy.exceptions import TranspilingError +from strawchemy.sqlalchemy.typing import DeclarativeT, OrderBySpec from strawchemy.strawberry.dto import ( BooleanFilterDTO, EnumDTO, @@ -44,9 +46,6 @@ QueryNode, ) -from .exceptions import TranspilingError -from .typing import DeclarativeT, OrderBySpec - if TYPE_CHECKING: from collections.abc import Sequence @@ -56,11 +55,10 @@ from sqlalchemy.sql.selectable import NamedFromClause from strawchemy.config.databases import DatabaseFeatures + from strawchemy.sqlalchemy._scope import QueryScope + from strawchemy.sqlalchemy.hook import ColumnLoadingMode, QueryHook from strawchemy.strawberry.typing import QueryNodeType - from ._scope import QueryScope - from .hook import ColumnLoadingMode, QueryHook - __all__ = ("AggregationJoin", "Conjunction", "DistinctOn", "Join", "OrderBy", "QueryGraph", "Where") diff --git a/src/strawchemy/sqlalchemy/_scope.py b/src/strawchemy/sqlalchemy/_scope.py index d7a2c2e0..6d7f0272 100644 --- a/src/strawchemy/sqlalchemy/_scope.py +++ b/src/strawchemy/sqlalchemy/_scope.py @@ -35,23 +35,21 @@ from strawchemy.constants import NODES_KEY from strawchemy.dto.types import DTOConfig, Purpose from strawchemy.graph import Node +from strawchemy.sqlalchemy.exceptions import TranspilingError +from strawchemy.sqlalchemy.inspector import SQLAlchemyInspector +from strawchemy.sqlalchemy.typing import DeclarativeT from strawchemy.strawberry.dto import GraphQLFieldDefinition, QueryNode -from .exceptions import TranspilingError -from .inspector import SQLAlchemyInspector -from .typing import DeclarativeT - if TYPE_CHECKING: from collections.abc import Callable from sqlalchemy.orm.util import AliasedClass from sqlalchemy.sql.elements import NamedColumn + from strawchemy.sqlalchemy.typing import DeclarativeSubT, FunctionGenerator, RelationshipSide from strawchemy.strawberry.typing import QueryNodeType from strawchemy.typing import SupportedDialect - from .typing import DeclarativeSubT, FunctionGenerator, RelationshipSide - __all__ = ("NodeInspect", "QueryScope") _FunctionVisitor: TypeAlias = "Callable[[Function[Any]], ColumnElement[Any]]" diff --git a/src/strawchemy/sqlalchemy/_transpiler.py b/src/strawchemy/sqlalchemy/_transpiler.py index 8d195c47..8f1daaaf 100644 --- a/src/strawchemy/sqlalchemy/_transpiler.py +++ b/src/strawchemy/sqlalchemy/_transpiler.py @@ -35,20 +35,8 @@ true, ) from strawchemy.constants import AGGREGATIONS_KEY -from strawchemy.strawberry.dto import ( - AggregationFilter, - BooleanFilterDTO, - EnumDTO, - Filter, - OrderByDTO, - OrderByEnum, - OrderByRelationFilterDTO, - QueryNode, -) -from strawchemy.strawberry.filters import GraphQLComparison - -from ._executor import SyncQueryExecutor -from ._query import ( +from strawchemy.sqlalchemy._executor import SyncQueryExecutor +from strawchemy.sqlalchemy._query import ( AggregationJoin, Conjunction, DistinctOn, @@ -60,10 +48,21 @@ SubqueryBuilder, Where, ) -from ._scope import QueryScope -from .exceptions import TranspilingError -from .inspector import SQLAlchemyGraphQLInspector -from .typing import DeclarativeT, OrderBySpec, QueryExecutorT +from strawchemy.sqlalchemy._scope import QueryScope +from strawchemy.sqlalchemy.exceptions import TranspilingError +from strawchemy.sqlalchemy.inspector import SQLAlchemyGraphQLInspector +from strawchemy.sqlalchemy.typing import DeclarativeT, OrderBySpec, QueryExecutorT +from strawchemy.strawberry.dto import ( + AggregationFilter, + BooleanFilterDTO, + EnumDTO, + Filter, + OrderByDTO, + OrderByEnum, + OrderByRelationFilterDTO, + QueryNode, +) +from strawchemy.strawberry.filters import GraphQLComparison if TYPE_CHECKING: from collections.abc import Iterable, Iterator, Sequence @@ -73,11 +72,10 @@ from sqlalchemy.sql import ColumnElement, SQLColumnExpression from sqlalchemy.sql.elements import NamedColumn + from strawchemy.sqlalchemy.hook import QueryHook from strawchemy.strawberry.typing import QueryNodeType from strawchemy.typing import SupportedDialect - from .hook import QueryHook - __all__ = ("QueryTranspiler",) diff --git a/src/strawchemy/sqlalchemy/hook.py b/src/strawchemy/sqlalchemy/hook.py index 359c57e5..84b99dd5 100644 --- a/src/strawchemy/sqlalchemy/hook.py +++ b/src/strawchemy/sqlalchemy/hook.py @@ -16,8 +16,8 @@ from sqlalchemy.orm.strategy_options import _AbstractLoad from sqlalchemy.orm.util import AliasedClass -from .exceptions import QueryHookError -from .typing import DeclarativeT +from strawchemy.sqlalchemy.exceptions import QueryHookError +from strawchemy.sqlalchemy.typing import DeclarativeT if TYPE_CHECKING: from collections.abc import Sequence diff --git a/src/strawchemy/sqlalchemy/inspector.py b/src/strawchemy/sqlalchemy/inspector.py index 8cb05c28..5bd5ac53 100644 --- a/src/strawchemy/sqlalchemy/inspector.py +++ b/src/strawchemy/sqlalchemy/inspector.py @@ -37,10 +37,9 @@ if TYPE_CHECKING: from strawchemy.dto.base import DTOFieldDefinition + from strawchemy.sqlalchemy.typing import FilterMap from strawchemy.typing import SupportedDialect - from .typing import FilterMap - __all__ = ("SQLAlchemyGraphQLInspector", "loaded_attributes") diff --git a/src/strawchemy/sqlalchemy/repository/__init__.py b/src/strawchemy/sqlalchemy/repository/__init__.py index 20310e6f..20166143 100644 --- a/src/strawchemy/sqlalchemy/repository/__init__.py +++ b/src/strawchemy/sqlalchemy/repository/__init__.py @@ -1,7 +1,7 @@ from __future__ import annotations -from ._async import SQLAlchemyGraphQLAsyncRepository -from ._base import SQLAlchemyGraphQLRepository -from ._sync import SQLAlchemyGraphQLSyncRepository +from strawchemy.sqlalchemy.repository._async import SQLAlchemyGraphQLAsyncRepository +from strawchemy.sqlalchemy.repository._base import SQLAlchemyGraphQLRepository +from strawchemy.sqlalchemy.repository._sync import SQLAlchemyGraphQLSyncRepository __all__ = ("SQLAlchemyGraphQLAsyncRepository", "SQLAlchemyGraphQLRepository", "SQLAlchemyGraphQLSyncRepository") diff --git a/src/strawchemy/sqlalchemy/repository/_async.py b/src/strawchemy/sqlalchemy/repository/_async.py index 922739fe..e23afc6a 100644 --- a/src/strawchemy/sqlalchemy/repository/_async.py +++ b/src/strawchemy/sqlalchemy/repository/_async.py @@ -9,12 +9,11 @@ from sqlalchemy import ColumnElement, Row, and_, delete, inspect, select, update from strawchemy.sqlalchemy._executor import AsyncQueryExecutor, QueryResult from strawchemy.sqlalchemy._transpiler import QueryTranspiler +from strawchemy.sqlalchemy.repository._base import InsertData, MutationData, SQLAlchemyGraphQLRepository from strawchemy.sqlalchemy.typing import AnyAsyncSession, DeclarativeT from strawchemy.strawberry.mutation.input import UpsertData from strawchemy.strawberry.mutation.types import RelationType -from ._base import InsertData, MutationData, SQLAlchemyGraphQLRepository - if TYPE_CHECKING: from collections.abc import Sequence @@ -22,12 +21,11 @@ from sqlalchemy.orm.util import AliasedClass from strawchemy.sqlalchemy.hook import QueryHook + from strawchemy.sqlalchemy.repository._base import InsertOrUpdate, RowLike from strawchemy.strawberry.dto import BooleanFilterDTO, EnumDTO, OrderByDTO from strawchemy.strawberry.mutation.input import Input, LevelInput from strawchemy.strawberry.typing import QueryNodeType - from ._base import InsertOrUpdate, RowLike - __all__ = ("SQLAlchemyGraphQLAsyncRepository",) T = TypeVar("T", bound=Any) diff --git a/src/strawchemy/sqlalchemy/repository/_base.py b/src/strawchemy/sqlalchemy/repository/_base.py index 1c538121..c2755e84 100644 --- a/src/strawchemy/sqlalchemy/repository/_base.py +++ b/src/strawchemy/sqlalchemy/repository/_base.py @@ -3,7 +3,7 @@ import dataclasses from collections import defaultdict from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Generic, Literal, NamedTuple, TypeAlias, TypeVar, Union, cast +from typing import TYPE_CHECKING, Any, Generic, Literal, NamedTuple, TypeAlias, TypeVar, cast from sqlalchemy.dialects import mysql, postgresql, sqlite from sqlalchemy.orm import RelationshipProperty @@ -37,7 +37,7 @@ InsertOrUpdate: TypeAlias = Literal["insert", "update_by_pks", "update_where", "upsert"] RowLike: TypeAlias = "Row[Any] | NamedTuple" -_ModelOrTable: TypeAlias = "Union[type[DeclarativeBase], Table]" +_ModelOrTable: TypeAlias = "type[DeclarativeBase] | Table" @dataclass diff --git a/src/strawchemy/sqlalchemy/repository/_sync.py b/src/strawchemy/sqlalchemy/repository/_sync.py index 70594b97..83bc2d3d 100644 --- a/src/strawchemy/sqlalchemy/repository/_sync.py +++ b/src/strawchemy/sqlalchemy/repository/_sync.py @@ -11,12 +11,11 @@ from sqlalchemy import ColumnElement, Row, and_, delete, inspect, select, update from strawchemy.sqlalchemy._executor import QueryResult, SyncQueryExecutor from strawchemy.sqlalchemy._transpiler import QueryTranspiler +from strawchemy.sqlalchemy.repository._base import InsertData, MutationData, SQLAlchemyGraphQLRepository from strawchemy.sqlalchemy.typing import AnySyncSession, DeclarativeT from strawchemy.strawberry.mutation.input import UpsertData from strawchemy.strawberry.mutation.types import RelationType -from ._base import InsertData, MutationData, SQLAlchemyGraphQLRepository - if TYPE_CHECKING: from collections.abc import Sequence @@ -24,12 +23,11 @@ from sqlalchemy.orm.util import AliasedClass from strawchemy.sqlalchemy.hook import QueryHook + from strawchemy.sqlalchemy.repository._base import InsertOrUpdate, RowLike from strawchemy.strawberry.dto import BooleanFilterDTO, EnumDTO, OrderByDTO from strawchemy.strawberry.mutation.input import Input, LevelInput from strawchemy.strawberry.typing import QueryNodeType - from ._base import InsertOrUpdate, RowLike - __all__ = () T = TypeVar("T", bound=Any) diff --git a/src/strawchemy/sqlalchemy/typing.py b/src/strawchemy/sqlalchemy/typing.py index ca1b5ba4..84859424 100644 --- a/src/strawchemy/sqlalchemy/typing.py +++ b/src/strawchemy/sqlalchemy/typing.py @@ -11,12 +11,11 @@ from sqlalchemy.sql import SQLColumnExpression from sqlalchemy import Function + from strawchemy.sqlalchemy._executor import QueryExecutor + from strawchemy.sqlalchemy.hook import QueryHook from strawchemy.strawberry.dto import OrderByEnum from strawchemy.strawberry.filters.base import GraphQLComparison - from ._executor import QueryExecutor - from .hook import QueryHook - __all__ = ( "AnyAsyncSession", diff --git a/src/strawchemy/strawberry/__init__.py b/src/strawchemy/strawberry/__init__.py index 4daf49a0..038db7ff 100644 --- a/src/strawchemy/strawberry/__init__.py +++ b/src/strawchemy/strawberry/__init__.py @@ -1,8 +1,7 @@ from __future__ import annotations +from strawchemy.strawberry._instance import ModelInstance +from strawchemy.strawberry._utils import default_session_getter from strawchemy.types import DefaultOffsetPagination -from ._instance import ModelInstance -from ._utils import default_session_getter - __all__ = ("DefaultOffsetPagination", "ModelInstance", "default_session_getter") diff --git a/src/strawchemy/strawberry/_field.py b/src/strawchemy/strawberry/_field.py index c5929048..791e734d 100644 --- a/src/strawchemy/strawberry/_field.py +++ b/src/strawchemy/strawberry/_field.py @@ -26,6 +26,7 @@ ) from strawchemy.dto.base import MappedDTO from strawchemy.dto.types import DTOConfig, Purpose +from strawchemy.strawberry._utils import dto_model_from_type, strawberry_contained_types, strawberry_contained_user_type from strawchemy.strawberry.dto import ( BooleanFilterDTO, EnumDTO, @@ -33,16 +34,14 @@ OrderByDTO, StrawchemyDTOAttributes, ) +from strawchemy.strawberry.exceptions import StrawchemyFieldError from strawchemy.strawberry.mutation.input import Input +from strawchemy.strawberry.repository import StrawchemyAsyncRepository from strawchemy.types import DefaultOffsetPagination from strawchemy.typing import UNION_TYPES from strawchemy.utils import is_type_hint_optional from strawchemy.validation.base import InputValidationError -from ._utils import dto_model_from_type, strawberry_contained_types, strawberry_contained_user_type -from .exceptions import StrawchemyFieldError -from .repository import StrawchemyAsyncRepository - if TYPE_CHECKING: from collections.abc import Awaitable, Callable, Coroutine, Mapping @@ -56,18 +55,17 @@ from strawchemy import StrawchemyConfig from strawchemy.sqlalchemy.typing import QueryHookCallable from strawchemy.strawberry.dto import BooleanFilterDTO, EnumDTO, OrderByDTO - from strawchemy.typing import AnyRepository - from strawchemy.validation.base import ValidationProtocol - - from .mutation.types import ValidationErrorType - from .repository import StrawchemySyncRepository - from .repository._base import GraphQLResult - from .typing import ( + from strawchemy.strawberry.mutation.types import ValidationErrorType + from strawchemy.strawberry.repository import StrawchemySyncRepository + from strawchemy.strawberry.repository._base import GraphQLResult + from strawchemy.strawberry.typing import ( AnyMappedDTO, FilterStatementCallable, MappedGraphQLDTO, StrawchemyTypeWithStrawberryObjectDefinition, ) + from strawchemy.typing import AnyRepository + from strawchemy.validation.base import ValidationProtocol __all__ = ("StrawchemyCreateMutationField", "StrawchemyDeleteMutationField", "StrawchemyField") diff --git a/src/strawchemy/strawberry/_registry.py b/src/strawchemy/strawberry/_registry.py index 4a9f2380..ae2be4c0 100644 --- a/src/strawchemy/strawberry/_registry.py +++ b/src/strawchemy/strawberry/_registry.py @@ -23,8 +23,7 @@ from strawberry.types.field import StrawberryField import strawberry - -from ._utils import strawberry_contained_types +from strawchemy.strawberry._utils import strawberry_contained_types try: from strawchemy.strawberry.filters.geo import GeoComparison @@ -43,11 +42,9 @@ from strawberry.types.base import WithStrawberryObjectDefinition from strawchemy.dto.types import DTOScope - from strawchemy.strawberry.typing import StrawchemyTypeWithStrawberryObjectDefinition + from strawchemy.strawberry.typing import GraphQLType, StrawchemyTypeWithStrawberryObjectDefinition from strawchemy.types import DefaultOffsetPagination - from .typing import GraphQLType - __all__ = ("RegistryTypeInfo", "StrawberryRegistry") diff --git a/src/strawchemy/strawberry/_utils.py b/src/strawchemy/strawberry/_utils.py index ca38862e..fb34d2c8 100644 --- a/src/strawchemy/strawberry/_utils.py +++ b/src/strawchemy/strawberry/_utils.py @@ -7,8 +7,7 @@ from strawberry.types.union import StrawberryUnion from strawchemy.exceptions import SessionNotFoundError - -from .mutation.types import ErrorType +from strawchemy.strawberry.mutation.types import ErrorType if TYPE_CHECKING: from strawberry import Info diff --git a/src/strawchemy/strawberry/dto.py b/src/strawchemy/strawberry/dto.py index 0bba43b0..3c6e6fed 100644 --- a/src/strawchemy/strawberry/dto.py +++ b/src/strawchemy/strawberry/dto.py @@ -50,15 +50,14 @@ from strawchemy.dto.types import DTOConfig, DTOFieldConfig, DTOMissing, Purpose from strawchemy.graph import AnyNode, GraphMetadata, MatchOn, Node, NodeMetadata, NodeT from strawchemy.sqlalchemy.hook import QueryHook # noqa: TC001 +from strawchemy.strawberry.typing import GraphQLPurpose, OrderByDTOT, QueryNodeType from strawchemy.utils import camel_to_snake -from .typing import GraphQLPurpose, OrderByDTOT, QueryNodeType - if TYPE_CHECKING: from collections.abc import Callable, Hashable, Sequence - from .filters import EqualityComparison, GraphQLComparison - from .typing import AggregationFunction, AggregationType, FunctionInfo + from strawchemy.strawberry.filters import EqualityComparison, GraphQLComparison + from strawchemy.strawberry.typing import AggregationFunction, AggregationType, FunctionInfo T = TypeVar("T") diff --git a/src/strawchemy/strawberry/factories/aggregations.py b/src/strawchemy/strawberry/factories/aggregations.py index fb9c7706..45777fe1 100644 --- a/src/strawchemy/strawberry/factories/aggregations.py +++ b/src/strawchemy/strawberry/factories/aggregations.py @@ -19,9 +19,8 @@ OutputFunctionInfo, UnmappedStrawberryGraphQLDTO, ) - -from .base import GraphQLDTOFactory -from .enum import EnumDTOBackend, EnumDTOFactory +from strawchemy.strawberry.factories.base import GraphQLDTOFactory +from strawchemy.strawberry.factories.enum import EnumDTOBackend, EnumDTOFactory if TYPE_CHECKING: from collections.abc import Generator diff --git a/src/strawchemy/strawberry/factories/inputs.py b/src/strawchemy/strawberry/factories/inputs.py index 45e3c208..6656ef7c 100644 --- a/src/strawchemy/strawberry/factories/inputs.py +++ b/src/strawchemy/strawberry/factories/inputs.py @@ -25,12 +25,11 @@ OrderByDTO, OrderByEnum, ) +from strawchemy.strawberry.factories.aggregations import AggregationInspector +from strawchemy.strawberry.factories.base import StrawchemyUnMappedDTOFactory, UnmappedGraphQLDTOT from strawchemy.strawberry.typing import AggregationFunction, GraphQLFilterDTOT, GraphQLPurpose from strawchemy.utils import snake_to_camel -from .aggregations import AggregationInspector -from .base import StrawchemyUnMappedDTOFactory, UnmappedGraphQLDTOT - if TYPE_CHECKING: from collections.abc import Callable, Generator, Mapping, Sequence diff --git a/src/strawchemy/strawberry/factories/types.py b/src/strawchemy/strawberry/factories/types.py index 3df9aafe..b6fce185 100644 --- a/src/strawchemy/strawberry/factories/types.py +++ b/src/strawchemy/strawberry/factories/types.py @@ -24,6 +24,15 @@ GraphQLFieldDefinition, MappedStrawberryGraphQLDTO, ) +from strawchemy.strawberry.factories.aggregations import AggregationInspector +from strawchemy.strawberry.factories.base import ( + GraphQLDTOFactory, + MappedGraphQLDTOT, + StrawchemyMappedFactory, + _ChildOptions, +) +from strawchemy.strawberry.factories.enum import EnumDTOFactory, UpsertConflictFieldsEnumDTOBackend +from strawchemy.strawberry.factories.inputs import OrderByDTOFactory from strawchemy.strawberry.mutation.types import ( RequiredToManyUpdateInput, RequiredToOneInput, @@ -34,11 +43,6 @@ from strawchemy.strawberry.typing import AggregateDTOT, GraphQLDTOT, GraphQLPurpose from strawchemy.utils import get_annotations, non_optional_type_hint, snake_to_camel -from .aggregations import AggregationInspector -from .base import GraphQLDTOFactory, MappedGraphQLDTOT, StrawchemyMappedFactory, _ChildOptions -from .enum import EnumDTOFactory, UpsertConflictFieldsEnumDTOBackend -from .inputs import OrderByDTOFactory - if TYPE_CHECKING: from collections.abc import Generator, Hashable, Sequence from enum import Enum diff --git a/src/strawchemy/strawberry/filters/__init__.py b/src/strawchemy/strawberry/filters/__init__.py index cf9f7ec7..26b4388c 100644 --- a/src/strawchemy/strawberry/filters/__init__.py +++ b/src/strawchemy/strawberry/filters/__init__.py @@ -1,6 +1,6 @@ from __future__ import annotations -from .inputs import ( +from strawchemy.strawberry.filters.inputs import ( ArrayComparison, DateComparison, DateTimeComparison, diff --git a/src/strawchemy/strawberry/filters/base.py b/src/strawchemy/strawberry/filters/base.py index e08e3e2d..0798befa 100644 --- a/src/strawchemy/strawberry/filters/base.py +++ b/src/strawchemy/strawberry/filters/base.py @@ -16,7 +16,7 @@ from sqlalchemy.orm import QueryableAttribute - from .inputs import ( + from strawchemy.strawberry.filters.inputs import ( ArrayComparison, DateComparison, DateTimeComparison, diff --git a/src/strawchemy/strawberry/filters/geo.py b/src/strawchemy/strawberry/filters/geo.py index c06bba54..f8ca87d9 100644 --- a/src/strawchemy/strawberry/filters/geo.py +++ b/src/strawchemy/strawberry/filters/geo.py @@ -11,11 +11,10 @@ import strawberry from sqlalchemy import ColumnElement, Dialect, null from strawberry import UNSET +from strawchemy.strawberry.filters.base import FilterProtocol +from strawchemy.strawberry.filters.inputs import GraphQLComparison from strawchemy.strawberry.geo import GeoJSON -from .base import FilterProtocol -from .inputs import GraphQLComparison - __all__ = ("GeoComparison",) T = TypeVar("T") diff --git a/src/strawchemy/strawberry/filters/inputs.py b/src/strawchemy/strawberry/filters/inputs.py index be6724a9..fec2706e 100644 --- a/src/strawchemy/strawberry/filters/inputs.py +++ b/src/strawchemy/strawberry/filters/inputs.py @@ -17,9 +17,7 @@ import strawberry from sqlalchemy import Dialect from strawberry import UNSET, Private -from strawchemy.strawberry.typing import QueryNodeType - -from .base import ( +from strawchemy.strawberry.filters.base import ( ArrayFilter, DateFilter, DateTimeFilter, @@ -31,6 +29,7 @@ TimeDeltaFilter, TimeFilter, ) +from strawchemy.strawberry.typing import QueryNodeType if TYPE_CHECKING: from sqlalchemy.orm import QueryableAttribute diff --git a/src/strawchemy/strawberry/mutation/input.py b/src/strawchemy/strawberry/mutation/input.py index 5c63887f..e9963d25 100644 --- a/src/strawchemy/strawberry/mutation/input.py +++ b/src/strawchemy/strawberry/mutation/input.py @@ -11,8 +11,14 @@ from sqlalchemy import event, inspect from strawchemy.dto.base import DTOFieldDefinition, MappedDTO, ToMappedProtocol, VisitorProtocol from strawchemy.dto.inspectors.sqlalchemy import SQLAlchemyInspector - -from .types import RelationType, ToManyCreateInput, ToManyUpdateInput, ToManyUpsertInput, ToOneInput, ToOneUpsertInput +from strawchemy.strawberry.mutation.types import ( + RelationType, + ToManyCreateInput, + ToManyUpdateInput, + ToManyUpsertInput, + ToOneInput, + ToOneUpsertInput, +) if TYPE_CHECKING: from collections.abc import Iterable diff --git a/src/strawchemy/strawberry/repository/__init__.py b/src/strawchemy/strawberry/repository/__init__.py index bc33ee75..637b27b3 100644 --- a/src/strawchemy/strawberry/repository/__init__.py +++ b/src/strawchemy/strawberry/repository/__init__.py @@ -1,6 +1,6 @@ from __future__ import annotations -from ._async import StrawchemyAsyncRepository -from ._sync import StrawchemySyncRepository +from strawchemy.strawberry.repository._async import StrawchemyAsyncRepository +from strawchemy.strawberry.repository._sync import StrawchemySyncRepository __all__ = ("StrawchemyAsyncRepository", "StrawchemySyncRepository") diff --git a/src/strawchemy/strawberry/repository/_async.py b/src/strawchemy/strawberry/repository/_async.py index 88bd1b75..b806ebbc 100644 --- a/src/strawchemy/strawberry/repository/_async.py +++ b/src/strawchemy/strawberry/repository/_async.py @@ -11,8 +11,7 @@ from strawchemy.sqlalchemy.repository import SQLAlchemyGraphQLAsyncRepository from strawchemy.strawberry._utils import default_session_getter, dto_model_from_type, strawberry_contained_user_type - -from ._base import GraphQLResult, StrawchemyRepository +from strawchemy.strawberry.repository._base import GraphQLResult, StrawchemyRepository if TYPE_CHECKING: from sqlalchemy import Select diff --git a/src/strawchemy/strawberry/repository/_base.py b/src/strawchemy/strawberry/repository/_base.py index 391e6402..0e688199 100644 --- a/src/strawchemy/strawberry/repository/_base.py +++ b/src/strawchemy/strawberry/repository/_base.py @@ -31,10 +31,9 @@ StrawchemyDTOAttributes, ) from strawchemy.strawberry.mutation.types import error_type_names +from strawchemy.strawberry.repository._node import StrawberryQueryNode from strawchemy.utils import camel_to_snake, snake_keys -from ._node import StrawberryQueryNode - if TYPE_CHECKING: from strawberry.types.field import StrawberryField diff --git a/src/strawchemy/strawberry/repository/_sync.py b/src/strawchemy/strawberry/repository/_sync.py index 80a2e2b7..09416265 100644 --- a/src/strawchemy/strawberry/repository/_sync.py +++ b/src/strawchemy/strawberry/repository/_sync.py @@ -13,8 +13,7 @@ from strawchemy.sqlalchemy.repository import SQLAlchemyGraphQLSyncRepository from strawchemy.strawberry._utils import default_session_getter, dto_model_from_type, strawberry_contained_user_type - -from ._base import GraphQLResult, StrawchemyRepository +from strawchemy.strawberry.repository._base import GraphQLResult, StrawchemyRepository if TYPE_CHECKING: from sqlalchemy import Select diff --git a/src/strawchemy/strawberry/typing.py b/src/strawchemy/strawberry/typing.py index 5032efd4..3b56b4df 100644 --- a/src/strawchemy/strawberry/typing.py +++ b/src/strawchemy/strawberry/typing.py @@ -11,18 +11,19 @@ from strawberry import Info from strawchemy.graph import Node from strawchemy.sqlalchemy.typing import AnyAsyncSession, AnySyncSession - from strawchemy.strawberry.dto import GraphQLFieldDefinition, QueryNodeMetadata, StrawchemyDTOAttributes - from strawchemy.validation.pydantic import MappedPydanticGraphQLDTO - - from .dto import ( + from strawchemy.strawberry.dto import ( AggregateDTO, FilterFunctionInfo, + GraphQLFieldDefinition, GraphQLFilterDTO, MappedStrawberryGraphQLDTO, OrderByDTO, OutputFunctionInfo, + QueryNodeMetadata, + StrawchemyDTOAttributes, UnmappedStrawberryGraphQLDTO, ) + from strawchemy.validation.pydantic import MappedPydanticGraphQLDTO __all__ = ( "AnySessionGetter", diff --git a/src/strawchemy/testing/__init__.py b/src/strawchemy/testing/__init__.py index b76371da..9901cf41 100644 --- a/src/strawchemy/testing/__init__.py +++ b/src/strawchemy/testing/__init__.py @@ -1,5 +1,5 @@ from __future__ import annotations -from .pytest_plugin import MockContext +from strawchemy.testing.pytest_plugin import MockContext __all__ = ("MockContext",) diff --git a/src/strawchemy/typing.py b/src/strawchemy/typing.py index 84e113ce..8e8653b9 100644 --- a/src/strawchemy/typing.py +++ b/src/strawchemy/typing.py @@ -7,7 +7,7 @@ if TYPE_CHECKING: - from . import StrawchemyAsyncRepository, StrawchemySyncRepository + from strawchemy import StrawchemyAsyncRepository, StrawchemySyncRepository __all__ = ("UNION_TYPES", "AnyRepository", "DataclassProtocol", "SupportedDialect") diff --git a/src/strawchemy/validation/pydantic.py b/src/strawchemy/validation/pydantic.py index efd0a82c..371aad6d 100644 --- a/src/strawchemy/validation/pydantic.py +++ b/src/strawchemy/validation/pydantic.py @@ -16,8 +16,7 @@ from strawchemy.strawberry.factories.types import InputFactory from strawchemy.strawberry.mutation.types import LocalizedErrorType, ValidationErrorType from strawchemy.utils import snake_to_lower_camel_case - -from .base import InputValidationError, T, ValidationProtocol +from strawchemy.validation.base import InputValidationError, T, ValidationProtocol if TYPE_CHECKING: from collections.abc import Callable, Mapping, Sequence diff --git a/tests/conftest.py b/tests/conftest.py index 1a458eb4..d7b48e27 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,4 @@ -from .fixtures import fx_sqlalchemy_pydantic_factory, graphql_snapshot, sql_snapshot, strawchemy, sync_query +from tests.fixtures import fx_sqlalchemy_pydantic_factory, graphql_snapshot, sql_snapshot, strawchemy, sync_query pytest_plugins = ("pytest_databases.docker.postgres", "pytest_databases.docker.mysql", "pytester") diff --git a/tests/fixtures.py b/tests/fixtures.py index 5d983ccb..ee1d4038 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -9,10 +9,9 @@ import strawberry from strawchemy import Strawchemy, StrawchemyConfig +from tests.syrupy import GraphQLFileExtension from tests.utils import sqlalchemy_pydantic_factory -from .syrupy import GraphQLFileExtension - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 431202ff..5761a284 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,6 +1,6 @@ from __future__ import annotations -from .fixtures import ( +from tests.integration.fixtures import ( aiosqlite_engine, any_query, any_session, diff --git a/tests/integration/fixtures.py b/tests/integration/fixtures.py index 5ff6cf3c..c82d9e0c 100644 --- a/tests/integration/fixtures.py +++ b/tests/integration/fixtures.py @@ -41,6 +41,17 @@ from strawchemy.constants import GEO_INSTALLED from strawchemy.strawberry.scalars import Date, DateTime, Interval, Time from tests.fixtures import DefaultQuery +from tests.integration.models import ( + Color, + Department, + Fruit, + FruitFarm, + Group, + Topic, + User, + UserDepartmentJoinTable, + metadata, +) from tests.integration.types import AnyAsyncMutationType, AnyAsyncQueryType, AnySyncQueryType from tests.integration.types import mysql as mysql_types from tests.integration.types import postgres as postgres_types @@ -48,8 +59,6 @@ from tests.typing import AnyQueryExecutor, SyncQueryExecutor from tests.utils import generate_query -from .models import Color, Department, Fruit, FruitFarm, Group, Topic, User, UserDepartmentJoinTable, metadata - if TYPE_CHECKING: from collections.abc import AsyncGenerator, Generator, Iterator from pathlib import Path @@ -64,8 +73,7 @@ from strawchemy import Strawchemy, StrawchemyConfig from strawchemy.sqlalchemy.typing import AnySession from strawchemy.typing import SupportedDialect - - from .typing import RawRecordData + from tests.integration.typing import RawRecordData __all__ = ( "QueryTracker", diff --git a/tests/integration/geo/test_geo_filters.py b/tests/integration/geo/test_geo_filters.py index 99183b61..cf5724aa 100644 --- a/tests/integration/geo/test_geo_filters.py +++ b/tests/integration/geo/test_geo_filters.py @@ -9,14 +9,13 @@ from sqlalchemy import Executable, Insert, MetaData, insert, text from tests.integration.fixtures import QueryTracker +from tests.integration.geo.models import GeoModel, geo_metadata from tests.integration.geo.types import mysql as mysql_types from tests.integration.geo.types import postgres as postgres_types from tests.integration.utils import to_graphql_representation from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .models import GeoModel, geo_metadata - if TYPE_CHECKING: from pytest_databases.docker.postgres import PostgresService from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_aggregation_filters.py b/tests/integration/test_aggregation_filters.py index 9ec789e7..83d94e93 100644 --- a/tests/integration/test_aggregation_filters.py +++ b/tests/integration/test_aggregation_filters.py @@ -4,13 +4,12 @@ import pytest +from tests.integration.fixtures import QueryTracker +from tests.integration.typing import RawRecordData from tests.integration.utils import to_graphql_representation from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker -from .typing import RawRecordData - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_aggregations.py b/tests/integration/test_aggregations.py index d30aee40..7ecc6937 100644 --- a/tests/integration/test_aggregations.py +++ b/tests/integration/test_aggregations.py @@ -5,14 +5,13 @@ import pytest from strawchemy.types import DefaultOffsetPagination +from tests.integration.fixtures import QueryTracker from tests.integration.models import Fruit +from tests.integration.typing import RawRecordData +from tests.integration.utils import compute_aggregation, from_graphql_representation, python_type from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker -from .typing import RawRecordData -from .utils import compute_aggregation, from_graphql_representation, python_type - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_custom_resolver.py b/tests/integration/test_custom_resolver.py index 156c04e5..7c6048eb 100644 --- a/tests/integration/test_custom_resolver.py +++ b/tests/integration/test_custom_resolver.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion - from .fixtures import QueryTracker + from tests.integration.fixtures import QueryTracker pytestmark = [pytest.mark.integration] diff --git a/tests/integration/test_distinct_on.py b/tests/integration/test_distinct_on.py index 7048548b..027af48a 100644 --- a/tests/integration/test_distinct_on.py +++ b/tests/integration/test_distinct_on.py @@ -4,12 +4,11 @@ import pytest +from tests.integration.fixtures import QueryTracker +from tests.integration.typing import RawRecordData from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker -from .typing import RawRecordData - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_field_extension.py b/tests/integration/test_field_extension.py index e73a04b6..a6a51314 100644 --- a/tests/integration/test_field_extension.py +++ b/tests/integration/test_field_extension.py @@ -2,11 +2,10 @@ import pytest +from tests.integration.typing import RawRecordData from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .typing import RawRecordData - pytestmark = [pytest.mark.integration] diff --git a/tests/integration/test_filters.py b/tests/integration/test_filters.py index 72c941b7..b3e499ff 100644 --- a/tests/integration/test_filters.py +++ b/tests/integration/test_filters.py @@ -4,13 +4,12 @@ import pytest +from tests.integration.fixtures import QueryTracker +from tests.integration.typing import RawRecordData +from tests.integration.utils import to_graphql_representation from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker -from .typing import RawRecordData -from .utils import to_graphql_representation - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_mutations.py b/tests/integration/test_mutations.py index 7ad17e97..c5564648 100644 --- a/tests/integration/test_mutations.py +++ b/tests/integration/test_mutations.py @@ -4,13 +4,12 @@ import pytest +from tests.integration.fixtures import QueryTracker +from tests.integration.typing import RawRecordData from tests.integration.utils import to_graphql_representation from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker -from .typing import RawRecordData - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_optimizations.py b/tests/integration/test_optimizations.py index 806432b1..d7c3959d 100644 --- a/tests/integration/test_optimizations.py +++ b/tests/integration/test_optimizations.py @@ -6,11 +6,10 @@ import pytest +from tests.integration.fixtures import QueryTracker from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/test_order_by.py b/tests/integration/test_order_by.py index 86f8731d..0957f502 100644 --- a/tests/integration/test_order_by.py +++ b/tests/integration/test_order_by.py @@ -4,13 +4,12 @@ import pytest +from tests.integration.fixtures import QueryTracker +from tests.integration.typing import RawRecordData +from tests.integration.utils import compute_aggregation from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker -from .typing import RawRecordData -from .utils import compute_aggregation - if TYPE_CHECKING: from decimal import Decimal diff --git a/tests/integration/test_queries.py b/tests/integration/test_queries.py index 57ef34b9..2522068b 100644 --- a/tests/integration/test_queries.py +++ b/tests/integration/test_queries.py @@ -6,16 +6,15 @@ from graphql import GraphQLError from strawberry.types import get_object_definition +from tests.integration.types.postgres import UserType +from tests.integration.typing import RawRecordData from tests.typing import AnyQueryExecutor, SyncQueryExecutor from tests.utils import maybe_async -from .types.postgres import UserType -from .typing import RawRecordData - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion - from .fixtures import QueryTracker + from tests.integration.fixtures import QueryTracker pytestmark = [pytest.mark.integration] diff --git a/tests/integration/test_query_hooks.py b/tests/integration/test_query_hooks.py index d73b1a97..d90fc7c0 100644 --- a/tests/integration/test_query_hooks.py +++ b/tests/integration/test_query_hooks.py @@ -4,15 +4,14 @@ import pytest +from tests.integration.typing import RawRecordData from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .typing import RawRecordData - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion - from .fixtures import QueryTracker + from tests.integration.fixtures import QueryTracker pytestmark = [pytest.mark.integration] diff --git a/tests/integration/test_schema.py b/tests/integration/test_schema.py index 89392e01..420ac30d 100644 --- a/tests/integration/test_schema.py +++ b/tests/integration/test_schema.py @@ -1,9 +1,8 @@ from __future__ import annotations from strawberry import Schema - -from .fixtures import scalar_overrides -from .types import mysql, postgres +from tests.integration.fixtures import scalar_overrides +from tests.integration.types import mysql, postgres def test_schema() -> None: diff --git a/tests/integration/test_upsert.py b/tests/integration/test_upsert.py index 3ed9e463..718fc731 100644 --- a/tests/integration/test_upsert.py +++ b/tests/integration/test_upsert.py @@ -4,11 +4,10 @@ import pytest +from tests.integration.fixtures import QueryTracker from tests.typing import AnyQueryExecutor from tests.utils import maybe_async -from .fixtures import QueryTracker - if TYPE_CHECKING: from syrupy.assertion import SnapshotAssertion diff --git a/tests/integration/types/__init__.py b/tests/integration/types/__init__.py index b3da6d2f..8c246071 100644 --- a/tests/integration/types/__init__.py +++ b/tests/integration/types/__init__.py @@ -1,12 +1,12 @@ from __future__ import annotations -from typing import TypeAlias, Union +from typing import TypeAlias -from . import mysql, postgres, sqlite +from tests.integration.types import mysql, postgres, sqlite __all__ = ("AnyAsyncMutationType", "AnyAsyncQueryType", "AnySyncMutationType", "AnySyncQueryType") -AnyAsyncQueryType: TypeAlias = Union[Union[postgres.AsyncQuery, mysql.AsyncQuery], sqlite.AsyncQuery] -AnySyncQueryType: TypeAlias = Union[Union[postgres.SyncQuery, mysql.SyncQuery], sqlite.SyncQuery] -AnyAsyncMutationType: TypeAlias = Union[Union[postgres.AsyncMutation, mysql.AsyncMutation], sqlite.AsyncMutation] -AnySyncMutationType: TypeAlias = Union[Union[postgres.SyncMutation, mysql.SyncMutation], sqlite.SyncMutation] +AnyAsyncQueryType: TypeAlias = "postgres.AsyncQuery | mysql.AsyncQuery | sqlite.AsyncQuery" +AnySyncQueryType: TypeAlias = "postgres.SyncQuery | mysql.SyncQuery | sqlite.SyncQuery" +AnyAsyncMutationType: TypeAlias = "postgres.AsyncMutation | mysql.AsyncMutation | sqlite.AsyncMutation" +AnySyncMutationType: TypeAlias = "postgres.SyncMutation | mysql.SyncMutation | sqlite.SyncMutation" diff --git a/tests/unit/dc_models.py b/tests/unit/dc_models.py index 042007ce..4879fa33 100644 --- a/tests/unit/dc_models.py +++ b/tests/unit/dc_models.py @@ -8,8 +8,7 @@ from sqlalchemy import ForeignKey from strawchemy.dto import Purpose, PurposeConfig, field from strawchemy.dto.utils import WRITE_ONLY - -from .models import validate_tomato_type +from tests.unit.models import validate_tomato_type class UUIDBase(MappedAsDataclass, DeclarativeBase): diff --git a/tests/unit/test_mutation_input.py b/tests/unit/test_mutation_input.py index 85f5afcd..d1f3c2d8 100644 --- a/tests/unit/test_mutation_input.py +++ b/tests/unit/test_mutation_input.py @@ -6,9 +6,8 @@ from strawchemy import Strawchemy from strawchemy.strawberry.mutation.input import Input - -from .dc_models import ColorDataclass, FruitDataclass -from .models import Color, Fruit +from tests.unit.dc_models import ColorDataclass, FruitDataclass +from tests.unit.models import Color, Fruit @pytest.mark.parametrize(("color_model", "fruit_model"), [(Color, Fruit), (ColorDataclass, FruitDataclass)]) diff --git a/tests/utils.py b/tests/utils.py index b3752276..004f6d98 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -25,8 +25,7 @@ from strawchemy.sqlalchemy.typing import AnySession from strawchemy.typing import DataclassProtocol - - from .typing import AnyQueryExecutor, AsyncQueryExecutor, SyncQueryExecutor + from tests.typing import AnyQueryExecutor, AsyncQueryExecutor, SyncQueryExecutor __all__ = ("DTOInspect", "generate_query", "sqlalchemy_pydantic_factory") diff --git a/uv.lock b/uv.lock index 4351f8fe..77c2328d 100644 --- a/uv.lock +++ b/uv.lock @@ -752,8 +752,8 @@ wheels = [ [package.optional-dependencies] toml = [ - { name = "tomli", version = "2.0.2", source = { registry = "https://pypi.org/simple" }, marker = "(python_full_version <= '3.11' and extra == 'group-10-strawchemy-build') or (python_full_version <= '3.11' and extra == 'group-10-strawchemy-dev') or (extra == 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash') or (extra == 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev')" }, - { name = "tomli", version = "2.3.0", source = { registry = "https://pypi.org/simple" }, marker = "(python_full_version <= '3.11' and extra == 'group-10-strawchemy-codeflash') or (python_full_version <= '3.11' and extra != 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-dev') or (extra == 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash') or (extra == 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev')" }, + { name = "tomli", version = "2.0.2", source = { registry = "https://pypi.org/simple" }, marker = "(python_full_version < '3.11' and extra == 'group-10-strawchemy-build') or (python_full_version < '3.11' and extra == 'group-10-strawchemy-dev') or (extra == 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash') or (extra == 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev')" }, + { name = "tomli", version = "2.3.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11' or (python_full_version < '3.11' and extra == 'group-10-strawchemy-codeflash') or (python_full_version < '3.11' and extra != 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-dev') or (python_full_version > '3.11' and extra == 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash') or (python_full_version > '3.11' and extra == 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev')" }, ] [[package]] @@ -984,7 +984,7 @@ name = "exceptiongroup" version = "1.3.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "typing-extensions", marker = "python_full_version < '3.13' or (extra == 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash') or (extra == 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev')" }, + { name = "typing-extensions", marker = "python_full_version < '3.11' or (extra == 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash') or (extra == 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev')" }, ] sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" } wheels = [ @@ -3313,7 +3313,7 @@ test = [ requires-dist = [ { name = "geoalchemy2", marker = "extra == 'geo'" }, { name = "geojson-pydantic", marker = "extra == 'geo'" }, - { name = "msgspec" }, + { name = "msgspec", specifier = ">=0.4.2" }, { name = "pydantic", marker = "extra == 'pydantic'" }, { name = "shapely", marker = "extra == 'geo'" }, { name = "sqlalchemy", specifier = ">=2.0.10" }, @@ -3437,7 +3437,6 @@ name = "tomli" version = "2.0.2" source = { registry = "https://pypi.org/simple" } resolution-markers = [ - "python_full_version >= '3.11' and python_full_version < '3.13'", "python_full_version < '3.11'", ] sdist = { url = "https://files.pythonhosted.org/packages/35/b9/de2a5c0144d7d75a57ff355c0c24054f965b2dc3036456ae03a51ea6264b/tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed", size = 16096, upload-time = "2024-10-02T10:46:13.208Z" } @@ -3452,6 +3451,9 @@ source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.11' and python_full_version < '3.13' and extra != 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash' and extra != 'group-10-strawchemy-dev'", "python_full_version < '3.11' and extra != 'group-10-strawchemy-build' and extra == 'group-10-strawchemy-codeflash' and extra != 'group-10-strawchemy-dev'", + "python_full_version >= '3.11' and python_full_version < '3.13' and extra == 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev'", + "python_full_version >= '3.11' and python_full_version < '3.13' and extra == 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-codeflash' and extra != 'group-10-strawchemy-dev'", + "python_full_version >= '3.11' and python_full_version < '3.13' and extra != 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-codeflash' and extra == 'group-10-strawchemy-dev'", "python_full_version >= '3.11' and extra != 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-codeflash' and extra != 'group-10-strawchemy-dev'", "python_full_version < '3.11' and extra != 'group-10-strawchemy-build' and extra != 'group-10-strawchemy-codeflash' and extra != 'group-10-strawchemy-dev'", ]