sqlspec 0.6.0__py3-none-any.whl → 0.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sqlspec might be problematic. Click here for more details.

sqlspec/__init__.py CHANGED
@@ -1 +0,0 @@
1
- from __future__ import annotations
sqlspec/__metadata__.py CHANGED
@@ -1,7 +1,5 @@
1
1
  """Metadata for the Project."""
2
2
 
3
- from __future__ import annotations
4
-
5
3
  from importlib.metadata import PackageNotFoundError, metadata, version
6
4
 
7
5
  __all__ = ("__project__", "__version__")
sqlspec/_serialization.py CHANGED
@@ -1,24 +1,71 @@
1
+ import datetime
2
+ import enum
1
3
  from typing import Any
2
4
 
3
- __all__ = ("decode_json", "encode_json")
5
+ from sqlspec._typing import PYDANTIC_INSTALLED, BaseModel
6
+
7
+
8
+ def _type_to_string(value: Any) -> str: # pragma: no cover
9
+ if isinstance(value, datetime.datetime):
10
+ return convert_datetime_to_gmt_iso(value)
11
+ if isinstance(value, datetime.date):
12
+ return convert_date_to_iso(value)
13
+ if isinstance(value, enum.Enum):
14
+ return str(value.value)
15
+ if PYDANTIC_INSTALLED and isinstance(value, BaseModel):
16
+ return value.model_dump_json()
17
+ try:
18
+ val = str(value)
19
+ except Exception as exc:
20
+ raise TypeError from exc
21
+ return val
22
+
4
23
 
5
24
  try:
6
- from msgspec.json import Decoder, Encoder # pyright: ignore[reportMissingImports]
25
+ from msgspec.json import Decoder, Encoder
7
26
 
8
- encoder, decoder = Encoder(), Decoder()
27
+ encoder, decoder = Encoder(enc_hook=_type_to_string), Decoder()
9
28
  decode_json = decoder.decode
10
29
 
11
- def encode_json(data: Any) -> str:
30
+ def encode_json(data: Any) -> str: # pragma: no cover
12
31
  return encoder.encode(data).decode("utf-8")
13
32
 
14
33
  except ImportError:
15
34
  try:
16
- from orjson import dumps as _encode_json # pyright: ignore[reportMissingImports,reportUnknownVariableType]
17
- from orjson import loads as decode_json # type: ignore[no-redef]
35
+ from orjson import ( # pyright: ignore[reportMissingImports]
36
+ OPT_NAIVE_UTC, # pyright: ignore[reportUnknownVariableType]
37
+ OPT_SERIALIZE_NUMPY, # pyright: ignore[reportUnknownVariableType]
38
+ OPT_SERIALIZE_UUID, # pyright: ignore[reportUnknownVariableType]
39
+ )
40
+ from orjson import dumps as _encode_json # pyright: ignore[reportUnknownVariableType,reportMissingImports]
41
+ from orjson import loads as decode_json # type: ignore[no-redef,assignment,unused-ignore]
18
42
 
19
- def encode_json(data: Any) -> str:
20
- return _encode_json(data).decode("utf-8") # type: ignore[no-any-return]
43
+ def encode_json(data: Any) -> str: # pragma: no cover
44
+ return _encode_json(
45
+ data,
46
+ default=_type_to_string,
47
+ option=OPT_SERIALIZE_NUMPY | OPT_NAIVE_UTC | OPT_SERIALIZE_UUID,
48
+ ).decode("utf-8")
21
49
 
22
50
  except ImportError:
23
51
  from json import dumps as encode_json # type: ignore[assignment]
24
52
  from json import loads as decode_json # type: ignore[assignment]
53
+
54
+ __all__ = (
55
+ "convert_date_to_iso",
56
+ "convert_datetime_to_gmt_iso",
57
+ "decode_json",
58
+ "encode_json",
59
+ )
60
+
61
+
62
+ def convert_datetime_to_gmt_iso(dt: datetime.datetime) -> str: # pragma: no cover
63
+ """Handle datetime serialization for nested timestamps."""
64
+ if not dt.tzinfo:
65
+ dt = dt.replace(tzinfo=datetime.timezone.utc)
66
+ return dt.isoformat().replace("+00:00", "Z")
67
+
68
+
69
+ def convert_date_to_iso(dt: datetime.date) -> str: # pragma: no cover
70
+ """Handle datetime serialization for nested timestamps."""
71
+ return dt.isoformat()
sqlspec/_typing.py CHANGED
@@ -3,8 +3,6 @@
3
3
  This is used to ensure compatibility when one or more of the libraries are installed.
4
4
  """
5
5
 
6
- from __future__ import annotations
7
-
8
6
  from enum import Enum
9
7
  from typing import (
10
8
  Any,
@@ -30,10 +28,15 @@ T = TypeVar("T")
30
28
  T_co = TypeVar("T_co", covariant=True)
31
29
 
32
30
  try:
33
- from pydantic import BaseModel, FailFast, TypeAdapter
31
+ from pydantic import (
32
+ BaseModel,
33
+ FailFast, # pyright: ignore[reportGeneralTypeIssues,reportAssignmentType]
34
+ TypeAdapter,
35
+ )
34
36
 
35
37
  PYDANTIC_INSTALLED = True
36
38
  except ImportError:
39
+ from dataclasses import dataclass
37
40
 
38
41
  @runtime_checkable
39
42
  class BaseModel(Protocol): # type: ignore[no-redef]
@@ -41,10 +44,42 @@ except ImportError:
41
44
 
42
45
  model_fields: ClassVar[dict[str, Any]]
43
46
 
44
- def model_dump(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
47
+ def model_dump(
48
+ self,
49
+ /,
50
+ *,
51
+ include: "Optional[Any]" = None,
52
+ exclude: "Optional[Any]" = None,
53
+ context: "Optional[Any]" = None,
54
+ by_alias: bool = False,
55
+ exclude_unset: bool = False,
56
+ exclude_defaults: bool = False,
57
+ exclude_none: bool = False,
58
+ round_trip: bool = False,
59
+ warnings: "Union[bool, Literal['none', 'warn', 'error']]" = True,
60
+ serialize_as_any: bool = False,
61
+ ) -> "dict[str, Any]":
45
62
  """Placeholder"""
46
63
  return {}
47
64
 
65
+ def model_dump_json(
66
+ self,
67
+ /,
68
+ *,
69
+ include: "Optional[Any]" = None,
70
+ exclude: "Optional[Any]" = None,
71
+ context: "Optional[Any]" = None,
72
+ by_alias: bool = False,
73
+ exclude_unset: bool = False,
74
+ exclude_defaults: bool = False,
75
+ exclude_none: bool = False,
76
+ round_trip: bool = False,
77
+ warnings: "Union[bool, Literal['none', 'warn', 'error']]" = True,
78
+ serialize_as_any: bool = False,
79
+ ) -> str:
80
+ """Placeholder"""
81
+ return ""
82
+
48
83
  @runtime_checkable
49
84
  class TypeAdapter(Protocol[T_co]): # type: ignore[no-redef]
50
85
  """Placeholder Implementation"""
@@ -53,9 +88,9 @@ except ImportError:
53
88
  self,
54
89
  type: Any, # noqa: A002
55
90
  *,
56
- config: Any | None = None,
91
+ config: "Optional[Any]" = None,
57
92
  _parent_depth: int = 2,
58
- module: str | None = None,
93
+ module: "Optional[str]" = None,
59
94
  ) -> None:
60
95
  """Init"""
61
96
 
@@ -64,19 +99,19 @@ except ImportError:
64
99
  object: Any, # noqa: A002
65
100
  /,
66
101
  *,
67
- strict: bool | None = None,
68
- from_attributes: bool | None = None,
69
- context: dict[str, Any] | None = None,
70
- ) -> T_co:
102
+ strict: "Optional[bool]" = None,
103
+ from_attributes: "Optional[bool]" = None,
104
+ context: "Optional[dict[str, Any]]" = None,
105
+ experimental_allow_partial: "Union[bool, Literal['off', 'on', 'trailing-strings']]" = False,
106
+ ) -> "T_co":
71
107
  """Stub"""
72
108
  return cast("T_co", object)
73
109
 
74
- @runtime_checkable
75
- class FailFast(Protocol): # type: ignore[no-redef]
110
+ @dataclass
111
+ class FailFast: # type: ignore[no-redef]
76
112
  """Placeholder Implementation for FailFast"""
77
113
 
78
- def __init__(self, *args: Any, **kwargs: Any) -> None:
79
- """Init"""
114
+ fail_fast: bool = True
80
115
 
81
116
  PYDANTIC_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
82
117
 
@@ -84,22 +119,36 @@ try:
84
119
  from msgspec import (
85
120
  UNSET,
86
121
  Struct,
87
- UnsetType, # pyright: ignore[reportAssignmentType]
122
+ UnsetType, # pyright: ignore[reportAssignmentType,reportGeneralTypeIssues]
88
123
  convert,
89
124
  )
90
125
 
91
126
  MSGSPEC_INSTALLED: bool = True
92
127
  except ImportError:
93
128
  import enum
129
+ from collections.abc import Iterable
130
+ from typing import TYPE_CHECKING, Callable, Optional, Union
131
+
132
+ if TYPE_CHECKING:
133
+ from collections.abc import Iterable
94
134
 
95
135
  @dataclass_transform()
96
136
  @runtime_checkable
97
137
  class Struct(Protocol): # type: ignore[no-redef]
98
138
  """Placeholder Implementation"""
99
139
 
100
- __struct_fields__: ClassVar[tuple[str, ...]]
101
-
102
- def convert(*args: Any, **kwargs: Any) -> Any: # type: ignore[no-redef]
140
+ __struct_fields__: "ClassVar[tuple[str, ...]]"
141
+
142
+ def convert( # type: ignore[no-redef]
143
+ obj: Any,
144
+ type: "Union[Any, type[T]]", # noqa: A002
145
+ *,
146
+ strict: bool = True,
147
+ from_attributes: bool = False,
148
+ dec_hook: "Optional[Callable[[type, Any], Any]]" = None,
149
+ builtin_types: "Union[Iterable[type], None]" = None,
150
+ str_keys: bool = False,
151
+ ) -> "Union[T, Any]":
103
152
  """Placeholder implementation"""
104
153
  return {}
105
154
 
@@ -124,11 +173,11 @@ except ImportError:
124
173
  def __init__(self, backend: Any, data_as_builtins: Any) -> None:
125
174
  """Placeholder init"""
126
175
 
127
- def create_instance(self, **kwargs: Any) -> T:
176
+ def create_instance(self, **kwargs: Any) -> "T":
128
177
  """Placeholder implementation"""
129
178
  return cast("T", kwargs)
130
179
 
131
- def update_instance(self, instance: T, **kwargs: Any) -> T:
180
+ def update_instance(self, instance: "T", **kwargs: Any) -> "T":
132
181
  """Placeholder implementation"""
133
182
  return cast("T", kwargs)
134
183
 
@@ -1,8 +1,6 @@
1
- from __future__ import annotations
2
-
3
1
  from contextlib import contextmanager
4
2
  from dataclasses import dataclass
5
- from typing import TYPE_CHECKING
3
+ from typing import TYPE_CHECKING, Any, Optional, Union
6
4
 
7
5
  from sqlspec.base import NoPoolSyncConfig
8
6
  from sqlspec.typing import Empty, EmptyType
@@ -24,18 +22,15 @@ class AdbcDatabaseConfig(NoPoolSyncConfig["Connection"]):
24
22
  ADBC Driver Manager.([1](https://arrow.apache.org/adbc/current/python/api/adbc_driver_manager.html))
25
23
  """
26
24
 
27
- __supports_connection_pooling = False
28
- __is_async = False
29
-
30
- uri: str | EmptyType = Empty
25
+ uri: "Union[str, EmptyType]" = Empty
31
26
  """Database URI"""
32
- driver_name: str | EmptyType = Empty
27
+ driver_name: "Union[str, EmptyType]" = Empty
33
28
  """Name of the ADBC driver to use"""
34
- db_kwargs: dict[str, Any] | None = None
29
+ db_kwargs: "Optional[dict[str, Any]]" = None
35
30
  """Additional database-specific connection parameters"""
36
31
 
37
32
  @property
38
- def connection_params(self) -> dict[str, Any]:
33
+ def connection_params(self) -> "dict[str, Any]":
39
34
  """Return the connection parameters as a dict."""
40
35
  return {
41
36
  k: v
@@ -44,7 +39,7 @@ class AdbcDatabaseConfig(NoPoolSyncConfig["Connection"]):
44
39
  }
45
40
 
46
41
  @contextmanager
47
- def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[Connection, None, None]:
42
+ def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[Connection, None, None]":
48
43
  """Create and provide a database connection."""
49
44
  from adbc_driver_manager.dbapi import connect
50
45
 
@@ -1,3 +1,3 @@
1
- from .config import AiosqliteConfig
1
+ from sqlspec.adapters.aiosqlite.config import AiosqliteConfig
2
2
 
3
3
  __all__ = ("AiosqliteConfig",)
@@ -1,8 +1,6 @@
1
- from __future__ import annotations
2
-
3
1
  from contextlib import asynccontextmanager
4
2
  from dataclasses import dataclass, field
5
- from typing import TYPE_CHECKING, Any
3
+ from typing import TYPE_CHECKING, Any, Optional, Union
6
4
 
7
5
  from sqlspec.base import NoPoolSyncConfig
8
6
  from sqlspec.exceptions import ImproperConfigurationError
@@ -28,25 +26,25 @@ class AiosqliteConfig(NoPoolSyncConfig["Connection"]):
28
26
  For details see: https://github.com/omnilib/aiosqlite/blob/main/aiosqlite/__init__.pyi
29
27
  """
30
28
 
31
- database: str = field(default=":memory:")
29
+ database: "Union[str, EmptyType]" = field(default=":memory:")
32
30
  """The path to the database file to be opened. Pass ":memory:" to open a connection to a database that resides in RAM instead of on disk."""
33
- timeout: float | EmptyType = field(default=Empty)
31
+ timeout: "Union[float, EmptyType]" = field(default=Empty)
34
32
  """How many seconds the connection should wait before raising an OperationalError when a table is locked. If another thread or process has acquired a shared lock, a wait for the specified timeout occurs."""
35
- detect_types: int | EmptyType = field(default=Empty)
33
+ detect_types: "Union[int, EmptyType]" = field(default=Empty)
36
34
  """Control whether and how data types are detected. It can be 0 (default) or a combination of PARSE_DECLTYPES and PARSE_COLNAMES."""
37
- isolation_level: Literal["DEFERRED", "IMMEDIATE", "EXCLUSIVE"] | None | EmptyType = field(default=Empty)
35
+ isolation_level: "Optional[Union[Literal['DEFERRED', 'IMMEDIATE', 'EXCLUSIVE'], EmptyType]]" = field(default=Empty)
38
36
  """The isolation_level of the connection. This can be None for autocommit mode or one of "DEFERRED", "IMMEDIATE" or "EXCLUSIVE"."""
39
- check_same_thread: bool | EmptyType = field(default=Empty)
37
+ check_same_thread: "Union[bool, EmptyType]" = field(default=Empty)
40
38
  """If True (default), ProgrammingError is raised if the database connection is used by a thread other than the one that created it. If False, the connection may be shared across multiple threads."""
41
- factory: type[SQLite3Connection] | EmptyType = field(default=Empty)
39
+ factory: "Union[type[SQLite3Connection], EmptyType]" = field(default=Empty)
42
40
  """A custom Connection class factory. If given, must be a callable that returns a Connection instance."""
43
- cached_statements: int | EmptyType = field(default=Empty)
41
+ cached_statements: "Union[int, EmptyType]" = field(default=Empty)
44
42
  """The number of statements that SQLite will cache for this connection. The default is 128."""
45
- uri: bool | EmptyType = field(default=Empty)
43
+ uri: "Union[bool, EmptyType]" = field(default=Empty)
46
44
  """If set to True, database is interpreted as a URI with supported options."""
47
45
 
48
46
  @property
49
- def connection_config_dict(self) -> dict[str, Any]:
47
+ def connection_config_dict(self) -> "dict[str, Any]":
50
48
  """Return the connection configuration as a dict.
51
49
 
52
50
  Returns:
@@ -54,7 +52,7 @@ class AiosqliteConfig(NoPoolSyncConfig["Connection"]):
54
52
  """
55
53
  return dataclass_to_dict(self, exclude_empty=True, convert_nested=False)
56
54
 
57
- async def create_connection(self) -> Connection:
55
+ async def create_connection(self) -> "Connection":
58
56
  """Create and return a new database connection.
59
57
 
60
58
  Returns:
@@ -72,7 +70,7 @@ class AiosqliteConfig(NoPoolSyncConfig["Connection"]):
72
70
  raise ImproperConfigurationError(msg) from e
73
71
 
74
72
  @asynccontextmanager
75
- async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Connection, None]:
73
+ async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[Connection, None]":
76
74
  """Create and provide a database connection.
77
75
 
78
76
  Yields:
@@ -1,3 +1,3 @@
1
- from .config import AsyncMyConfig, AsyncmyPoolConfig
1
+ from sqlspec.adapters.asyncmy.config import AsyncMyConfig, AsyncmyPoolConfig
2
2
 
3
3
  __all__ = ("AsyncMyConfig", "AsyncmyPoolConfig")
@@ -1,11 +1,9 @@
1
- from __future__ import annotations
2
-
3
1
  from contextlib import asynccontextmanager
4
2
  from dataclasses import dataclass
5
- from typing import TYPE_CHECKING, TypeVar
3
+ from typing import TYPE_CHECKING, Optional, TypeVar, Union
6
4
 
7
- from asyncmy.connection import Connection
8
- from asyncmy.pool import Pool
5
+ from asyncmy.connection import Connection # pyright: ignore[reportUnknownVariableType]
6
+ from asyncmy.pool import Pool # pyright: ignore[reportUnknownVariableType]
9
7
 
10
8
  from sqlspec.base import AsyncDatabaseConfig, GenericPoolConfig
11
9
  from sqlspec.exceptions import ImproperConfigurationError
@@ -15,7 +13,7 @@ if TYPE_CHECKING:
15
13
  from collections.abc import AsyncGenerator
16
14
  from typing import Any
17
15
 
18
- from asyncmy.cursors import Cursor, DictCursor
16
+ from asyncmy.cursors import Cursor, DictCursor # pyright: ignore[reportUnknownVariableType]
19
17
 
20
18
  __all__ = (
21
19
  "AsyncMyConfig",
@@ -35,68 +33,68 @@ class AsyncmyPoolConfig(GenericPoolConfig):
35
33
  For details see: https://github.com/long2ice/asyncmy
36
34
  """
37
35
 
38
- host: str | EmptyType = Empty
36
+ host: "Union[str, EmptyType]" = Empty
39
37
  """Host where the database server is located."""
40
38
 
41
- user: str | EmptyType = Empty
39
+ user: "Union[str, EmptyType]" = Empty
42
40
  """The username used to authenticate with the database."""
43
41
 
44
- password: str | EmptyType = Empty
42
+ password: "Union[str, EmptyType]" = Empty
45
43
  """The password used to authenticate with the database."""
46
44
 
47
- database: str | EmptyType = Empty
45
+ database: "Union[str, EmptyType]" = Empty
48
46
  """The database name to use."""
49
47
 
50
- port: int | EmptyType = Empty
48
+ port: "Union[int, EmptyType]" = Empty
51
49
  """The TCP/IP port of the MySQL server. Must be an integer."""
52
50
 
53
- unix_socket: str | EmptyType = Empty
51
+ unix_socket: "Union[str, EmptyType]" = Empty
54
52
  """The location of the Unix socket file."""
55
53
 
56
- charset: str | EmptyType = Empty
54
+ charset: "Union[str, EmptyType]" = Empty
57
55
  """The character set to use for the connection."""
58
56
 
59
- connect_timeout: float | EmptyType = Empty
57
+ connect_timeout: "Union[float, EmptyType]" = Empty
60
58
  """Timeout before throwing an error when connecting."""
61
59
 
62
- read_default_file: str | EmptyType = Empty
60
+ read_default_file: "Union[str, EmptyType]" = Empty
63
61
  """MySQL configuration file to read."""
64
62
 
65
- read_default_group: str | EmptyType = Empty
63
+ read_default_group: "Union[str, EmptyType]" = Empty
66
64
  """Group to read from the configuration file."""
67
65
 
68
- autocommit: bool | EmptyType = Empty
66
+ autocommit: "Union[bool, EmptyType]" = Empty
69
67
  """If True, autocommit mode will be enabled."""
70
68
 
71
- local_infile: bool | EmptyType = Empty
69
+ local_infile: "Union[bool, EmptyType]" = Empty
72
70
  """If True, enables LOAD LOCAL INFILE."""
73
71
 
74
- ssl: dict[str, Any] | bool | EmptyType = Empty
72
+ ssl: "Union[dict[str, Any], bool, EmptyType]" = Empty
75
73
  """If present, a dictionary of SSL connection parameters, or just True."""
76
74
 
77
- sql_mode: str | EmptyType = Empty
75
+ sql_mode: "Union[str, EmptyType]" = Empty
78
76
  """Default SQL_MODE to use."""
79
77
 
80
- init_command: str | EmptyType = Empty
78
+ init_command: "Union[str, EmptyType]" = Empty
81
79
  """Initial SQL statement to execute once connected."""
82
80
 
83
- cursor_class: type[Cursor] | type[DictCursor] | EmptyType = Empty
81
+ cursor_class: "Union[type[Union[Cursor, DictCursor]], EmptyType]" = Empty
84
82
  """Custom cursor class to use."""
85
83
 
86
- minsize: int | EmptyType = Empty
84
+ minsize: "Union[int, EmptyType]" = Empty
87
85
  """Minimum number of connections to keep in the pool."""
88
86
 
89
- maxsize: int | EmptyType = Empty
87
+ maxsize: "Union[int, EmptyType]" = Empty
90
88
  """Maximum number of connections allowed in the pool."""
91
89
 
92
- echo: bool | EmptyType = Empty
90
+ echo: "Union[bool, EmptyType]" = Empty
93
91
  """If True, logging will be enabled for all SQL statements."""
94
92
 
95
- pool_recycle: int | EmptyType = Empty
93
+ pool_recycle: "Union[int, EmptyType]" = Empty
96
94
  """Number of seconds after which a connection is recycled."""
97
95
 
98
96
  @property
99
- def pool_config_dict(self) -> dict[str, Any]:
97
+ def pool_config_dict(self) -> "dict[str, Any]":
100
98
  """Return the pool configuration as a dict.
101
99
 
102
100
  Returns:
@@ -112,28 +110,31 @@ class AsyncMyConfig(AsyncDatabaseConfig[Connection, Pool]):
112
110
  __is_async__ = True
113
111
  __supports_connection_pooling__ = True
114
112
 
115
- pool_config: AsyncmyPoolConfig | None = None
113
+ pool_config: "Optional[AsyncmyPoolConfig]" = None
116
114
  """Asyncmy Pool configuration"""
117
115
 
118
- pool_instance: Pool | None = None
116
+ pool_instance: "Optional[Pool]" = None # pyright: ignore[reportUnknownVariableType]
119
117
  """Optional pool to use.
120
118
 
121
119
  If set, the plugin will use the provided pool rather than instantiate one.
122
120
  """
123
121
 
124
122
  @property
125
- def pool_config_dict(self) -> dict[str, Any]:
123
+ def pool_config_dict(self) -> "dict[str, Any]":
126
124
  """Return the pool configuration as a dict.
127
125
 
128
126
  Returns:
129
127
  A string keyed dict of config kwargs for the Asyncmy create_pool function.
128
+
129
+ Raises:
130
+ ImproperConfigurationError: If the pool configuration is not provided.
130
131
  """
131
132
  if self.pool_config:
132
133
  return dataclass_to_dict(self.pool_config, exclude_empty=True, convert_nested=False)
133
134
  msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
134
135
  raise ImproperConfigurationError(msg)
135
136
 
136
- async def create_pool(self) -> Pool:
137
+ async def create_pool(self) -> "Pool": # pyright: ignore[reportUnknownParameterType]
137
138
  """Return a pool. If none exists yet, create one.
138
139
 
139
140
  Returns:
@@ -142,40 +143,39 @@ class AsyncMyConfig(AsyncDatabaseConfig[Connection, Pool]):
142
143
  Raises:
143
144
  ImproperConfigurationError: If the pool could not be created.
144
145
  """
145
- if self.pool_instance is not None:
146
- return self.pool_instance
146
+ if self.pool_instance is not None: # pyright: ignore[reportUnknownMemberType]
147
+ return self.pool_instance # pyright: ignore[reportUnknownVariableType,reportUnknownMemberType]
147
148
 
148
149
  if self.pool_config is None:
149
150
  msg = "One of 'pool_config' or 'pool_instance' must be provided."
150
151
  raise ImproperConfigurationError(msg)
151
152
 
152
153
  try:
153
- import asyncmy
154
+ import asyncmy # pyright: ignore[reportMissingTypeStubs]
154
155
 
155
- self.pool_instance = await asyncmy.create_pool(**self.pool_config_dict)
156
- return self.pool_instance
156
+ self.pool_instance = await asyncmy.create_pool(**self.pool_config_dict) # pyright: ignore[reportUnknownMemberType]
157
157
  except Exception as e:
158
158
  msg = f"Could not configure the Asyncmy pool. Error: {e!s}"
159
159
  raise ImproperConfigurationError(msg) from e
160
+ else:
161
+ return self.pool_instance # pyright: ignore[reportUnknownVariableType,reportUnknownMemberType]
160
162
 
161
- async def provide_pool(self, *args: Any, **kwargs: Any) -> Pool:
163
+ async def provide_pool(self, *args: "Any", **kwargs: "Any") -> "Pool": # pyright: ignore[reportUnknownParameterType]
162
164
  """Create a pool instance.
163
165
 
164
166
  Returns:
165
167
  A Pool instance.
166
168
  """
167
- return await self.create_pool()
169
+ return await self.create_pool() # pyright: ignore[reportUnknownMemberType,reportUnknownVariableType]
168
170
 
169
171
  @asynccontextmanager
170
- async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Connection, None]:
172
+ async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[Connection, None]": # pyright: ignore[reportUnknownParameterType]
171
173
  """Create and provide a database connection.
172
174
 
173
175
  Yields:
174
176
  An Asyncmy connection instance.
175
177
 
176
- Raises:
177
- ImproperConfigurationError: If the connection could not be established.
178
178
  """
179
- pool = await self.provide_pool(*args, **kwargs)
180
- async with pool.acquire() as connection:
181
- yield connection
179
+ pool = await self.provide_pool(*args, **kwargs) # pyright: ignore[reportUnknownVariableType,reportUnknownMemberType]
180
+ async with pool.acquire() as connection: # pyright: ignore[reportUnknownMemberType,reportUnknownVariableType]
181
+ yield connection # pyright: ignore[reportUnknownMemberType]