Skip to content

Commit adc0a0b

Browse files
Fixed type delaration for the "connectiontype" parameter to
oracledb.create_pool_async().
1 parent 3ab90d9 commit adc0a0b

File tree

6 files changed

+67
-13
lines changed

6 files changed

+67
-13
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Thin Mode Changes
3535
#) Fixed bug when connecting to a database using listener redirects when using
3636
:ref:`asyncio <asyncio>`
3737
(`issue 285 <https://github.com/oracle/python-oracledb/issues/285>`__).
38+
#) Fixed type declaration for the `connectiontype` parameter to
39+
:meth:`oracledb.create_pool_async()`.
3840

3941

4042
Thick Mode Changes

src/oracledb/pool.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ def create_pool(
672672
whenever a new connection needs to be created (default: 1)
673673
674674
- connectiontype: the class of the connection that should be returned
675-
during calls to pool.acquire(). It must be Connection or a subclass of
676-
Connection (default: None)
675+
during calls to pool.acquire(). It must be oracledb.Connection or a
676+
subclass of oracledb.Connection (default: None)
677677
678678
- getmode: how pool.acquire() will behave. One of the constants
679679
oracledb.POOL_GETMODE_WAIT, oracledb.POOL_GETMODE_NOWAIT,
@@ -980,7 +980,7 @@ def create_pool_async(
980980
min: int = 1,
981981
max: int = 2,
982982
increment: int = 1,
983-
connectiontype: Type["oracledb.Connection"] = None,
983+
connectiontype: Type["oracledb.AsyncConnection"] = None,
984984
getmode: int = oracledb.POOL_GETMODE_WAIT,
985985
homogeneous: bool = True,
986986
timeout: int = 0,
@@ -1067,8 +1067,8 @@ def create_pool_async(
10671067
whenever a new connection needs to be created (default: 1)
10681068
10691069
- connectiontype: the class of the connection that should be returned
1070-
during calls to pool.acquire(). It must be Connection or a subclass of
1071-
Connection (default: None)
1070+
during calls to pool.acquire(). It must be oracledb.AsyncConnection or a
1071+
subclass of oracledb.AsyncConnection (default: None)
10721072
10731073
- getmode: how pool.acquire() will behave. One of the constants
10741074
oracledb.POOL_GETMODE_WAIT, oracledb.POOL_GETMODE_NOWAIT,

src/oracledb/pool_params.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def __init__(
122122
whenever a new connection needs to be created (default: 1)
123123
124124
- connectiontype: the class of the connection that should be returned
125-
during calls to pool.acquire(). It must be Connection or a subclass
126-
of Connection (default: None)
125+
during calls to pool.acquire(). It must be oracledb.Connection or a
126+
subclass of oracledb.Connection (default: None)
127127
128128
- getmode: how pool.acquire() will behave. One of the constants
129129
oracledb.POOL_GETMODE_WAIT, oracledb.POOL_GETMODE_NOWAIT,
@@ -383,7 +383,8 @@ def __repr__(self):
383383
def connectiontype(self) -> Type["oracledb.Connection"]:
384384
"""
385385
The class of the connection that should be returned during calls to
386-
pool.acquire(). It must be Connection or a subclass of Connection.
386+
pool.acquire(). It must be oracledb.Connection or a subclass of
387+
oracledb.Connection.
387388
"""
388389
return self._impl.connectiontype
389390

@@ -567,8 +568,8 @@ def set(
567568
whenever a new connection needs to be created
568569
569570
- connectiontype: the class of the connection that should be returned
570-
during calls to pool.acquire(). It must be Connection or a subclass
571-
of Connection
571+
during calls to pool.acquire(). It must be oracledb.Connection or a
572+
subclass of oracledb.Connection
572573
573574
- getmode: how pool.acquire() will behave. One of the constants
574575
oracledb.POOL_GETMODE_WAIT, oracledb.POOL_GETMODE_NOWAIT,

utils/build_from_template.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@
3131
#
3232
# # {{ args_help_with_defaults }}
3333
# is replaced by the arguments help string with field defaults
34+
# # {{ async_args_help_with_defaults }}
35+
# is replaced by the arguments help string with field defaults (async)
3436
# # {{ args_help_without_defaults }}
3537
# is replaced by the arguments help string without field defaults
3638
# # {{ args_with_defaults }}
3739
# is replaced by the arguments with field defaults included
40+
# # {{ async_args_with_defaults }}
41+
# is replaced by the arguments with field defaults included (async)
3842
# # {{ generated_notice }}
3943
# is replaced by a notice that the file is generated and should not be
4044
# modified directly
@@ -72,6 +76,18 @@ class Field:
7276
description: str = ""
7377
decorator: str = None
7478

79+
@property
80+
def async_description(self):
81+
return self.description.replace(
82+
"oracledb.Connection", "oracledb.AsyncConnection"
83+
)
84+
85+
@property
86+
def async_typ(self):
87+
return self.typ.replace(
88+
"oracledb.Connection", "oracledb.AsyncConnection"
89+
)
90+
7591

7692
# parse command line
7793
parser = argparse.ArgumentParser(description="build module from template")
@@ -174,6 +190,36 @@ def args_with_defaults_content(indent):
174190
return args_joiner.join(args)
175191

176192

193+
def async_args_help_with_defaults_content(indent):
194+
"""
195+
Generates the content for the async_args_help_with_defaults template tag.
196+
"""
197+
raw_descriptions = [
198+
f"- {f.name}: {f.async_description} (default: {f.default})"
199+
for f in fields
200+
if f.description
201+
]
202+
descriptions = [
203+
textwrap.fill(
204+
d,
205+
initial_indent=indent,
206+
subsequent_indent=indent + " ",
207+
width=TEXT_WIDTH,
208+
)
209+
for d in raw_descriptions
210+
]
211+
return "\n\n".join(descriptions).strip()
212+
213+
214+
def async_args_with_defaults_content(indent):
215+
"""
216+
Generates the content for the async_args_with_defaults template tag.
217+
"""
218+
args_joiner = "\n" + indent
219+
args = [f"{f.name}: {f.async_typ} = {f.default}," for f in fields]
220+
return args_joiner.join(args)
221+
222+
177223
def generated_notice_content(indent):
178224
"""
179225
Generates the content for the generated_notice template tag.
@@ -270,8 +316,12 @@ def params_setter_args_content(indent):
270316

271317
# replace generated_notice template tag
272318
replace_tag("args_help_with_defaults", args_help_with_defaults_content)
319+
replace_tag(
320+
"async_args_help_with_defaults", async_args_help_with_defaults_content
321+
)
273322
replace_tag("args_help_without_defaults", args_help_without_defaults_content)
274323
replace_tag("args_with_defaults", args_with_defaults_content)
324+
replace_tag("async_args_with_defaults", async_args_with_defaults_content)
275325
replace_tag("generated_notice", generated_notice_content)
276326
replace_tag("params_constructor_args", params_constructor_args_content)
277327
replace_tag("params_properties", params_properties_content)

utils/fields.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ type = Type["oracledb.Connection"]
5757
pool_only: True
5858
description =
5959
the class of the connection that should be returned during calls to
60-
pool.acquire(). It must be Connection or a subclass of Connection
60+
pool.acquire(). It must be oracledb.Connection or a subclass of
61+
oracledb.Connection
6162

6263
[getmode]
6364
type = int

utils/templates/pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def create_pool_async(
721721
*,
722722
pool_class: Type[ConnectionPool] = AsyncConnectionPool,
723723
params: PoolParams = None,
724-
# {{ args_with_defaults }}
724+
# {{ async_args_with_defaults }}
725725
) -> AsyncConnectionPool:
726726
"""
727727
Creates a connection pool with the supplied parameters and returns it.
@@ -749,6 +749,6 @@ def create_pool_async(
749749
The following parameters are all optional. A brief description of each
750750
parameter follows:
751751
752-
# {{ args_help_with_defaults }}
752+
# {{ async_args_help_with_defaults }}
753753
"""
754754
pass

0 commit comments

Comments
 (0)