Skip to content

Commit c146228

Browse files
author
Siting Ren
authored
Add type hints (cont.) (#541)
1 parent 4a13f85 commit c146228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+233
-191
lines changed

vertica_python/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3434
# THE SOFTWARE.
3535

36-
from __future__ import print_function, division, absolute_import
36+
from __future__ import print_function, division, absolute_import, annotations
3737

3838
from .vertica.connection import Connection, connect, parse_dsn
3939

vertica_python/datatypes.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@
3434
# THE SOFTWARE.
3535

3636

37-
from __future__ import print_function, division, absolute_import
37+
from __future__ import print_function, division, absolute_import, annotations
3838

3939
from datetime import date, datetime, time, timezone
40+
from typing import TYPE_CHECKING
41+
if TYPE_CHECKING:
42+
from typing import Optional
4043

4144

4245
# noinspection PyPep8Naming
@@ -298,7 +301,7 @@ def __ne__(self, other):
298301
}
299302

300303
def getTypeName(data_type_oid: int, type_modifier: int) -> str:
301-
"""Returns the base type name according to data_type_oid and type_modifier"""
304+
"""Returns the base type name according to data_type_oid and type_modifier."""
302305
if data_type_oid in TYPENAME:
303306
return TYPENAME[data_type_oid]
304307
elif data_type_oid in (VerticaType.INTERVAL, VerticaType.INTERVALYM):
@@ -310,12 +313,12 @@ def getTypeName(data_type_oid: int, type_modifier: int) -> str:
310313
else:
311314
return "Unknown"
312315

313-
def getComplexElementType(data_type_oid: int):
314-
"""For 1D ARRAY or SET, returns the type of its elements"""
316+
def getComplexElementType(data_type_oid: int) -> Optional[int]:
317+
"""For 1D ARRAY or SET, returns the type of its elements."""
315318
return COMPLEX_ELEMENT_TYPE.get(data_type_oid)
316319

317-
def getIntervalRange(data_type_oid: int, type_modifier: int):
318-
"""Extracts an interval's range from the bits set in its type_modifier"""
320+
def getIntervalRange(data_type_oid: int, type_modifier: int) -> str:
321+
"""Extracts an interval's range from the bits set in its type_modifier."""
319322

320323
if data_type_oid not in (VerticaType.INTERVAL, VerticaType.INTERVALYM):
321324
raise ValueError("Invalid data type OID: {}".format(data_type_oid))
@@ -361,7 +364,7 @@ def getIntervalRange(data_type_oid: int, type_modifier: int):
361364
return "Day to Second"
362365

363366

364-
def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int):
367+
def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int) -> int:
365368
"""
366369
Returns the leading precision for an interval, which is the largest number
367370
of digits that can fit in the leading field of the interval.
@@ -394,7 +397,7 @@ def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int):
394397
raise ValueError("Invalid interval range: {}".format(interval_range))
395398

396399

397-
def getPrecision(data_type_oid: int, type_modifier: int):
400+
def getPrecision(data_type_oid: int, type_modifier: int) -> Optional[int]:
398401
"""
399402
Returns the precision for the given Vertica type with consideration of
400403
the type modifier.
@@ -423,22 +426,23 @@ def getPrecision(data_type_oid: int, type_modifier: int):
423426
return None # None if no meaningful values can be provided
424427

425428

426-
def getScale(data_type_oid: int, type_modifier: int):
429+
def getScale(data_type_oid: int, type_modifier: int) -> Optional[int]:
427430
"""
428431
Returns the scale for the given Vertica type with consideration of
429-
the type modifier.
432+
the type modifier. Returns None if no meaningful values can be provided.
430433
"""
431434

432435
if data_type_oid == VerticaType.NUMERIC:
433436
return 15 if type_modifier == -1 else (type_modifier - 4) & 0xFF
434437
else:
435-
return None # None if no meaningful values can be provided
438+
return None
436439

437440

438-
def getDisplaySize(data_type_oid: int, type_modifier: int):
441+
def getDisplaySize(data_type_oid: int, type_modifier: int) -> Optional[int]:
439442
"""
440443
Returns the column display size for the given Vertica type with
441444
consideration of the type modifier.
445+
Returns None if no meaningful values can be provided.
442446
443447
The display size of a column is the maximum number of characters needed to
444448
display data in character form.

vertica_python/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# THE SOFTWARE.
3535

3636

37-
from __future__ import print_function, division, absolute_import
37+
from __future__ import print_function, division, absolute_import, annotations
3838

3939
import re
4040

vertica_python/os_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515

16-
from __future__ import print_function, division, absolute_import
16+
from __future__ import print_function, division, absolute_import, annotations
1717

1818
import errno
1919
import os

vertica_python/tests/common/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3434
# THE SOFTWARE.
3535

36-
from __future__ import print_function, division, absolute_import
36+
from __future__ import print_function, division, absolute_import, annotations
3737

3838
import os
3939
import sys

vertica_python/tests/integration_tests/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3434
# THE SOFTWARE.
3535

36-
from __future__ import print_function, division, absolute_import
36+
from __future__ import print_function, division, absolute_import, annotations
3737

3838
import pytest
3939

vertica_python/tests/integration_tests/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from __future__ import print_function, division, absolute_import
15+
from __future__ import print_function, division, absolute_import, annotations
1616

1717
from .base import VerticaPythonIntegrationTestCase
1818

vertica_python/tests/integration_tests/test_cancel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from __future__ import print_function, division, absolute_import
15+
from __future__ import print_function, division, absolute_import, annotations
1616

1717
from multiprocessing import Process
1818
import pytest

vertica_python/tests/integration_tests/test_column.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3434
# THE SOFTWARE.
3535

36-
from __future__ import print_function, division, absolute_import
36+
from __future__ import print_function, division, absolute_import, annotations
3737

3838
from .base import VerticaPythonIntegrationTestCase
3939

vertica_python/tests/integration_tests/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3434
# THE SOFTWARE.
3535

36-
from __future__ import print_function, division, absolute_import
36+
from __future__ import print_function, division, absolute_import, annotations
3737

3838
import getpass
3939
import socket

0 commit comments

Comments
 (0)