Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints #539

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions vertica_python/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __ne__(self, other):
VerticaType.SET_LONGVARBINARY: VerticaType.LONGVARBINARY,
}

def getTypeName(data_type_oid, type_modifier):
def getTypeName(data_type_oid: int, type_modifier: int) -> str:
"""Returns the base type name according to data_type_oid and type_modifier"""
if data_type_oid in TYPENAME:
return TYPENAME[data_type_oid]
Expand All @@ -310,11 +310,11 @@ def getTypeName(data_type_oid, type_modifier):
else:
return "Unknown"

def getComplexElementType(data_type_oid):
def getComplexElementType(data_type_oid: int):
"""For 1D ARRAY or SET, returns the type of its elements"""
return COMPLEX_ELEMENT_TYPE.get(data_type_oid)

def getIntervalRange(data_type_oid, type_modifier):
def getIntervalRange(data_type_oid: int, type_modifier: int):
"""Extracts an interval's range from the bits set in its type_modifier"""

if data_type_oid not in (VerticaType.INTERVAL, VerticaType.INTERVALYM):
Expand Down Expand Up @@ -361,7 +361,7 @@ def getIntervalRange(data_type_oid, type_modifier):
return "Day to Second"


def getIntervalLeadingPrecision(data_type_oid, type_modifier):
def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int):
"""
Returns the leading precision for an interval, which is the largest number
of digits that can fit in the leading field of the interval.
Expand Down Expand Up @@ -394,7 +394,7 @@ def getIntervalLeadingPrecision(data_type_oid, type_modifier):
raise ValueError("Invalid interval range: {}".format(interval_range))


def getPrecision(data_type_oid, type_modifier):
def getPrecision(data_type_oid: int, type_modifier: int):
"""
Returns the precision for the given Vertica type with consideration of
the type modifier.
Expand Down Expand Up @@ -423,7 +423,7 @@ def getPrecision(data_type_oid, type_modifier):
return None # None if no meaningful values can be provided


def getScale(data_type_oid, type_modifier):
def getScale(data_type_oid: int, type_modifier: int):
"""
Returns the scale for the given Vertica type with consideration of
the type modifier.
Expand All @@ -435,7 +435,7 @@ def getScale(data_type_oid, type_modifier):
return None # None if no meaningful values can be provided


def getDisplaySize(data_type_oid, type_modifier):
def getDisplaySize(data_type_oid: int, type_modifier: int):
"""
Returns the column display size for the given Vertica type with
consideration of the type modifier.
Expand Down
6 changes: 3 additions & 3 deletions vertica_python/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os


def ensure_dir_exists(filepath):
def ensure_dir_exists(filepath: str) -> None:
"""Ensure that a directory exists

If it doesn't exist, try to create it and protect against a race condition
Expand All @@ -33,7 +33,7 @@ def ensure_dir_exists(filepath):
if e.errno != errno.EEXIST:
raise

def check_file_readable(filename):
def check_file_readable(filename: str) -> None:
"""Ensure this is a readable file"""
if not os.path.exists(filename):
raise OSError('{} does not exist'.format(filename))
Expand All @@ -42,7 +42,7 @@ def check_file_readable(filename):
elif not os.access(filename, os.R_OK):
raise OSError('{} is not readable'.format(filename))

def check_file_writable(filename):
def check_file_writable(filename: str) -> None:
"""Ensure this is a writable file. If the file doesn't exist,
ensure its directory is writable.
"""
Expand Down
Loading