Skip to content

Commit a70bb00

Browse files
Fix typing declaration for AsyncConnectionPool.acquire().
1 parent 0e9d935 commit a70bb00

File tree

3 files changed

+216
-113
lines changed

3 files changed

+216
-113
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Thin Mode Changes
3838
:ref:`asyncio <asyncio>`
3939
(`issue 285 <https://github.com/oracle/python-oracledb/issues/285>`__).
4040
#) Fixed type declaration for the ``connectiontype`` parameter to
41-
:meth:`oracledb.create_pool_async()`.
41+
:meth:`oracledb.create_pool_async()` and the return value of
42+
:meth:`AsyncConnectionPool.acquire()`.
4243

4344

4445
Thick Mode Changes

src/oracledb/pool.py

Lines changed: 107 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -105,59 +105,6 @@ def _verify_open(self) -> None:
105105
if self._impl is None:
106106
errors._raise_err(errors.ERR_POOL_NOT_OPEN)
107107

108-
def acquire(
109-
self,
110-
user: str = None,
111-
password: str = None,
112-
cclass: str = None,
113-
purity: int = oracledb.PURITY_DEFAULT,
114-
tag: str = None,
115-
matchanytag: bool = False,
116-
shardingkey: list = None,
117-
supershardingkey: list = None,
118-
) -> "connection_module.Connection":
119-
"""
120-
Acquire a connection from the pool and return it.
121-
122-
If the pool is homogeneous, the user and password parameters cannot be
123-
specified. If they are, an exception will be raised.
124-
125-
The cclass parameter, if specified, should be a string corresponding to
126-
the connection class for database resident connection pooling (DRCP).
127-
128-
The purity parameter is expected to be one of PURITY_DEFAULT,
129-
PURITY_NEW, or PURITY_SELF.
130-
131-
The tag parameter, if specified, is expected to be a string with
132-
name=value pairs like “k1=v1;k2=v2” and will limit the connections that
133-
can be returned from a pool unless the matchanytag parameter is
134-
set to True. In that case connections with the specified tag will be
135-
preferred over others, but if no such connections are available a
136-
connection with a different tag may be returned instead. In any case,
137-
untagged connections will always be returned if no connections with the
138-
specified tag are available. Connections are tagged when they are
139-
released back to the pool.
140-
141-
The shardingkey and supershardingkey parameters, if specified, are
142-
expected to be a sequence of values which will be used to identify the
143-
database shard to connect to. The key values can be strings, numbers,
144-
bytes or dates.
145-
"""
146-
self._verify_open()
147-
148-
return self._connection_method(
149-
conn_class=self._connection_type,
150-
user=user,
151-
password=password,
152-
cclass=cclass,
153-
purity=purity,
154-
tag=tag,
155-
matchanytag=matchanytag,
156-
shardingkey=shardingkey,
157-
supershardingkey=supershardingkey,
158-
pool=self,
159-
)
160-
161108
@property
162109
def busy(self) -> int:
163110
"""
@@ -414,7 +361,59 @@ def _set_connection_type(self, conn_class):
414361
) or issubclass(conn_class, connection_module.AsyncConnection):
415362
errors._raise_err(errors.ERR_INVALID_CONN_CLASS)
416363
self._connection_type = conn_class
417-
self._connection_method = oracledb.connect
364+
365+
def acquire(
366+
self,
367+
user: str = None,
368+
password: str = None,
369+
cclass: str = None,
370+
purity: int = oracledb.PURITY_DEFAULT,
371+
tag: str = None,
372+
matchanytag: bool = False,
373+
shardingkey: list = None,
374+
supershardingkey: list = None,
375+
) -> "connection_module.Connection":
376+
"""
377+
Acquire a connection from the pool and return it.
378+
379+
If the pool is homogeneous, the user and password parameters cannot be
380+
specified. If they are, an exception will be raised.
381+
382+
The cclass parameter, if specified, should be a string corresponding to
383+
the connection class for database resident connection pooling (DRCP).
384+
385+
The purity parameter is expected to be one of PURITY_DEFAULT,
386+
PURITY_NEW, or PURITY_SELF.
387+
388+
The tag parameter, if specified, is expected to be a string with
389+
name=value pairs like “k1=v1;k2=v2” and will limit the connections that
390+
can be returned from a pool unless the matchanytag parameter is
391+
set to True. In that case connections with the specified tag will be
392+
preferred over others, but if no such connections are available a
393+
connection with a different tag may be returned instead. In any case,
394+
untagged connections will always be returned if no connections with the
395+
specified tag are available. Connections are tagged when they are
396+
released back to the pool.
397+
398+
The shardingkey and supershardingkey parameters, if specified, are
399+
expected to be a sequence of values which will be used to identify the
400+
database shard to connect to. The key values can be strings, numbers,
401+
bytes or dates.
402+
"""
403+
self._verify_open()
404+
405+
return oracledb.connect(
406+
conn_class=self._connection_type,
407+
user=user,
408+
password=password,
409+
cclass=cclass,
410+
purity=purity,
411+
tag=tag,
412+
matchanytag=matchanytag,
413+
shardingkey=shardingkey,
414+
supershardingkey=supershardingkey,
415+
pool=self,
416+
)
418417

419418
def close(self, force: bool = False) -> None:
420419
"""
@@ -882,7 +881,59 @@ def _set_connection_type(self, conn_class):
882881
elif not issubclass(conn_class, connection_module.AsyncConnection):
883882
errors._raise_err(errors.ERR_INVALID_CONN_CLASS)
884883
self._connection_type = conn_class
885-
self._connection_method = oracledb.connect_async
884+
885+
def acquire(
886+
self,
887+
user: str = None,
888+
password: str = None,
889+
cclass: str = None,
890+
purity: int = oracledb.PURITY_DEFAULT,
891+
tag: str = None,
892+
matchanytag: bool = False,
893+
shardingkey: list = None,
894+
supershardingkey: list = None,
895+
) -> "connection_module.AsyncConnection":
896+
"""
897+
Acquire a connection from the pool and return it.
898+
899+
If the pool is homogeneous, the user and password parameters cannot be
900+
specified. If they are, an exception will be raised.
901+
902+
The cclass parameter, if specified, should be a string corresponding to
903+
the connection class for database resident connection pooling (DRCP).
904+
905+
The purity parameter is expected to be one of PURITY_DEFAULT,
906+
PURITY_NEW, or PURITY_SELF.
907+
908+
The tag parameter, if specified, is expected to be a string with
909+
name=value pairs like “k1=v1;k2=v2” and will limit the connections that
910+
can be returned from a pool unless the matchanytag parameter is
911+
set to True. In that case connections with the specified tag will be
912+
preferred over others, but if no such connections are available a
913+
connection with a different tag may be returned instead. In any case,
914+
untagged connections will always be returned if no connections with the
915+
specified tag are available. Connections are tagged when they are
916+
released back to the pool.
917+
918+
The shardingkey and supershardingkey parameters, if specified, are
919+
expected to be a sequence of values which will be used to identify the
920+
database shard to connect to. The key values can be strings, numbers,
921+
bytes or dates.
922+
"""
923+
self._verify_open()
924+
925+
return oracledb.connect_async(
926+
conn_class=self._connection_type,
927+
user=user,
928+
password=password,
929+
cclass=cclass,
930+
purity=purity,
931+
tag=tag,
932+
matchanytag=matchanytag,
933+
shardingkey=shardingkey,
934+
supershardingkey=supershardingkey,
935+
pool=self,
936+
)
886937

887938
async def close(self, force: bool = False) -> None:
888939
"""

utils/templates/pool.py

Lines changed: 107 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -103,59 +103,6 @@ def _verify_open(self) -> None:
103103
if self._impl is None:
104104
errors._raise_err(errors.ERR_POOL_NOT_OPEN)
105105

106-
def acquire(
107-
self,
108-
user: str = None,
109-
password: str = None,
110-
cclass: str = None,
111-
purity: int = oracledb.PURITY_DEFAULT,
112-
tag: str = None,
113-
matchanytag: bool = False,
114-
shardingkey: list = None,
115-
supershardingkey: list = None,
116-
) -> "connection_module.Connection":
117-
"""
118-
Acquire a connection from the pool and return it.
119-
120-
If the pool is homogeneous, the user and password parameters cannot be
121-
specified. If they are, an exception will be raised.
122-
123-
The cclass parameter, if specified, should be a string corresponding to
124-
the connection class for database resident connection pooling (DRCP).
125-
126-
The purity parameter is expected to be one of PURITY_DEFAULT,
127-
PURITY_NEW, or PURITY_SELF.
128-
129-
The tag parameter, if specified, is expected to be a string with
130-
name=value pairs like “k1=v1;k2=v2” and will limit the connections that
131-
can be returned from a pool unless the matchanytag parameter is
132-
set to True. In that case connections with the specified tag will be
133-
preferred over others, but if no such connections are available a
134-
connection with a different tag may be returned instead. In any case,
135-
untagged connections will always be returned if no connections with the
136-
specified tag are available. Connections are tagged when they are
137-
released back to the pool.
138-
139-
The shardingkey and supershardingkey parameters, if specified, are
140-
expected to be a sequence of values which will be used to identify the
141-
database shard to connect to. The key values can be strings, numbers,
142-
bytes or dates.
143-
"""
144-
self._verify_open()
145-
146-
return self._connection_method(
147-
conn_class=self._connection_type,
148-
user=user,
149-
password=password,
150-
cclass=cclass,
151-
purity=purity,
152-
tag=tag,
153-
matchanytag=matchanytag,
154-
shardingkey=shardingkey,
155-
supershardingkey=supershardingkey,
156-
pool=self,
157-
)
158-
159106
@property
160107
def busy(self) -> int:
161108
"""
@@ -412,7 +359,59 @@ def _set_connection_type(self, conn_class):
412359
) or issubclass(conn_class, connection_module.AsyncConnection):
413360
errors._raise_err(errors.ERR_INVALID_CONN_CLASS)
414361
self._connection_type = conn_class
415-
self._connection_method = oracledb.connect
362+
363+
def acquire(
364+
self,
365+
user: str = None,
366+
password: str = None,
367+
cclass: str = None,
368+
purity: int = oracledb.PURITY_DEFAULT,
369+
tag: str = None,
370+
matchanytag: bool = False,
371+
shardingkey: list = None,
372+
supershardingkey: list = None,
373+
) -> "connection_module.Connection":
374+
"""
375+
Acquire a connection from the pool and return it.
376+
377+
If the pool is homogeneous, the user and password parameters cannot be
378+
specified. If they are, an exception will be raised.
379+
380+
The cclass parameter, if specified, should be a string corresponding to
381+
the connection class for database resident connection pooling (DRCP).
382+
383+
The purity parameter is expected to be one of PURITY_DEFAULT,
384+
PURITY_NEW, or PURITY_SELF.
385+
386+
The tag parameter, if specified, is expected to be a string with
387+
name=value pairs like “k1=v1;k2=v2” and will limit the connections that
388+
can be returned from a pool unless the matchanytag parameter is
389+
set to True. In that case connections with the specified tag will be
390+
preferred over others, but if no such connections are available a
391+
connection with a different tag may be returned instead. In any case,
392+
untagged connections will always be returned if no connections with the
393+
specified tag are available. Connections are tagged when they are
394+
released back to the pool.
395+
396+
The shardingkey and supershardingkey parameters, if specified, are
397+
expected to be a sequence of values which will be used to identify the
398+
database shard to connect to. The key values can be strings, numbers,
399+
bytes or dates.
400+
"""
401+
self._verify_open()
402+
403+
return oracledb.connect(
404+
conn_class=self._connection_type,
405+
user=user,
406+
password=password,
407+
cclass=cclass,
408+
purity=purity,
409+
tag=tag,
410+
matchanytag=matchanytag,
411+
shardingkey=shardingkey,
412+
supershardingkey=supershardingkey,
413+
pool=self,
414+
)
416415

417416
def close(self, force: bool = False) -> None:
418417
"""
@@ -626,7 +625,59 @@ def _set_connection_type(self, conn_class):
626625
elif not issubclass(conn_class, connection_module.AsyncConnection):
627626
errors._raise_err(errors.ERR_INVALID_CONN_CLASS)
628627
self._connection_type = conn_class
629-
self._connection_method = oracledb.connect_async
628+
629+
def acquire(
630+
self,
631+
user: str = None,
632+
password: str = None,
633+
cclass: str = None,
634+
purity: int = oracledb.PURITY_DEFAULT,
635+
tag: str = None,
636+
matchanytag: bool = False,
637+
shardingkey: list = None,
638+
supershardingkey: list = None,
639+
) -> "connection_module.AsyncConnection":
640+
"""
641+
Acquire a connection from the pool and return it.
642+
643+
If the pool is homogeneous, the user and password parameters cannot be
644+
specified. If they are, an exception will be raised.
645+
646+
The cclass parameter, if specified, should be a string corresponding to
647+
the connection class for database resident connection pooling (DRCP).
648+
649+
The purity parameter is expected to be one of PURITY_DEFAULT,
650+
PURITY_NEW, or PURITY_SELF.
651+
652+
The tag parameter, if specified, is expected to be a string with
653+
name=value pairs like “k1=v1;k2=v2” and will limit the connections that
654+
can be returned from a pool unless the matchanytag parameter is
655+
set to True. In that case connections with the specified tag will be
656+
preferred over others, but if no such connections are available a
657+
connection with a different tag may be returned instead. In any case,
658+
untagged connections will always be returned if no connections with the
659+
specified tag are available. Connections are tagged when they are
660+
released back to the pool.
661+
662+
The shardingkey and supershardingkey parameters, if specified, are
663+
expected to be a sequence of values which will be used to identify the
664+
database shard to connect to. The key values can be strings, numbers,
665+
bytes or dates.
666+
"""
667+
self._verify_open()
668+
669+
return oracledb.connect_async(
670+
conn_class=self._connection_type,
671+
user=user,
672+
password=password,
673+
cclass=cclass,
674+
purity=purity,
675+
tag=tag,
676+
matchanytag=matchanytag,
677+
shardingkey=shardingkey,
678+
supershardingkey=supershardingkey,
679+
pool=self,
680+
)
630681

631682
async def close(self, force: bool = False) -> None:
632683
"""

0 commit comments

Comments
 (0)