Skip to content

Commit d3e14f6

Browse files
Corrected and enhanced type checking issues (#52, #54, #60).
1 parent aa9b1da commit d3e14f6

File tree

14 files changed

+86
-78
lines changed

14 files changed

+86
-78
lines changed

doc/src/release_notes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Thick Mode Changes
2525
Common Changes
2626
++++++++++++++
2727

28+
#) Fixed type checking errors
29+
(`issue 52 <https://github.com/oracle/python-oracledb/issues/52>`__).
30+
#) Enhanced type checking
31+
(`issue 54 <https://github.com/oracle/python-oracledb/issues/54>`__),
32+
(`issue 60 <https://github.com/oracle/python-oracledb/issues/60>`__).
33+
2834

2935
oracledb 1.1.0 (September 2022)
3036
-------------------------------

src/oracledb/aq.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import datetime
3333

3434
from . import connection as connection_module
35-
from typing import Type, Union
35+
from typing import Union, List
3636
from . import errors, exceptions
3737
from .dbobject import DbObject, DbObjectType
3838

@@ -48,7 +48,7 @@ def _from_impl(cls, connection, impl):
4848
queue._impl = impl
4949
return queue
5050

51-
def _verify_message(self, message: Type["MessageProperties"]) -> None:
51+
def _verify_message(self, message: "MessageProperties") -> None:
5252
"""
5353
Internal method used for verifying a message.
5454
"""
@@ -58,7 +58,7 @@ def _verify_message(self, message: Type["MessageProperties"]) -> None:
5858
errors._raise_err(errors.ERR_MESSAGE_HAS_NO_PAYLOAD)
5959

6060
@property
61-
def connection(self) -> Type["connection_module.Connection"]:
61+
def connection(self) -> "connection_module.Connection":
6262
"""
6363
Returns the connection on which the queue was created.
6464
"""
@@ -72,13 +72,13 @@ def deqmany(self, max_num_messages: int) -> list:
7272
message_impls = self._impl.deq_many(max_num_messages)
7373
return [MessageProperties._from_impl(impl) for impl in message_impls]
7474

75-
def deqMany(self, max_num_messages: int) -> list:
75+
def deqMany(self, max_num_messages: int) -> List["MessageProperties"]:
7676
"""
7777
Deprecated: use deqmany() instead.
7878
"""
7979
return self.deqmany(max_num_messages)
8080

81-
def deqone(self) -> Union[Type["MessageProperties"], None]:
81+
def deqone(self) -> Union["MessageProperties", None]:
8282
"""
8383
Dequeues at most one message from the queue and returns it. If no
8484
message is dequeued, None is returned.
@@ -87,22 +87,22 @@ def deqone(self) -> Union[Type["MessageProperties"], None]:
8787
if message_impl is not None:
8888
return MessageProperties._from_impl(message_impl)
8989

90-
def deqOne(self) -> Union[Type["MessageProperties"], None]:
90+
def deqOne(self) -> Union["MessageProperties", None]:
9191
"""
9292
Deprecated: use deqone() instead.
9393
"""
9494
return self.deqone()
9595

9696
@property
97-
def deqoptions(self) -> Type["DeqOptions"]:
97+
def deqoptions(self) -> "DeqOptions":
9898
"""
9999
Returns the options that will be used when dequeuing messages from the
100100
queue.
101101
"""
102102
return self._deq_options
103103

104104
@property
105-
def deqOptions(self) -> Type["DeqOptions"]:
105+
def deqOptions(self) -> "DeqOptions":
106106
"""
107107
Deprecated: use deqoptions instead.
108108
"""
@@ -131,7 +131,7 @@ def enqMany(self, messages: list) -> None:
131131
"""
132132
return self.enqmany(messages)
133133

134-
def enqone(self, message: Type["MessageProperties"]) -> None:
134+
def enqone(self, message: "MessageProperties") -> None:
135135
"""
136136
Enqueues a single message into the queue. The message must be a message
137137
property object which has had its payload attribute set to a value that
@@ -140,22 +140,22 @@ def enqone(self, message: Type["MessageProperties"]) -> None:
140140
self._verify_message(message)
141141
self._impl.enq_one(message._impl)
142142

143-
def enqOne(self, message: Type["MessageProperties"]) -> None:
143+
def enqOne(self, message: "MessageProperties") -> None:
144144
"""
145145
Deprecated: use enqone() instead.
146146
"""
147147
return self.enqone(message)
148148

149149
@property
150-
def enqoptions(self) -> Type["EnqOptions"]:
150+
def enqoptions(self) -> "EnqOptions":
151151
"""
152152
Returns the options that will be used when enqueuing messages into the
153153
queue.
154154
"""
155155
return self._enq_options
156156

157157
@property
158-
def enqOptions(self) -> Type["EnqOptions"]:
158+
def enqOptions(self) -> "EnqOptions":
159159
"""
160160
Deprecated: use enqoptions() instead.
161161
"""

src/oracledb/connect_params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#------------------------------------------------------------------------------
3535

3636
import functools
37-
from typing import Type, Union, Callable
37+
from typing import Union, Callable
3838

3939
import oracledb
4040

@@ -575,7 +575,7 @@ def wallet_location(self) -> Union[list, str]:
575575
"""
576576
return self._impl.wallet_location
577577

578-
def copy(self) -> Type["ConnectParams"]:
578+
def copy(self) -> "ConnectParams":
579579
"""
580580
Creates a copy of the parameters and returns it.
581581
"""

src/oracledb/connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Connection:
6464

6565
def __init__(self,
6666
dsn: str=None, *,
67-
pool: Type["pool_module.ConnectionPool"]=None,
67+
pool: "pool_module.ConnectionPool"=None,
6868
params: ConnectParams=None,
6969
**kwargs) -> None:
7070
"""
@@ -603,7 +603,7 @@ def prepare(self) -> bool:
603603
"""
604604
return self.tpc_prepare()
605605

606-
def queue(self, name: str, payload_type: [DbObjectType, str]=None, *,
606+
def queue(self, name: str, payload_type: Union[DbObjectType, str]=None, *,
607607
payloadType: DbObjectType=None) -> Queue:
608608
"""
609609
Creates and returns a queue which is used to enqueue and dequeue
@@ -1001,7 +1001,7 @@ class constructor does not check the validity of the supplied keyword
10011001
"""
10021002
@functools.wraps(f)
10031003
def connect(dsn: str=None, *,
1004-
pool: Type["pool_module.ConnectionPool"]=None,
1004+
pool: "pool_module.ConnectionPool"=None,
10051005
conn_class: Type[Connection]=Connection,
10061006
params: ConnectParams=None,
10071007
**kwargs) -> Connection:
@@ -1014,7 +1014,7 @@ def connect(dsn: str=None, *,
10141014

10151015
@_connection_factory
10161016
def connect(dsn: str=None, *,
1017-
pool: Type["pool_module.ConnectionPool"]=None,
1017+
pool: "pool_module.ConnectionPool"=None,
10181018
conn_class: Type[Connection]=Connection,
10191019
params: ConnectParams=None,
10201020
user: str=None,

src/oracledb/cursor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# fetching results from queries.
3030
#------------------------------------------------------------------------------
3131

32-
from typing import Any, Type, Union, Callable
32+
from typing import Any, Union, Callable
3333

3434
from . import __name__ as MODULE_NAME
3535
from . import errors, exceptions
@@ -42,7 +42,7 @@
4242
class Cursor:
4343
__module__ = MODULE_NAME
4444

45-
def __init__(self, connection: Type["connection_module.Connection"],
45+
def __init__(self, connection: "connection_module.Connection",
4646
scrollable: bool = False) -> None:
4747
self._impl = None
4848
self.connection = connection
@@ -309,7 +309,7 @@ def description(self) -> tuple:
309309

310310
def execute(self, statement: Union[str, None],
311311
parameters: Union[list, tuple, dict]=None,
312-
**keyword_parameters: dict) -> Union[Type["Cursor"], None]:
312+
**keyword_parameters: dict) -> Union["Cursor", None]:
313313
"""
314314
Execute a statement against the database.
315315
@@ -739,7 +739,7 @@ def var(self,
739739
encoding_errors: str=None,
740740
bypass_decode: bool=False,
741741
*,
742-
encodingErrors: str=None) -> Type["Var"]:
742+
encodingErrors: str=None) -> "Var":
743743
"""
744744
Create a variable with the specified characteristics. This method was
745745
designed for use with PL/SQL in/out variables where the length or type

src/oracledb/dbobject.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# object type metadata: DbObject, DbObjectType and DbObjectAttr.
3030
#------------------------------------------------------------------------------
3131

32-
from typing import Sequence, Type, Union
32+
from typing import Sequence, Union
3333

3434
from . import __name__ as MODULE_NAME
3535
from .base_impl import DbType
@@ -91,7 +91,7 @@ def aslist(self) -> list:
9191
ix = self._impl.get_next_index(ix)
9292
return result
9393

94-
def copy(self) -> Type["DbObject"]:
94+
def copy(self) -> "DbObject":
9595
"""
9696
Create a copy of the object and return it.
9797
"""
@@ -181,7 +181,7 @@ def trim(self, num: int) -> None:
181181
self._impl.trim(num)
182182

183183
@property
184-
def type(self) -> Type["DbObjectType"]:
184+
def type(self) -> "DbObjectType":
185185
"""
186186
Returns an ObjectType corresponding to the type of the object.
187187
"""
@@ -211,7 +211,7 @@ def name(self) -> str:
211211
return self._impl.name
212212

213213
@property
214-
def type(self) -> Union[Type["DbObjectType"], DbType]:
214+
def type(self) -> Union["DbObjectType", DbType]:
215215
"""
216216
This read-only attribute returns the type of the attribute. This will
217217
be an Oracle Object Type if the variable binds Oracle objects;
@@ -274,7 +274,7 @@ def name(self) -> str:
274274
return self._impl.name
275275

276276
@property
277-
def element_type(self) -> Union[Type["DbObjectType"], DbType]:
277+
def element_type(self) -> Union["DbObjectType", DbType]:
278278
"""
279279
This read-only attribute returns the type of elements found in
280280
collections of this type, if iscollection is True; otherwise, it

src/oracledb/pool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def acquire(self,
120120
tag: str=None,
121121
matchanytag: bool=False,
122122
shardingkey: list=None,
123-
supershardingkey: list=None) -> Type["connection_module.Connection"]:
123+
supershardingkey: list=None) -> "connection_module.Connection":
124124
"""
125125
Acquire a connection from the pool and return it.
126126
@@ -177,7 +177,7 @@ def close(self, force: bool=False) -> None:
177177
self._impl.close(force)
178178
self._impl = None
179179

180-
def drop(self, connection: Type["connection_module.Connection"]) -> None:
180+
def drop(self, connection: "connection_module.Connection") -> None:
181181
"""
182182
Drop the connection from the pool, which is useful if the connection is
183183
no longer usable (such as when the database session is killed).
@@ -322,7 +322,7 @@ def ping_interval(self) -> int:
322322
def ping_interval(self, value: int) -> None:
323323
self._impl.set_ping_interval(value)
324324

325-
def release(self, connection: Type["connection_module.Connection"],
325+
def release(self, connection: "connection_module.Connection",
326326
tag: str=None) -> None:
327327
"""
328328
Release the connection back to the pool now, rather than whenever

src/oracledb/pool_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def wait_timeout(self) -> int:
468468
"""
469469
return self._impl.wait_timeout
470470

471-
def copy(self) -> Type["PoolParams"]:
471+
def copy(self) -> "PoolParams":
472472
"""
473473
Creates a copy of the parameters and returns it.
474474
"""

0 commit comments

Comments
 (0)