dinao 2.2.0.dev174__tar.gz → 2.2.0.dev178__tar.gz

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.
Files changed (34) hide show
  1. {dinao-2.2.0.dev174/dinao.egg-info → dinao-2.2.0.dev178}/PKG-INFO +1 -1
  2. dinao-2.2.0.dev178/dinao/__version__.py +2 -0
  3. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/__init__.py +3 -1
  4. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/asyncpg.py +1 -1
  5. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/async_.py +14 -1
  6. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/base.py +5 -0
  7. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/sync.py +14 -1
  8. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/errors.py +6 -0
  9. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178/dinao.egg-info}/PKG-INFO +1 -1
  10. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/pyproject.toml +3 -0
  11. dinao-2.2.0.dev174/dinao/__version__.py +0 -2
  12. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/AUTHORS +0 -0
  13. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/LICENSE +0 -0
  14. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/README.md +0 -0
  15. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/__init__.py +0 -0
  16. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/base.py +0 -0
  17. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/errors.py +0 -0
  18. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/mariadb.py +0 -0
  19. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/mysql.py +0 -0
  20. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/__init__.py +0 -0
  21. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/base.py +0 -0
  22. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/psycopg2.py +0 -0
  23. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/postgres/psycopg3.py +0 -0
  24. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/backend/sqlite.py +0 -0
  25. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/__init__.py +0 -0
  26. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/binders/__init__.py +0 -0
  27. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/mappers.py +0 -0
  28. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/binding/templating.py +0 -0
  29. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao/mung.py +0 -0
  30. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/SOURCES.txt +0 -0
  31. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/dependency_links.txt +0 -0
  32. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/requires.txt +0 -0
  33. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/dinao.egg-info/top_level.txt +0 -0
  34. {dinao-2.2.0.dev174 → dinao-2.2.0.dev178}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dinao
3
- Version: 2.2.0.dev174
3
+ Version: 2.2.0.dev178
4
4
  Summary: A simple database API
5
5
  Author-email: Jim Carreer <jim.carreer+dinao@gmail.com>
6
6
  License-Expression: ISC
@@ -0,0 +1,2 @@
1
+ # noqa: D100
2
+ __version__ = "2.2.0.dev178"
@@ -94,9 +94,11 @@ def create_connection_pool(db_url: str) -> ConnectionPoolBase:
94
94
  if mode == "async":
95
95
  return AsyncConnectionPoolPSQLPsycopg3(db_url)
96
96
  return ConnectionPoolPSQLPsycopg3(db_url)
97
- if backend == "sqlite3" and engine is None:
97
+ if backend == "sqlite3":
98
98
  if mode == "async":
99
99
  raise UnsupportedBackendError("The sqlite3 backend does not support async mode")
100
+ if engine is not None:
101
+ raise UnsupportedBackendError(f"The backend+engine '{scheme}' is not supported")
100
102
  return ConnectionPoolSQLite3(db_url)
101
103
  if backend == "mariadb" and engine == "mariadbconnector":
102
104
  if mode == "async":
@@ -214,7 +214,7 @@ class AsyncConnectionPoolPSQLAsyncpg(AsyncConnectionPoolPSQL):
214
214
  if self._pool is not None:
215
215
  return
216
216
  async with self._pool_lock:
217
- if self._pool is not None:
217
+ if self._pool is not None: # pragma: no cover
218
218
  return
219
219
  import asyncpg
220
220
 
@@ -14,7 +14,7 @@ from dinao.binding.binders.base import (
14
14
  BoundTransactionBase,
15
15
  FunctionBinderBase,
16
16
  )
17
- from dinao.binding.errors import CannotInferMappingError, NoPoolSetError, TooManyRowsError
17
+ from dinao.binding.errors import CannotInferMappingError, IncompatibleBindingError, NoPoolSetError, TooManyRowsError
18
18
  from dinao.binding.mappers import ASYNC_GENERATOR_GENERICS, GENERATOR_GENERICS
19
19
 
20
20
 
@@ -26,6 +26,19 @@ class AsyncFunctionBinder(FunctionBinderBase):
26
26
  super().__init__()
27
27
  self._context_store = contextvars.ContextVar("active_cnx", default=None)
28
28
 
29
+ def _validate_function(self, func):
30
+ """Validate that the function is a coroutine.
31
+
32
+ :raises IncompatibleBindingError
33
+ """
34
+ if not inspect.iscoroutinefunction(func):
35
+ error = (
36
+ f"AsyncFunctionBinder cannot bind sync function"
37
+ f" '{func.__name__}'; use FunctionBinder"
38
+ f" for sync functions"
39
+ )
40
+ self._suppressed_raise(IncompatibleBindingError(error))
41
+
29
42
  def _validate_pool(self, pool):
30
43
  """Validate that the pool is an async pool.
31
44
 
@@ -69,6 +69,10 @@ class FunctionBinderBase(ABC):
69
69
  """Validate a pool before assignment. Override in subclasses for type checking."""
70
70
  pass
71
71
 
72
+ def _validate_function(self, func):
73
+ """Validate a function before binding. Override in subclasses for type checking."""
74
+ pass # pragma: no cover
75
+
72
76
  @property
73
77
  def pool(self) -> ConnectionPoolBase:
74
78
  """Get the connection pool used by this binder."""
@@ -112,6 +116,7 @@ class BoundFunction(ABC):
112
116
  """Abstract class for common behaviors between bound functions."""
113
117
 
114
118
  def __init__(self, binder: FunctionBinderBase, func: callable): # noqa: D107
119
+ binder._validate_function(func)
115
120
  self._binder = binder
116
121
  self._func = func
117
122
  self._sig = inspect.signature(func)
@@ -14,7 +14,7 @@ from dinao.binding.binders.base import (
14
14
  BoundTransactionBase,
15
15
  FunctionBinderBase,
16
16
  )
17
- from dinao.binding.errors import NoPoolSetError, TooManyRowsError
17
+ from dinao.binding.errors import IncompatibleBindingError, NoPoolSetError, TooManyRowsError
18
18
  from dinao.binding.mappers import GENERATOR_GENERICS
19
19
 
20
20
 
@@ -26,6 +26,19 @@ class FunctionBinder(FunctionBinderBase):
26
26
  super().__init__()
27
27
  self._context_store = threading.local()
28
28
 
29
+ def _validate_function(self, func):
30
+ """Validate that the function is not a coroutine.
31
+
32
+ :raises IncompatibleBindingError
33
+ """
34
+ if inspect.iscoroutinefunction(func):
35
+ error = (
36
+ f"FunctionBinder cannot bind async function"
37
+ f" '{func.__name__}'; use AsyncFunctionBinder"
38
+ f" for async functions"
39
+ )
40
+ self._suppressed_raise(IncompatibleBindingError(error))
41
+
29
42
  def execute(self, sql: str) -> callable:
30
43
  """Binds a given function to a given SQL template.
31
44
 
@@ -33,6 +33,12 @@ class TemplateError(BindingError):
33
33
  pass
34
34
 
35
35
 
36
+ class IncompatibleBindingError(BindingError):
37
+ """Raised when a function's coroutine type is incompatible with its binder."""
38
+
39
+ pass
40
+
41
+
36
42
  class FunctionAlreadyBoundError(BindingError):
37
43
  """Raised when a function is bound more than once to a query, execution, or transaction."""
38
44
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dinao
3
- Version: 2.2.0.dev174
3
+ Version: 2.2.0.dev178
4
4
  Summary: A simple database API
5
5
  Author-email: Jim Carreer <jim.carreer+dinao@gmail.com>
6
6
  License-Expression: ISC
@@ -87,3 +87,6 @@ branch = true
87
87
  exclude_lines = [
88
88
  "pragma: no cover",
89
89
  ]
90
+ partial_branches = [
91
+ "pragma: no branch",
92
+ ]
@@ -1,2 +0,0 @@
1
- # noqa: D100
2
- __version__ = "2.2.0.dev174"
File without changes
File without changes
File without changes
File without changes
File without changes