Skip to content

Commit 68c6f35

Browse files
Use functools.wraps() instead of manipulating __qualname__; use the name
of the top-level function in order to make the function name match in versions earlier than Python 3.10.
1 parent 9bd497f commit 68c6f35

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/oracledb/connect_params.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# more information.
3434
#------------------------------------------------------------------------------
3535

36+
import functools
3637
from typing import Type, Union
3738

3839
import oracledb
@@ -261,26 +262,26 @@ def _address_attr(f):
261262
"""
262263
Helper function used to get address level attributes.
263264
"""
265+
@functools.wraps(f)
264266
def wrapped(self):
265267
output = []
266268
for description in self._impl.description_list.descriptions:
267269
for address_list in description.address_lists:
268270
for address in address_list.addresses:
269271
output.append(getattr(address, f.__name__))
270272
return output if len(output) > 1 else output[0]
271-
wrapped.__qualname__ = f.__qualname__
272273
return wrapped
273274

274275
def _description_attr(f):
275276
"""
276277
Helper function used to get description level attributes.
277278
"""
279+
@functools.wraps(f)
278280
def wrapped(self):
279281
output = []
280282
for description in self._impl.description_list.descriptions:
281283
output.append(getattr(description, f.__name__))
282284
return output if len(output) > 1 else output[0]
283-
wrapped.__qualname__ = f.__qualname__
284285
return wrapped
285286

286287
@property

src/oracledb/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#------------------------------------------------------------------------------
3131

3232
import collections
33+
import functools
3334

3435
from . import __name__ as MODULE_NAME
3536

@@ -987,7 +988,8 @@ def _connection_factory(f):
987988
class constructor does not check the validity of the supplied keyword
988989
parameters.
989990
"""
990-
def wrapped(dsn: str=None, *,
991+
@functools.wraps(f)
992+
def connect(dsn: str=None, *,
991993
pool: Type["pool_module.ConnectionPool"]=None,
992994
conn_class: Type[Connection]=Connection,
993995
params: ConnectParams=None,
@@ -996,8 +998,7 @@ def wrapped(dsn: str=None, *,
996998
if not issubclass(conn_class, Connection):
997999
errors._raise_err(errors.INVALID_CONN_CLASS)
9981000
return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
999-
wrapped.__qualname__ = f.__qualname__
1000-
return wrapped
1001+
return connect
10011002

10021003

10031004
@_connection_factory

src/oracledb/pool.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# for creating connection pools.
3030
#------------------------------------------------------------------------------
3131

32+
import functools
3233
from typing import Callable, Type
3334

3435
import oracledb
@@ -528,16 +529,16 @@ def _pool_factory(f):
528529
ConnectionPool class constructor does not check the validity of the
529530
supplied keyword parameters.
530531
"""
531-
def wrapped(dsn: str=None, *,
532+
@functools.wraps(f)
533+
def create_pool(dsn: str=None, *,
532534
pool_class: Type[ConnectionPool]=ConnectionPool,
533535
params: PoolParams=None,
534536
**kwargs) -> ConnectionPool:
535537
f(dsn=dsn, pool_class=pool_class, params=params, **kwargs)
536538
if not issubclass(pool_class, ConnectionPool):
537539
errors._raise_err(errors.INVALID_POOL_CLASS)
538540
return pool_class(dsn, params=params, **kwargs)
539-
wrapped.__qualname__ = f.__qualname__
540-
return wrapped
541+
return create_pool
541542

542543

543544
@_pool_factory

utils/connect_params_template.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#{{ generated_notice }}
3232
#------------------------------------------------------------------------------
3333

34+
import functools
3435
from typing import Type, Union
3536

3637
import oracledb
@@ -54,25 +55,27 @@ def _address_attr(f):
5455
"""
5556
Helper function used to get address level attributes.
5657
"""
57-
def wrapped_func(self):
58+
@functools.wraps(f)
59+
def wrapped(self):
5860
output = []
5961
for description in self._impl.description_list.descriptions:
6062
for address_list in description.address_lists:
6163
for address in address_list.addresses:
6264
output.append(getattr(address, f.__name__))
6365
return output if len(output) > 1 else output[0]
64-
return wrapped_func
66+
return wrapped
6567

6668
def _description_attr(f):
6769
"""
6870
Helper function used to get description level attributes.
6971
"""
70-
def wrapped_func(self):
72+
@functools.wraps(f)
73+
def wrapped(self):
7174
output = []
7275
for description in self._impl.description_list.descriptions:
7376
output.append(getattr(description, f.__name__))
7477
return output if len(output) > 1 else output[0]
75-
return wrapped_func
78+
return wrapped
7679

7780
#{{ properties }}
7881

0 commit comments

Comments
 (0)