Skip to content

Commit 72a677a

Browse files
Make type checkers happy.
1 parent 05a297b commit 72a677a

File tree

8 files changed

+127
-86
lines changed

8 files changed

+127
-86
lines changed

src/oracledb/__init__.py

Lines changed: 98 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,76 +30,118 @@
3030

3131
import sys
3232

33-
from .version import __version__
33+
from .version import (
34+
__version__ as __version__
35+
)
36+
3437
from .constants import *
3538
from .exceptions import *
36-
from .errors import _Error
37-
from .defaults import defaults
38-
from .connection import connect, Connection
39-
from .cursor import Cursor
40-
from .pool import create_pool, ConnectionPool
41-
from .connect_params import ConnectParams
42-
from .pool_params import PoolParams
43-
from .lob import LOB
44-
from .dbobject import DbObject, DbObjectType
45-
from .var import Var
46-
from .dsn import makedsn
47-
from .driver_mode import is_thin_mode
39+
40+
from .errors import (
41+
_Error as _Error
42+
)
43+
44+
from .defaults import (
45+
defaults as defaults
46+
)
47+
48+
from .connection import (
49+
connect as connect,
50+
Connection as Connection
51+
)
52+
53+
from .cursor import (
54+
Cursor as Cursor
55+
)
56+
57+
from .pool import (
58+
create_pool as create_pool,
59+
ConnectionPool as ConnectionPool
60+
)
61+
62+
from .connect_params import (
63+
ConnectParams as ConnectParams
64+
)
65+
66+
from .pool_params import (
67+
PoolParams as PoolParams
68+
)
69+
70+
from .lob import (
71+
LOB as LOB
72+
)
73+
74+
from .dbobject import (
75+
DbObject as DbObject,
76+
DbObjectType as DbObjectType
77+
)
78+
79+
from .var import (
80+
Var as Var
81+
)
82+
83+
from .dsn import (
84+
makedsn as makedsn
85+
)
86+
87+
from .driver_mode import (
88+
is_thin_mode as is_thin_mode
89+
)
4890

4991
from .base_impl import (
5092

5193
# database types
52-
DB_TYPE_BFILE,
53-
DB_TYPE_BINARY_DOUBLE,
54-
DB_TYPE_BINARY_FLOAT,
55-
DB_TYPE_BINARY_INTEGER,
56-
DB_TYPE_BLOB,
57-
DB_TYPE_BOOLEAN,
58-
DB_TYPE_CHAR,
59-
DB_TYPE_CLOB,
60-
DB_TYPE_CURSOR,
61-
DB_TYPE_DATE,
62-
DB_TYPE_INTERVAL_DS,
63-
DB_TYPE_INTERVAL_YM,
64-
DB_TYPE_JSON,
65-
DB_TYPE_LONG,
66-
DB_TYPE_LONG_NVARCHAR,
67-
DB_TYPE_LONG_RAW,
68-
DB_TYPE_NCHAR,
69-
DB_TYPE_NCLOB,
70-
DB_TYPE_NUMBER,
71-
DB_TYPE_NVARCHAR,
72-
DB_TYPE_OBJECT,
73-
DB_TYPE_RAW,
74-
DB_TYPE_ROWID,
75-
DB_TYPE_TIMESTAMP,
76-
DB_TYPE_TIMESTAMP_LTZ,
77-
DB_TYPE_TIMESTAMP_TZ,
78-
DB_TYPE_UNKNOWN,
79-
DB_TYPE_UROWID,
80-
DB_TYPE_VARCHAR,
94+
DB_TYPE_BFILE as DB_TYPE_BFILE,
95+
DB_TYPE_BINARY_DOUBLE as DB_TYPE_BINARY_DOUBLE,
96+
DB_TYPE_BINARY_FLOAT as DB_TYPE_BINARY_FLOAT,
97+
DB_TYPE_BINARY_INTEGER as DB_TYPE_BINARY_INTEGER,
98+
DB_TYPE_BLOB as DB_TYPE_BLOB,
99+
DB_TYPE_BOOLEAN as DB_TYPE_BOOLEAN,
100+
DB_TYPE_CHAR as DB_TYPE_CHAR,
101+
DB_TYPE_CLOB as DB_TYPE_CLOB,
102+
DB_TYPE_CURSOR as DB_TYPE_CURSOR,
103+
DB_TYPE_DATE as DB_TYPE_DATE,
104+
DB_TYPE_INTERVAL_DS as DB_TYPE_INTERVAL_DS,
105+
DB_TYPE_INTERVAL_YM as DB_TYPE_INTERVAL_YM,
106+
DB_TYPE_JSON as DB_TYPE_JSON,
107+
DB_TYPE_LONG as DB_TYPE_LONG,
108+
DB_TYPE_LONG_NVARCHAR as DB_TYPE_LONG_NVARCHAR,
109+
DB_TYPE_LONG_RAW as DB_TYPE_LONG_RAW,
110+
DB_TYPE_NCHAR as DB_TYPE_NCHAR,
111+
DB_TYPE_NCLOB as DB_TYPE_NCLOB,
112+
DB_TYPE_NUMBER as DB_TYPE_NUMBER,
113+
DB_TYPE_NVARCHAR as DB_TYPE_NVARCHAR,
114+
DB_TYPE_OBJECT as DB_TYPE_OBJECT,
115+
DB_TYPE_RAW as DB_TYPE_RAW,
116+
DB_TYPE_ROWID as DB_TYPE_ROWID,
117+
DB_TYPE_TIMESTAMP as DB_TYPE_TIMESTAMP,
118+
DB_TYPE_TIMESTAMP_LTZ as DB_TYPE_TIMESTAMP_LTZ,
119+
DB_TYPE_TIMESTAMP_TZ as DB_TYPE_TIMESTAMP_TZ,
120+
DB_TYPE_UNKNOWN as DB_TYPE_UNKNOWN,
121+
DB_TYPE_UROWID as DB_TYPE_UROWID,
122+
DB_TYPE_VARCHAR as DB_TYPE_VARCHAR,
81123

82124
# API types
83-
BINARY,
84-
DATETIME,
85-
NUMBER,
86-
ROWID,
87-
STRING
125+
BINARY as BINARY,
126+
DATETIME as DATETIME,
127+
NUMBER as NUMBER,
128+
ROWID as ROWID,
129+
STRING as STRING
88130
)
89131

90132
from .thick_impl import (
91-
clientversion,
92-
init_oracle_client
133+
clientversion as clientversion,
134+
init_oracle_client as init_oracle_client
93135
)
94136

95137
from .constructors import (
96-
Binary,
97-
Date,
98-
DateFromTicks,
99-
Time,
100-
TimeFromTicks,
101-
Timestamp,
102-
TimestampFromTicks
138+
Binary as Binary,
139+
Date as Date,
140+
DateFromTicks as DateFromTicks,
141+
Time as Time,
142+
TimeFromTicks as TimeFromTicks,
143+
Timestamp as Timestamp,
144+
TimestampFromTicks as TimestampFromTicks
103145
)
104146

105147
package = sys.modules[__name__]

src/oracledb/aq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023, 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
@@ -32,7 +32,7 @@
3232
import datetime
3333

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

@@ -491,7 +491,7 @@ def payload(self) -> Union[bytes, DbObject]:
491491
return self._impl.payload
492492

493493
@payload.setter
494-
def payload(self, value: object) -> None:
494+
def payload(self, value: Any) -> None:
495495
if isinstance(value, DbObject):
496496
self._impl.set_payload_object(value._impl)
497497
elif not isinstance(value, (str, bytes)):

src/oracledb/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def module(self, value: str) -> None:
533533
self._verify_connected()
534534
self._impl.set_module(value)
535535

536-
def msgproperties(self, payload: Union[bytes, DbObject]=None,
536+
def msgproperties(self, payload: Union[bytes, str, DbObject]=None,
537537
correlation: str=None, delay: int=None,
538538
exceptionq: str=None, expiration: int=None,
539539
priority: int=None, recipients: list=None) -> MessageProperties:

src/oracledb/cursor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ def bindvars(self) -> list:
240240
self._verify_open()
241241
return self._impl.get_bind_vars()
242242

243-
def callfunc(self, name: str, return_type: object,
243+
def callfunc(self, name: str, return_type: Any,
244244
parameters: Union[list, tuple]=None,
245245
keyword_parameters: dict=None, *,
246-
keywordParameters: dict=None) -> object:
246+
keywordParameters: dict=None) -> Any:
247247
"""
248248
Call a function with the given name. The return type is specified in
249249
the same notation as is required by setinputsizes(). The sequence of
@@ -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: Any) -> Union["Cursor", None]:
312+
**keyword_parameters: Any) -> Any:
313313
"""
314314
Execute a statement against the database.
315315
@@ -495,7 +495,7 @@ def fetchmany(self, size: int=None, numRows: int=None) -> list:
495495
result.append(row)
496496
return result
497497

498-
def fetchone(self) -> object:
498+
def fetchone(self) -> Any:
499499
"""
500500
Fetch the next row of a query result set, returning a single tuple or
501501
None when no more data is available.

src/oracledb/dbobject.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023, 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
@@ -29,7 +29,7 @@
2929
# object type metadata: DbObject, DbObjectType and DbObjectAttr.
3030
#------------------------------------------------------------------------------
3131

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

3434
from . import errors
3535
from . import __name__ as MODULE_NAME
@@ -69,7 +69,7 @@ def _from_impl(cls, impl):
6969
obj._type = None
7070
return obj
7171

72-
def append(self, element: object) -> None:
72+
def append(self, element: Any) -> None:
7373
"""
7474
Append an element to the collection object. If no elements exist in the
7575
collection, this creates an element at index 0; otherwise, it creates
@@ -147,7 +147,7 @@ def first(self) -> int:
147147
self._ensure_is_collection()
148148
return self._impl.get_first_index()
149149

150-
def getelement(self, index: int) -> object:
150+
def getelement(self, index: int) -> Any:
151151
"""
152152
Return the element at the specified index of the collection. If no
153153
element exists at that index, an exception is raised.
@@ -181,7 +181,7 @@ def prev(self, index: int) -> int:
181181
self._ensure_is_collection()
182182
return self._impl.get_prev_index(index)
183183

184-
def setelement(self, index: int, value: object) -> None:
184+
def setelement(self, index: int, value: Any) -> None:
185185
"""
186186
Set the value in the collection at the specified index to the given
187187
value.

src/oracledb/lob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Contains the LOB class for managing BLOB, CLOB, NCLOB and BFILE data.
2929
#------------------------------------------------------------------------------
3030

31-
from typing import Union
31+
from typing import Any, Union
3232

3333
from . import __name__ as MODULE_NAME
3434
from . import errors
@@ -146,7 +146,7 @@ def trim(self, new_size: int=0, *, newSize: int=None) -> None:
146146
self._impl.trim(new_size)
147147

148148
@property
149-
def type(self) -> object:
149+
def type(self) -> Any:
150150
"""
151151
Returns the type of the LOB as one of the database type constants.
152152
"""

src/oracledb/soda.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2023, 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
@@ -29,7 +29,7 @@
2929
# SodaDatabase, SodaCollection, SodaDocument, SodaDocCursor and SodaOperation.
3030
#------------------------------------------------------------------------------
3131

32-
from typing import Union, List
32+
from typing import Any, Union, List
3333
import json
3434

3535
from . import connection, errors
@@ -46,7 +46,7 @@ def _from_impl(cls, conn, impl):
4646
db._impl = impl
4747
return db
4848

49-
def _get_content_bytes(self, content: object) -> bytes:
49+
def _get_content_bytes(self, content: Any) -> bytes:
5050
"""
5151
Internal method used for returning the bytes to store in document
5252
content.
@@ -84,7 +84,7 @@ def createCollection(self, name: str, metadata: Union[str, dict]=None,
8484
collection_impl = self._impl.create_collection(name, metadata, mapMode)
8585
return SodaCollection._from_impl(self, collection_impl)
8686

87-
def createDocument(self, content: object, key: str=None,
87+
def createDocument(self, content: Any, key: str=None,
8888
mediaType: str="application/json") -> "SodaDocument":
8989
"""
9090
Creates a SODA document usable for SODA write operations. You only need
@@ -245,16 +245,15 @@ def insertManyAndGet(self, docs: list, hint: str=None) -> list:
245245
return_docs=True)
246246
return [SodaDocument._from_impl(i) for i in return_doc_impls]
247247

248-
def insertOne(self, doc: object) -> None:
248+
def insertOne(self, doc: Any) -> None:
249249
"""
250250
Inserts a given document into the collection. The input document can be
251251
a dictionary or list or an existing SODA document object.
252252
"""
253253
doc_impl = self._process_doc_arg(doc)
254254
self._impl.insert_one(doc_impl, hint=None, return_doc=False)
255255

256-
def insertOneAndGet(self, doc: object,
257-
hint: str=None) -> "SodaDocument":
256+
def insertOneAndGet(self, doc: Any, hint: str=None) -> "SodaDocument":
258257
"""
259258
Similarly to insertOne() this method inserts a given document into the
260259
collection. The only difference is that it returns a SODA Document
@@ -291,7 +290,7 @@ def name(self) -> str:
291290
"""
292291
return self._impl.name
293292

294-
def save(self, doc: object) -> None:
293+
def save(self, doc: Any) -> None:
295294
"""
296295
Saves a document into the collection. This method is equivalent to
297296
insertOne() except that if client-assigned keys are used, and the
@@ -301,7 +300,7 @@ def save(self, doc: object) -> None:
301300
doc_impl = self._process_doc_arg(doc)
302301
self._impl.save(doc_impl, hint=None, return_doc=False)
303302

304-
def saveAndGet(self, doc: object, hint: str=None) -> "SodaDocument":
303+
def saveAndGet(self, doc: Any, hint: str=None) -> "SodaDocument":
305304
"""
306305
Saves a document into the collection. This method is equivalent to
307306
insertOneAndGet() except that if client-assigned keys are used, and the
@@ -601,7 +600,7 @@ def remove(self) -> int:
601600
"""
602601
return self._collection._impl.remove(self)
603602

604-
def replaceOne(self, doc: object) -> bool:
603+
def replaceOne(self, doc: Any) -> bool:
605604
"""
606605
Replaces a single document in the collection with the specified
607606
document. The input document can be a dictionary or list or an existing
@@ -615,7 +614,7 @@ def replaceOne(self, doc: object) -> bool:
615614
return self._collection._impl.replace_one(self, doc_impl,
616615
return_doc=False)
617616

618-
def replaceOneAndGet(self, doc: object) -> "SodaDocument":
617+
def replaceOneAndGet(self, doc: Any) -> "SodaDocument":
619618
"""
620619
Similarly to replaceOne(), this method replaces a single document in
621620
the collection with the specified document. The only difference is that

0 commit comments

Comments
 (0)