diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py index 2393cb46..425b6d69 100644 --- a/vertica_python/__init__.py +++ b/vertica_python/__init__.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .vertica.connection import Connection, connect, parse_dsn diff --git a/vertica_python/datatypes.py b/vertica_python/datatypes.py index 20623105..e8db82ad 100644 --- a/vertica_python/datatypes.py +++ b/vertica_python/datatypes.py @@ -34,9 +34,12 @@ # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from datetime import date, datetime, time, timezone +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from typing import Optional # noinspection PyPep8Naming @@ -298,7 +301,7 @@ def __ne__(self, other): } def getTypeName(data_type_oid: int, type_modifier: int) -> str: - """Returns the base type name according to data_type_oid and type_modifier""" + """Returns the base type name according to data_type_oid and type_modifier.""" if data_type_oid in TYPENAME: return TYPENAME[data_type_oid] elif data_type_oid in (VerticaType.INTERVAL, VerticaType.INTERVALYM): @@ -310,12 +313,12 @@ def getTypeName(data_type_oid: int, type_modifier: int) -> str: else: return "Unknown" -def getComplexElementType(data_type_oid: int): - """For 1D ARRAY or SET, returns the type of its elements""" +def getComplexElementType(data_type_oid: int) -> Optional[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: int, type_modifier: int): - """Extracts an interval's range from the bits set in its type_modifier""" +def getIntervalRange(data_type_oid: int, type_modifier: int) -> str: + """Extracts an interval's range from the bits set in its type_modifier.""" if data_type_oid not in (VerticaType.INTERVAL, VerticaType.INTERVALYM): raise ValueError("Invalid data type OID: {}".format(data_type_oid)) @@ -361,7 +364,7 @@ def getIntervalRange(data_type_oid: int, type_modifier: int): return "Day to Second" -def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int): +def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int) -> 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. @@ -394,7 +397,7 @@ def getIntervalLeadingPrecision(data_type_oid: int, type_modifier: int): raise ValueError("Invalid interval range: {}".format(interval_range)) -def getPrecision(data_type_oid: int, type_modifier: int): +def getPrecision(data_type_oid: int, type_modifier: int) -> Optional[int]: """ Returns the precision for the given Vertica type with consideration of the type modifier. @@ -423,22 +426,23 @@ def getPrecision(data_type_oid: int, type_modifier: int): return None # None if no meaningful values can be provided -def getScale(data_type_oid: int, type_modifier: int): +def getScale(data_type_oid: int, type_modifier: int) -> Optional[int]: """ Returns the scale for the given Vertica type with consideration of - the type modifier. + the type modifier. Returns None if no meaningful values can be provided. """ if data_type_oid == VerticaType.NUMERIC: return 15 if type_modifier == -1 else (type_modifier - 4) & 0xFF else: - return None # None if no meaningful values can be provided + return None -def getDisplaySize(data_type_oid: int, type_modifier: int): +def getDisplaySize(data_type_oid: int, type_modifier: int) -> Optional[int]: """ Returns the column display size for the given Vertica type with consideration of the type modifier. + Returns None if no meaningful values can be provided. The display size of a column is the maximum number of characters needed to display data in character form. diff --git a/vertica_python/errors.py b/vertica_python/errors.py index 5fa25f15..26bc3f64 100644 --- a/vertica_python/errors.py +++ b/vertica_python/errors.py @@ -34,7 +34,7 @@ # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import re diff --git a/vertica_python/os_utils.py b/vertica_python/os_utils.py index 14113efa..36545f66 100644 --- a/vertica_python/os_utils.py +++ b/vertica_python/os_utils.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import errno import os diff --git a/vertica_python/tests/common/base.py b/vertica_python/tests/common/base.py index 597c03c3..11d8ec43 100644 --- a/vertica_python/tests/common/base.py +++ b/vertica_python/tests/common/base.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import os import sys diff --git a/vertica_python/tests/integration_tests/base.py b/vertica_python/tests/integration_tests/base.py index 72cd39a3..64067ec4 100644 --- a/vertica_python/tests/integration_tests/base.py +++ b/vertica_python/tests/integration_tests/base.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import pytest diff --git a/vertica_python/tests/integration_tests/test_authentication.py b/vertica_python/tests/integration_tests/test_authentication.py index c63f05e0..5df8f9a6 100644 --- a/vertica_python/tests/integration_tests/test_authentication.py +++ b/vertica_python/tests/integration_tests/test_authentication.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonIntegrationTestCase diff --git a/vertica_python/tests/integration_tests/test_cancel.py b/vertica_python/tests/integration_tests/test_cancel.py index e9517c86..8c4e9cd8 100644 --- a/vertica_python/tests/integration_tests/test_cancel.py +++ b/vertica_python/tests/integration_tests/test_cancel.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from multiprocessing import Process import pytest diff --git a/vertica_python/tests/integration_tests/test_column.py b/vertica_python/tests/integration_tests/test_column.py index 34e67801..657b9b26 100644 --- a/vertica_python/tests/integration_tests/test_column.py +++ b/vertica_python/tests/integration_tests/test_column.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonIntegrationTestCase diff --git a/vertica_python/tests/integration_tests/test_connection.py b/vertica_python/tests/integration_tests/test_connection.py index de23069f..e9015c03 100644 --- a/vertica_python/tests/integration_tests/test_connection.py +++ b/vertica_python/tests/integration_tests/test_connection.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import getpass import socket diff --git a/vertica_python/tests/integration_tests/test_cursor.py b/vertica_python/tests/integration_tests/test_cursor.py index 50ba5cd9..4a8b52fa 100644 --- a/vertica_python/tests/integration_tests/test_cursor.py +++ b/vertica_python/tests/integration_tests/test_cursor.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from datetime import date, datetime, time from dateutil.relativedelta import relativedelta diff --git a/vertica_python/tests/integration_tests/test_datatypes.py b/vertica_python/tests/integration_tests/test_datatypes.py index 8fd6aad6..ed346ee9 100644 --- a/vertica_python/tests/integration_tests/test_datatypes.py +++ b/vertica_python/tests/integration_tests/test_datatypes.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from datetime import date, datetime, time from dateutil.relativedelta import relativedelta diff --git a/vertica_python/tests/integration_tests/test_dates.py b/vertica_python/tests/integration_tests/test_dates.py index c4157f96..06729397 100644 --- a/vertica_python/tests/integration_tests/test_dates.py +++ b/vertica_python/tests/integration_tests/test_dates.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from collections import namedtuple from datetime import date diff --git a/vertica_python/tests/integration_tests/test_errors.py b/vertica_python/tests/integration_tests/test_errors.py index 243eb1ac..b3bbea96 100644 --- a/vertica_python/tests/integration_tests/test_errors.py +++ b/vertica_python/tests/integration_tests/test_errors.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonIntegrationTestCase diff --git a/vertica_python/tests/integration_tests/test_loadbalance.py b/vertica_python/tests/integration_tests/test_loadbalance.py index cb590c5a..abfa5ba1 100644 --- a/vertica_python/tests/integration_tests/test_loadbalance.py +++ b/vertica_python/tests/integration_tests/test_loadbalance.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonIntegrationTestCase diff --git a/vertica_python/tests/integration_tests/test_timezones.py b/vertica_python/tests/integration_tests/test_timezones.py index e853a599..4214dc9f 100644 --- a/vertica_python/tests/integration_tests/test_timezones.py +++ b/vertica_python/tests/integration_tests/test_timezones.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from collections import namedtuple from datetime import datetime diff --git a/vertica_python/tests/integration_tests/test_tls.py b/vertica_python/tests/integration_tests/test_tls.py index 2a0bb4af..135bc231 100644 --- a/vertica_python/tests/integration_tests/test_tls.py +++ b/vertica_python/tests/integration_tests/test_tls.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import os import socket diff --git a/vertica_python/tests/integration_tests/test_transfer_format.py b/vertica_python/tests/integration_tests/test_transfer_format.py index d6f9373d..e124ffcc 100644 --- a/vertica_python/tests/integration_tests/test_transfer_format.py +++ b/vertica_python/tests/integration_tests/test_transfer_format.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonIntegrationTestCase diff --git a/vertica_python/tests/integration_tests/test_unicode.py b/vertica_python/tests/integration_tests/test_unicode.py index 6225bad9..acc44db5 100644 --- a/vertica_python/tests/integration_tests/test_unicode.py +++ b/vertica_python/tests/integration_tests/test_unicode.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonIntegrationTestCase diff --git a/vertica_python/tests/unit_tests/base.py b/vertica_python/tests/unit_tests/base.py index b3d5fb1c..a60ff3c8 100644 --- a/vertica_python/tests/unit_tests/base.py +++ b/vertica_python/tests/unit_tests/base.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import pytest from ..common.base import VerticaPythonTestCase diff --git a/vertica_python/tests/unit_tests/test_errors.py b/vertica_python/tests/unit_tests/test_errors.py index 3907fc6a..9334d950 100644 --- a/vertica_python/tests/unit_tests/test_errors.py +++ b/vertica_python/tests/unit_tests/test_errors.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonUnitTestCase from ...errors import VerticaSyntaxError diff --git a/vertica_python/tests/unit_tests/test_logging.py b/vertica_python/tests/unit_tests/test_logging.py index ccab0e8f..7801c026 100644 --- a/vertica_python/tests/unit_tests/test_logging.py +++ b/vertica_python/tests/unit_tests/test_logging.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import logging import os diff --git a/vertica_python/tests/unit_tests/test_notice.py b/vertica_python/tests/unit_tests/test_notice.py index f078e61e..a1121509 100644 --- a/vertica_python/tests/unit_tests/test_notice.py +++ b/vertica_python/tests/unit_tests/test_notice.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import mock diff --git a/vertica_python/tests/unit_tests/test_parsedsn.py b/vertica_python/tests/unit_tests/test_parsedsn.py index 28e84ae3..dda09f8f 100644 --- a/vertica_python/tests/unit_tests/test_parsedsn.py +++ b/vertica_python/tests/unit_tests/test_parsedsn.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .base import VerticaPythonUnitTestCase from ...vertica.connection import parse_dsn diff --git a/vertica_python/tests/unit_tests/test_sql_literal.py b/vertica_python/tests/unit_tests/test_sql_literal.py index e850efc4..e5ee1a40 100644 --- a/vertica_python/tests/unit_tests/test_sql_literal.py +++ b/vertica_python/tests/unit_tests/test_sql_literal.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from collections import namedtuple from decimal import Decimal diff --git a/vertica_python/tests/unit_tests/test_timestamps.py b/vertica_python/tests/unit_tests/test_timestamps.py index 37c9e16d..246c9753 100644 --- a/vertica_python/tests/unit_tests/test_timestamps.py +++ b/vertica_python/tests/unit_tests/test_timestamps.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from collections import namedtuple from datetime import datetime diff --git a/vertica_python/vertica/column.py b/vertica_python/vertica/column.py index 305da015..0ecb4350 100644 --- a/vertica_python/vertica/column.py +++ b/vertica_python/vertica/column.py @@ -34,9 +34,11 @@ # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations -from collections import namedtuple +from typing import TYPE_CHECKING, NamedTuple +if TYPE_CHECKING: + from typing import Optional from ..datatypes import getDisplaySize, getPrecision, getScale from ..compat import as_str, as_text @@ -49,12 +51,18 @@ class FormatCode(object): BINARY = 1 -ColumnTuple = namedtuple('Column', ['name', 'type_code', 'display_size', 'internal_size', - 'precision', 'scale', 'null_ok']) +class ColumnTuple(NamedTuple): + name: str + type_code: int + display_size: Optional[int] + internal_size: int + precision: Optional[int] + scale: Optional[int] + null_ok: bool class Column(object): - def __init__(self, col): + def __init__(self, col) -> None: # Describe one query result column self.name = col['name'] self.type_code = col['data_type_oid'] @@ -74,7 +82,7 @@ def __init__(self, col): self.props = ColumnTuple(self.name, self.type_code, self.display_size, self.internal_size, self.precision, self.scale, self.null_ok) - def add_child_column(self, col): + def add_child_column(self, col: Column) -> None: """ Complex types involve multiple columns arranged in a hierarchy of parents and children. Each parent column stores references to child columns in a list. @@ -83,7 +91,7 @@ def add_child_column(self, col): self.child_columns = [] self.child_columns.append(col) - def debug_info(self): + def debug_info(self) -> str: childs = "" if self.child_columns: c = ", ".join([col.debug_info() for col in self.child_columns]) diff --git a/vertica_python/vertica/connection.py b/vertica_python/vertica/connection.py index 24ab5840..aaeeaf44 100644 --- a/vertica_python/vertica/connection.py +++ b/vertica_python/vertica/connection.py @@ -633,7 +633,7 @@ def ssl(self) -> bool: """Returns True if the TCP socket is a SSL socket.""" return self.socket is not None and isinstance(self.socket, ssl.SSLSocket) - def write(self, message, vsocket=None) -> None: + def write(self, message: FrontendMessage, vsocket: Optional[Union[socket.socket, ssl.SSLSocket]] = None) -> None: if not isinstance(message, FrontendMessage): raise TypeError("invalid message: ({0})".format(message)) if vsocket is None: @@ -670,14 +670,14 @@ def reset_connection(self) -> None: self.close() self.startup_connection() - def is_asynchronous_message(self, message) -> bool: + def is_asynchronous_message(self, message: BackendMessage) -> bool: # Check if it is an asynchronous response message # Note: ErrorResponse is a subclass of NoticeResponse return (isinstance(message, messages.ParameterStatus) or (isinstance(message, messages.NoticeResponse) and not isinstance(message, messages.ErrorResponse))) - def handle_asynchronous_message(self, message) -> None: + def handle_asynchronous_message(self, message: Union[messages.ParameterStatus, messages.NoticeResponse]) -> None: if isinstance(message, messages.ParameterStatus): if message.name == 'protocol_version': message.value = int(message.value) @@ -700,7 +700,7 @@ def read_string(self) -> bytearray: s.extend(char) return s - def read_message(self): + def read_message(self) -> BackendMessage: while True: try: type_ = self.read_bytes(1) diff --git a/vertica_python/vertica/cursor.py b/vertica_python/vertica/cursor.py index e1c45347..f67a5644 100644 --- a/vertica_python/vertica/cursor.py +++ b/vertica_python/vertica/cursor.py @@ -60,7 +60,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import IO, Any, AnyStr, Callable, Dict, Generator, List, Optional, Sequence, Tuple, Type, TypeVar, Union + from typing import IO, Any, AnyStr, Callable, Dict, Generator, List, NoReturn, Optional, Sequence, Tuple, Type, TypeVar, Union from typing_extensions import Self from .connection import Connection from logging import Logger @@ -71,6 +71,7 @@ from ..vertica import messages from ..vertica.column import Column from ..vertica.deserializer import Deserializer +from ..vertica.messages.message import BackendMessage # A note regarding support for temporary files: @@ -169,8 +170,7 @@ def __init__(self, ############################################# # supporting `with` statements ############################################# - def __enter__(self): - # type: () -> Self + def __enter__(self) -> Self: return self def __exit__(self, type_, value, traceback): @@ -196,19 +196,23 @@ def wrap(self, *args, **kwargs): # dbapi methods ############################################# # noinspection PyMethodMayBeStatic - def callproc(self, procname, parameters=None): + def callproc(self, procname, parameters=None) -> NoReturn: raise errors.NotSupportedError('Cursor.callproc() is not implemented') - def close(self): + def close(self) -> None: + """Close the cursor now.""" self._logger.info('Close the cursor') if not self.closed() and self.prepared_sql: self._close_prepared_statement() self._closed = True @handle_ctrl_c - def execute(self, operation, parameters=None, use_prepared_statements=None, - copy_stdin=None, buffer_size=DEFAULT_BUFFER_SIZE): - # type: (str, Optional[Union[List[Any], Tuple[Any], Dict[str, Any]]], Optional[bool], Optional[Union[IO[AnyStr], List[IO[AnyStr]]]], int) -> Self + def execute(self, operation: str, + parameters: Optional[Union[List[Any], Tuple[Any], Dict[str, Any]]] = None, + use_prepared_statements: Optional[bool] = None, + copy_stdin: Optional[Union[IO[AnyStr], List[IO[AnyStr]]]] = None, + buffer_size: int = DEFAULT_BUFFER_SIZE) -> Self: + """Execute a query or command to the database.""" if self.closed(): raise errors.InterfaceError('Cursor is closed') @@ -264,8 +268,11 @@ def execute(self, operation, parameters=None, use_prepared_statements=None, return self @handle_ctrl_c - def executemany(self, operation, seq_of_parameters, use_prepared_statements=None): - # type: (str, Sequence[Union[List[Any], Tuple[Any], Dict[str, Any]]], Optional[bool]) -> None + def executemany(self, + operation: str, + seq_of_parameters: Sequence[Union[List[Any], Tuple[Any], Dict[str, Any]]], + use_prepared_statements: Optional[bool] = None) -> None: + """Execute the same command with a sequence of input data.""" if not isinstance(seq_of_parameters, (list, tuple)): raise TypeError("seq_of_parameters should be list/tuple") @@ -324,8 +331,8 @@ def executemany(self, operation, seq_of_parameters, use_prepared_statements=None raise NotImplementedError( "executemany is implemented for simple INSERT statements only") - def fetchone(self): - # type: () -> Optional[Union[List[Any], OrderedDict[str, Any]]] + def fetchone(self) -> Optional[Union[List[Any], OrderedDict[str, Any]]]: + """Return the next record from the current statement result set.""" while True: if isinstance(self._message, messages.DataRow): if self.rowcount == -1: @@ -359,8 +366,10 @@ def fetchone(self): self._message = self.connection.read_message() - def fetchmany(self, size=None): - # type: (Optional[int]) -> List[Union[List[Any], OrderedDict[str, Any]]] + def fetchmany(self, size: Optional[int] = None) -> List[Union[List[Any], OrderedDict[str, Any]]]: + """Return the next `size` records from the current statement result set. + `size` default to `cursor.arraysize` if not specified. + """ if not size: size = self.arraysize results = [] @@ -373,11 +382,11 @@ def fetchmany(self, size=None): break return results - def fetchall(self): + def fetchall(self) -> List[Union[List[Any], OrderedDict[str, Any]]]: + """Return all the remaining records from the current statement result set.""" return list(self.iterate()) - def nextset(self): - # type: () -> bool + def nextset(self) -> bool: """ Skip to the next available result set, discarding any remaining rows from the current result set. @@ -427,35 +436,38 @@ def nextset(self): else: raise errors.MessageError('Unexpected nextset() state: {0}'.format(self._message)) - def setinputsizes(self, sizes): + def setinputsizes(self, sizes) -> None: pass - def setoutputsize(self, size, column=None): + def setoutputsize(self, size, column=None) -> None: pass ############################################# # non-dbapi methods ############################################# def closed(self) -> bool: + """Returns True if the cursor is closed.""" return self._closed or self.connection.closed() - def cancel(self): - # Cancel is a session-level operation, cursor-level API does not make - # sense. Keep this API for backward compatibility. + def cancel(self) -> NoReturn: + """Cancel is a session-level operation, cursor-level API does not make + sense. Keep this API for backward compatibility. + """ raise errors.NotSupportedError( 'Cursor.cancel() is deprecated. Call Connection.cancel() ' 'to cancel the current database operation.') - def iterate(self): - # type: () -> Generator[Union[List[Any], OrderedDict[str, Any]], None, None] + def iterate(self) -> Generator[Union[List[Any], OrderedDict[str, Any]], None, None]: + """Yield the next record from the current statement result set.""" row = self.fetchone() while row: yield row row = self.fetchone() - def copy(self, sql, data, **kwargs): - # type: (str, IO[AnyStr], Any) -> None + def copy(self, sql: str, data: IO[AnyStr], **kwargs: Any) -> None: """ + Execute a "COPY FROM STDIN" SQL. + EXAMPLE: ``` >> with open("/tmp/file.csv", "rb") as fs: @@ -519,28 +531,30 @@ def copy(self, sql, data, **kwargs): if self.error is not None: raise self.error - def object_to_sql_literal(self, py_obj): + def object_to_sql_literal(self, py_obj: Any) -> str: + """Returns the SQL literal string converted from a Python object.""" return self.object_to_string(py_obj, False) - def register_sql_literal_adapter(self, obj_type, adapter_func): - # type: (T, Callable[[T], str]) -> None + def register_sql_literal_adapter(self, obj_type: T, adapter_func: Callable[[T], str]) -> None: + """Register a sql literal adapter, which adapt a Python type/class to SQL literals.""" if not callable(adapter_func): raise TypeError("Cannot register this sql literal adapter. The adapter is not callable.") self._sql_literal_adapters[obj_type] = adapter_func @property - def disable_sqldata_converter(self): + def disable_sqldata_converter(self) -> bool: return self._disable_sqldata_converter @disable_sqldata_converter.setter - def disable_sqldata_converter(self, value): + def disable_sqldata_converter(self, value: bool) -> None: """By default, the client does data conversions for query results: reading a bytes sequence from server and creating a Python object out of it. - If set to True, bypass conversions from SQL type raw data to the native Python object + If set to True, bypass conversions from SQL type raw data to the native Python object. """ self._disable_sqldata_converter = bool(value) - def register_sqldata_converter(self, oid, converter_func): + def register_sqldata_converter(self, oid: int, converter_func: Callable[[bytes, Dict[str, Any]], Any]) -> None: + """Customize how SQL data values are converted to Python objects when query results are returned.""" if not isinstance(oid, int): raise TypeError(f"sqldata converters should be registered on oid integer, got {oid} instead.") @@ -552,7 +566,8 @@ def register_sqldata_converter(self, oid, converter_func): # For prepared statements, need to reset self._deserializers if self.description: self._deserializers = self.get_deserializers() - def unregister_sqldata_converter(self, oid): + def unregister_sqldata_converter(self, oid: int) -> None: + """Cancel customized SQL data values converter and use the default converter.""" if oid in self._sqldata_converters: del self._sqldata_converters[oid] # For prepared statements, need to reset self._deserializers @@ -573,7 +588,7 @@ def get_deserializers(self): 'complex_types_enabled': self.connection.complex_types_enabled,} ) - def flush_to_query_ready(self): + def flush_to_query_ready(self) -> None: # if the last message isn't empty or ReadyForQuery, read all remaining messages if self._message is None \ or isinstance(self._message, messages.ReadyForQuery): @@ -588,7 +603,7 @@ def flush_to_query_ready(self): self._message = message self._handle_copy_local_protocol() - def flush_to_end_of_result(self): + def flush_to_end_of_result(self) -> None: # if the last message isn't empty or END_OF_RESULT_RESPONSES, # read messages until it is if (self._message is None or @@ -613,7 +628,7 @@ def row_formatter(self, row_data): else: raise TypeError('Unrecognized cursor_type: {0}'.format(self.cursor_type)) - def format_row_as_dict(self, row_data): + def format_row_as_dict(self, row_data) -> OrderedDict[str, Any]: if self._disable_sqldata_converter: return OrderedDict((descr.name, value) for descr, value in zip(self.description, row_data.values)) @@ -622,13 +637,13 @@ def format_row_as_dict(self, row_data): for descr, convert, value in zip(self.description, self._deserializers, row_data.values) ) - def format_row_as_array(self, row_data): + def format_row_as_array(self, row_data) -> List[Any]: if self._disable_sqldata_converter: return row_data.values return [convert(value) for convert, value in zip(self._deserializers, row_data.values)] - def object_to_string(self, py_obj, is_copy_data, is_collection=False): + def object_to_string(self, py_obj: Any, is_copy_data: bool, is_collection: bool = False) -> str: """Return the SQL representation of the object as a string""" if type(py_obj) in self._sql_literal_adapters and not is_copy_data: adapter = self._sql_literal_adapters[type(py_obj)] @@ -701,7 +716,7 @@ def object_to_string(self, py_obj, is_copy_data, is_collection=False): raise TypeError(msg) # noinspection PyArgumentList - def format_operation_with_parameters(self, operation, parameters, is_copy_data=False): + def format_operation_with_parameters(self, operation: str, parameters: Union[List[Any], Tuple[Any], Dict[str, Any]], is_copy_data: bool = False) -> str: if isinstance(parameters, dict): if parameters and ':' not in operation and os.environ.get('VERTICA_PYTHON_IGNORE_NAMED_PARAMETER_CHECK') != '1': raise ValueError(f'Invalid SQL: {operation}' @@ -735,7 +750,7 @@ def format_operation_with_parameters(self, operation, parameters, is_copy_data=F return operation - def format_quote(self, param, is_copy_data, is_collection): + def format_quote(self, param: str, is_copy_data: bool, is_collection: bool) -> str: if is_collection: # COPY COLLECTIONENCLOSE s = list(param) for i, c in enumerate(param): @@ -751,10 +766,9 @@ def format_quote(self, param, is_copy_data, is_collection): else: return u"'{0}'".format(param.replace(u"'", u"''")) - def _execute_simple_query(self, query): + def _execute_simple_query(self, query: str) -> None: """ Send the query to the server using the simple query protocol. - Return True if this query contained no SQL (e.g. the string "--comment") """ self._logger.info(u'Execute simple query: [{}]'.format(query)) @@ -763,7 +777,7 @@ def _execute_simple_query(self, query): # The first response could be a number of things: # ErrorResponse: Something went wrong on the server. - # EmptyQueryResponse: The query being executed is empty. + # EmptyQueryResponse: The query being executed is empty. (e.g. the string "--comment") # RowDescription: This is the "normal" case when executing a query. # It marks the start of the results. # CommandComplete: This occurs when executing DDL/transactions. @@ -779,7 +793,7 @@ def _execute_simple_query(self, query): elif isinstance(self._message, messages.VerifyFiles): self._handle_copy_local_protocol() - def _handle_copy_local_protocol(self): + def _handle_copy_local_protocol(self) -> None: if self.connection.options['disable_copy_local']: msg = 'COPY LOCAL operation is disabled.' self.connection.write(messages.CopyError(msg)) @@ -877,7 +891,7 @@ def _check_copy_local_files(self, input_files): # Note: Sending an empty list of files will make server kill the session. return file_list - def _send_copy_data(self, stream, buffer_size): + def _send_copy_data(self, stream, buffer_size) -> None: # Send zero or more CopyData messages, forming a stream of input data while True: chunk = stream.read(buffer_size) @@ -885,7 +899,7 @@ def _send_copy_data(self, stream, buffer_size): break self.connection.write(messages.CopyData(chunk, self.unicode_error)) - def _send_copy_file_data(self): + def _send_copy_file_data(self) -> None: filename = self._message.filename self._logger.info('Sending {} data to server'.format(filename)) @@ -897,7 +911,7 @@ def _send_copy_file_data(self): self._send_copy_data(f, self.buffer_size) self.connection.write(messages.EndOfBatchRequest()) - def _read_copy_data_response(self, is_stdin_copy: bool = False): + def _read_copy_data_response(self, is_stdin_copy: bool = False) -> bool: """Returns True if the server wants us to load more data, False if we are done.""" self._message = self.connection.read_expected_message(END_OF_BATCH_RESPONSES) # Check for rejections during this load @@ -932,11 +946,11 @@ def _read_copy_data_response(self, is_stdin_copy: bool = False): type(self._message).__name__)) return False - def _error_handler(self, msg): + def _error_handler(self, msg: BackendMessage) -> NoReturn: self.connection.write(messages.Sync()) raise errors.QueryError.from_error_response(msg, self.operation) - def _prepare(self, query): + def _prepare(self, query: str) -> None: """ Send the query to be prepared to the server. The server will parse the query and return some metadata. @@ -976,7 +990,7 @@ def _prepare(self, query): self._logger.info('Finish preparing the statement') - def _execute_prepared_statement(self, list_of_parameter_values): + def _execute_prepared_statement(self, list_of_parameter_values: Sequence[Any]) -> None: """ Send multiple statement parameter sets to the server using the extended query protocol. The server would bind and execute each set of parameter @@ -1021,7 +1035,7 @@ def _execute_prepared_statement(self, list_of_parameter_values): if isinstance(self._message, messages.ErrorResponse): raise errors.QueryError.from_error_response(self._message, self.prepared_sql) - def _close_prepared_statement(self): + def _close_prepared_statement(self) -> None: """ Close the prepared statement on the server. """ diff --git a/vertica_python/vertica/deserializer.py b/vertica_python/vertica/deserializer.py index 2d16e2fd..285011ae 100644 --- a/vertica_python/vertica/deserializer.py +++ b/vertica_python/vertica/deserializer.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import json import re @@ -23,6 +23,11 @@ from struct import unpack from uuid import UUID +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from typing import Any, Callable, Dict, List, Optional, Set, Union + from ..vertica.column import Column + from .. import errors from ..compat import as_str, as_bytes from ..datatypes import VerticaType @@ -30,14 +35,20 @@ class Deserializer(object): - def get_row_deserializers(self, columns, custom_converters, context): + def get_row_deserializers(self, + columns: List[Column], + custom_converters: Dict[int, Callable[[bytes, Dict[str, Any]], Any]], + context: Dict[str, Any]) -> List[Callable[[Optional[bytes]], Any]]: result = [None] * len(columns) for idx, col in enumerate(columns): result[idx] = self.get_column_deserializer(col, custom_converters, context) return result - def get_column_deserializer(self, col, custom_converters, context): - """Return a function that inputs a column's raw data and returns a Python object""" + def get_column_deserializer(self, + col: Column, + custom_converters: Dict[int, Callable[[bytes, Dict[str, Any]], Any]], + context: Dict[str, Any]) -> Callable[[Optional[bytes]], Any]: + """Return a function that inputs a column's raw data and returns a Python object.""" if col.type_code in custom_converters: f = custom_converters[col.type_code] else: @@ -45,7 +56,7 @@ def get_column_deserializer(self, col, custom_converters, context): if f is None: # skip conversion return lambda data: data - def deserializer(data): + def deserializer(data: Optional[bytes]): if data is None: # null return None return f(data, ctx={'column': col, **context}) @@ -64,7 +75,7 @@ def deserializer(data): TZ_RE = re.compile(r"(?ix) ^([-+]) (\d+) (?: : (\d+) )? (?: : (\d+) )? $") SECONDS_PER_DAY = 86400 -def load_bool_binary(val:bytes, ctx) -> bool: +def load_bool_binary(val: bytes, ctx: Dict[str, Any]) -> bool: """ Parses binary representation of a BOOLEAN type. :param val: a byte - b'\x01' for True, b'\x00' for False @@ -73,7 +84,7 @@ def load_bool_binary(val:bytes, ctx) -> bool: """ return val == b'\x01' -def load_int8_binary(val: bytes, ctx) -> int: +def load_int8_binary(val: bytes, ctx: Dict[str, Any]) -> int: """ Parses binary representation of a INTEGER type. :param val: bytes - a 64-bit integer. @@ -82,7 +93,7 @@ def load_int8_binary(val: bytes, ctx) -> int: """ return unpack("!q", val)[0] -def load_float8_binary(val: bytes, ctx) -> float: +def load_float8_binary(val: bytes, ctx: Dict[str, Any]) -> float: """ Parses binary representation of a FLOAT type. :param val: bytes - a float encoded in IEEE-754 format. @@ -91,7 +102,7 @@ def load_float8_binary(val: bytes, ctx) -> float: """ return unpack("!d", val)[0] -def load_numeric_binary(val: bytes, ctx) -> Decimal: +def load_numeric_binary(val: bytes, ctx: Dict[str, Any]) -> Decimal: """ Parses binary representation of a NUMERIC type. :param val: bytes @@ -106,7 +117,7 @@ def load_numeric_binary(val: bytes, ctx) -> Decimal: # The numeric value is (unscaledVal * 10^(-scale)) return Decimal(unscaledVal).scaleb(-scale, context=Context(prec=precision)) -def load_varchar_text(val: bytes, ctx) -> str: +def load_varchar_text(val: bytes, ctx: Dict[str, Any]) -> str: """ Parses text/binary representation of a CHAR / VARCHAR / LONG VARCHAR type. :param val: bytes @@ -115,7 +126,7 @@ def load_varchar_text(val: bytes, ctx) -> str: """ return val.decode('utf-8', ctx['unicode_error']) -def load_date_text(val: bytes, ctx) -> date: +def load_date_text(val: bytes, ctx: Dict[str, Any]) -> date: """ Parses text representation of a DATE type. :param val: bytes @@ -131,7 +142,7 @@ def load_date_text(val: bytes, ctx) -> date: except ValueError: raise errors.NotSupportedError('Dates after year 9999 are not supported by datetime.date. Got: {0}'.format(s)) -def load_date_binary(val: bytes, ctx) -> date: +def load_date_binary(val: bytes, ctx: Dict[str, Any]) -> date: """ Parses binary representation of a DATE type. :param val: bytes @@ -149,7 +160,7 @@ def load_date_binary(val: bytes, ctx) -> date: raise errors.NotSupportedError('Dates after year 9999 are not supported by datetime.date. Got: Julian day number {0}'.format(jdn)) return date.fromordinal(days) -def load_time_text(val: bytes, ctx) -> time: +def load_time_text(val: bytes, ctx: Dict[str, Any]) -> time: """ Parses text representation of a TIME type. :param val: bytes @@ -161,7 +172,7 @@ def load_time_text(val: bytes, ctx) -> time: return datetime.strptime(val, '%H:%M:%S').time() return datetime.strptime(val, '%H:%M:%S.%f').time() -def load_time_binary(val: bytes, ctx) -> time: +def load_time_binary(val: bytes, ctx: Dict[str, Any]) -> time: """ Parses binary representation of a TIME type. :param val: bytes @@ -180,7 +191,7 @@ def load_time_binary(val: bytes, ctx) -> time: except ValueError: raise errors.NotSupportedError("Time not supported by datetime.time. Got: hour={}".format(hour)) -def load_timetz_text(val: bytes, ctx) -> time: +def load_timetz_text(val: bytes, ctx: Dict[str, Any]) -> time: """ Parses text representation of a TIMETZ type. :param val: bytes @@ -212,7 +223,7 @@ def load_timetz_text(val: bytes, ctx) -> time: return time(int(hr), int(mi), int(sec), us, tz.tzoffset(None, tz_offset)) -def load_timetz_binary(val: bytes, ctx) -> time: +def load_timetz_binary(val: bytes, ctx: Dict[str, Any]) -> time: """ Parses binary representation of a TIMETZ type. :param val: bytes @@ -223,7 +234,7 @@ def load_timetz_binary(val: bytes, ctx) -> time: # - Upper 40 bits contain the number of microseconds since midnight in the UTC time zone. # - Lower 24 bits contain time zone as the UTC offset in seconds. v = load_int8_binary(val, ctx) - tz_offset = SECONDS_PER_DAY - (v & 0xffffff) # in seconds + tz_offset = SECONDS_PER_DAY - (v & 0xffffff) # in seconds msecs = v >> 24 # shift to given time zone msecs += tz_offset * 1000000 @@ -233,7 +244,7 @@ def load_timetz_binary(val: bytes, ctx) -> time: hour, minute = divmod(msecs, 60) return time(hour, minute, second, fraction, tz.tzoffset(None, tz_offset)) -def load_timestamp_text(val: bytes, ctx) -> datetime: +def load_timestamp_text(val: bytes, ctx: Dict[str, Any]) -> datetime: """ Parses text representation of a TIMESTAMP type. :param val: bytes @@ -249,7 +260,7 @@ def load_timestamp_text(val: bytes, ctx) -> datetime: except ValueError: raise errors.NotSupportedError('Timestamps after year 9999 are not supported by datetime.datetime. Got: {0}'.format(s)) -def load_timestamp_binary(val: bytes, ctx) -> datetime: +def load_timestamp_binary(val: bytes, ctx: Dict[str, Any]) -> datetime: """ Parses binary representation of a TIMESTAMP type. :param val: bytes @@ -267,7 +278,7 @@ def load_timestamp_binary(val: bytes, ctx) -> datetime: else: raise errors.NotSupportedError('Timestamps after year 9999 are not supported by datetime.datetime.') -def load_timestamptz_text(val: bytes, ctx) -> datetime: +def load_timestamptz_text(val: bytes, ctx: Dict[str, Any]) -> datetime: """ Parses text representation of a TIMESTAMPTZ type. :param val: bytes @@ -287,7 +298,7 @@ def load_timestamptz_text(val: bytes, ctx) -> datetime: t = load_timetz_text(dt[1], ctx) return datetime.combine(d, t) -def load_timestamptz_binary(val: bytes, ctx) -> datetime: +def load_timestamptz_binary(val: bytes, ctx: Dict[str, Any]) -> datetime: """ Parses binary representation of a TIMESTAMPTZ type. :param val: bytes @@ -312,7 +323,7 @@ def load_timestamptz_binary(val: bytes, ctx) -> datetime: else: # year might be over 9999 raise errors.NotSupportedError('TimestampTzs after year 9999 are not supported by datetime.datetime.') -def load_interval_text(val: bytes, ctx) -> relativedelta: +def load_interval_text(val: bytes, ctx: Dict[str, Any]) -> relativedelta: """ Parses text representation of a INTERVAL day-time type. :param val: bytes @@ -361,7 +372,7 @@ def load_interval_text(val: bytes, ctx) -> relativedelta: return relativedelta(days=parts[0], hours=parts[1], minutes=parts[2], seconds=parts[3], microseconds=parts[4]) -def load_interval_binary(val: bytes, ctx) -> relativedelta: +def load_interval_binary(val: bytes, ctx: Dict[str, Any]) -> relativedelta: """ Parses binary representation of a INTERVAL day-time type. :param val: bytes @@ -372,7 +383,7 @@ def load_interval_binary(val: bytes, ctx) -> relativedelta: msecs = load_int8_binary(val, ctx) return relativedelta(microseconds=msecs) -def load_intervalYM_text(val: bytes, ctx) -> relativedelta: +def load_intervalYM_text(val: bytes, ctx: Dict[str, Any]) -> relativedelta: """ Parses text representation of a INTERVAL YEAR TO MONTH / INTERVAL YEAR / INTERVAL MONTH type. :param val: bytes @@ -398,7 +409,7 @@ def load_intervalYM_text(val: bytes, ctx) -> relativedelta: else: # Interval Month return relativedelta(months=interval) -def load_intervalYM_binary(val: bytes, ctx) -> relativedelta: +def load_intervalYM_binary(val: bytes, ctx: Dict[str, Any]) -> relativedelta: """ Parses binary representation of a INTERVAL YEAR TO MONTH / INTERVAL YEAR / INTERVAL MONTH type. :param val: bytes @@ -409,7 +420,7 @@ def load_intervalYM_binary(val: bytes, ctx) -> relativedelta: months = load_int8_binary(val, ctx) return relativedelta(months=months) -def load_uuid_binary(val: bytes, ctx) -> UUID: +def load_uuid_binary(val: bytes, ctx: Dict[str, Any]) -> UUID: """ Parses binary representation of a UUID type. :param val: bytes @@ -419,7 +430,7 @@ def load_uuid_binary(val: bytes, ctx) -> UUID: # 16-byte value in big-endian order interpreted as UUID return UUID(bytes=bytes(val)) -def load_varbinary_text(s: bytes, ctx) -> bytes: +def load_varbinary_text(s: bytes, ctx: Dict[str, Any]) -> bytes: """ Parses text representation of a BINARY / VARBINARY / LONG VARBINARY type. :param s: bytes @@ -443,7 +454,7 @@ def load_varbinary_text(s: bytes, ctx) -> bytes: buf.append(c) return b''.join(buf) -def load_array_text(val: bytes, ctx): +def load_array_text(val: bytes, ctx: Dict[str, Any]) -> Union[str, List[Any]]: """ Parses text/binary representation of an ARRAY type. :param val: bytes @@ -457,7 +468,7 @@ def load_array_text(val: bytes, ctx): json_data = json.loads(v) return parse_array(json_data, ctx) -def load_set_text(val: bytes, ctx): +def load_set_text(val: bytes, ctx: Dict[str, Any]) -> Set[Any]: """ Parses text/binary representation of a SET type. :param val: bytes @@ -466,7 +477,7 @@ def load_set_text(val: bytes, ctx): """ return set(load_array_text(val, ctx)) -def parse_array(json_data, ctx): +def parse_array(json_data: List[Any], ctx: Dict[str, Any]) -> List[Any]: if not isinstance(json_data, list): raise TypeError('Expected a list, got {}'.format(json_data)) # An array has only one child, all elements in the array are the same type. @@ -485,7 +496,7 @@ def parse_array(json_data, ctx): parsed_array[idx] = parse_json_element(element, child_ctx) return parsed_array -def load_row_text(val: bytes, ctx): +def load_row_text(val: bytes, ctx: Dict[str, Any]) -> Union[str, Dict[str, Any]]: """ Parses text/binary representation of a ROW type. :param val: bytes @@ -499,7 +510,7 @@ def load_row_text(val: bytes, ctx): json_data = json.loads(v) return parse_row(json_data, ctx) -def parse_row(json_data, ctx): +def parse_row(json_data: Dict[str, Any], ctx: Dict[str, Any]) -> Dict[str, Any]: if not isinstance(json_data, dict): raise TypeError('Expected a dict, got {}'.format(json_data)) # A row has one or more child fields @@ -520,7 +531,7 @@ def parse_row(json_data, ctx): parsed_row[key] = parse_json_element(element, child_ctx) return parsed_row -def parse_json_element(element, ctx): +def parse_json_element(element: Any, ctx: Dict[str, Any]) -> Any: type_code = ctx['column'].type_code if type_code in (VerticaType.BOOL, VerticaType.INT8, VerticaType.CHAR, VerticaType.VARCHAR, VerticaType.LONGVARCHAR): diff --git a/vertica_python/vertica/log.py b/vertica_python/vertica/log.py index 843eeecc..6369891c 100644 --- a/vertica_python/vertica/log.py +++ b/vertica_python/vertica/log.py @@ -34,10 +34,12 @@ # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import logging -from typing import Union +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from typing import Union from ..os_utils import ensure_dir_exists class VerticaLogging(object): diff --git a/vertica_python/vertica/messages/__init__.py b/vertica_python/vertica/messages/__init__.py index e246e361..88c63cb2 100644 --- a/vertica_python/vertica/messages/__init__.py +++ b/vertica_python/vertica/messages/__init__.py @@ -34,7 +34,7 @@ # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..messages import backend_messages from ..messages.backend_messages import * diff --git a/vertica_python/vertica/messages/backend_messages/__init__.py b/vertica_python/vertica/messages/backend_messages/__init__.py index e818d455..53ce0ae2 100644 --- a/vertica_python/vertica/messages/backend_messages/__init__.py +++ b/vertica_python/vertica/messages/backend_messages/__init__.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .authentication import Authentication from .backend_key_data import BackendKeyData diff --git a/vertica_python/vertica/messages/backend_messages/authentication.py b/vertica_python/vertica/messages/backend_messages/authentication.py index 93a631ac..f1f8cbc0 100644 --- a/vertica_python/vertica/messages/backend_messages/authentication.py +++ b/vertica_python/vertica/messages/backend_messages/authentication.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/backend_key_data.py b/vertica_python/vertica/messages/backend_messages/backend_key_data.py index 668222b7..ba950d22 100644 --- a/vertica_python/vertica/messages/backend_messages/backend_key_data.py +++ b/vertica_python/vertica/messages/backend_messages/backend_key_data.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/bind_complete.py b/vertica_python/vertica/messages/backend_messages/bind_complete.py index 9ec3d3ba..50dea5f7 100644 --- a/vertica_python/vertica/messages/backend_messages/bind_complete.py +++ b/vertica_python/vertica/messages/backend_messages/bind_complete.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/close_complete.py b/vertica_python/vertica/messages/backend_messages/close_complete.py index d9d7afa2..739b59f0 100644 --- a/vertica_python/vertica/messages/backend_messages/close_complete.py +++ b/vertica_python/vertica/messages/backend_messages/close_complete.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/command_complete.py b/vertica_python/vertica/messages/backend_messages/command_complete.py index 405462a1..68029e58 100644 --- a/vertica_python/vertica/messages/backend_messages/command_complete.py +++ b/vertica_python/vertica/messages/backend_messages/command_complete.py @@ -40,7 +40,7 @@ string is the name of the command that was run. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import re import warnings diff --git a/vertica_python/vertica/messages/backend_messages/command_description.py b/vertica_python/vertica/messages/backend_messages/command_description.py index cff5f550..3dbe7a54 100644 --- a/vertica_python/vertica/messages/backend_messages/command_description.py +++ b/vertica_python/vertica/messages/backend_messages/command_description.py @@ -43,7 +43,7 @@ batches of parameters. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/copy_done_response.py b/vertica_python/vertica/messages/backend_messages/copy_done_response.py index 35d822b9..838549e0 100644 --- a/vertica_python/vertica/messages/backend_messages/copy_done_response.py +++ b/vertica_python/vertica/messages/backend_messages/copy_done_response.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/copy_in_response.py b/vertica_python/vertica/messages/backend_messages/copy_in_response.py index 4a5b5739..37e325bd 100644 --- a/vertica_python/vertica/messages/backend_messages/copy_in_response.py +++ b/vertica_python/vertica/messages/backend_messages/copy_in_response.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/data_row.py b/vertica_python/vertica/messages/backend_messages/data_row.py index 71aece16..e841e852 100644 --- a/vertica_python/vertica/messages/backend_messages/data_row.py +++ b/vertica_python/vertica/messages/backend_messages/data_row.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack_from diff --git a/vertica_python/vertica/messages/backend_messages/empty_query_response.py b/vertica_python/vertica/messages/backend_messages/empty_query_response.py index 3a01ddc9..54dfb37b 100644 --- a/vertica_python/vertica/messages/backend_messages/empty_query_response.py +++ b/vertica_python/vertica/messages/backend_messages/empty_query_response.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/end_of_batch_response.py b/vertica_python/vertica/messages/backend_messages/end_of_batch_response.py index 0ddaa790..280033d8 100644 --- a/vertica_python/vertica/messages/backend_messages/end_of_batch_response.py +++ b/vertica_python/vertica/messages/backend_messages/end_of_batch_response.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/error_response.py b/vertica_python/vertica/messages/backend_messages/error_response.py index cc216183..09020ba6 100644 --- a/vertica_python/vertica/messages/backend_messages/error_response.py +++ b/vertica_python/vertica/messages/backend_messages/error_response.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage from vertica_python.vertica.messages.backend_messages.notice_response import NoticeResponse diff --git a/vertica_python/vertica/messages/backend_messages/load_balance_response.py b/vertica_python/vertica/messages/backend_messages/load_balance_response.py index ea3e988d..f57981a6 100644 --- a/vertica_python/vertica/messages/backend_messages/load_balance_response.py +++ b/vertica_python/vertica/messages/backend_messages/load_balance_response.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/load_file.py b/vertica_python/vertica/messages/backend_messages/load_file.py index 171e6d5f..fc81df4b 100644 --- a/vertica_python/vertica/messages/backend_messages/load_file.py +++ b/vertica_python/vertica/messages/backend_messages/load_file.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/no_data.py b/vertica_python/vertica/messages/backend_messages/no_data.py index 2c2978b9..9cf9ec80 100644 --- a/vertica_python/vertica/messages/backend_messages/no_data.py +++ b/vertica_python/vertica/messages/backend_messages/no_data.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/notice_response.py b/vertica_python/vertica/messages/backend_messages/notice_response.py index 9c7e5f97..2c93ee5e 100644 --- a/vertica_python/vertica/messages/backend_messages/notice_response.py +++ b/vertica_python/vertica/messages/backend_messages/notice_response.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack_from diff --git a/vertica_python/vertica/messages/backend_messages/parameter_description.py b/vertica_python/vertica/messages/backend_messages/parameter_description.py index ea15e52d..8e921ecb 100644 --- a/vertica_python/vertica/messages/backend_messages/parameter_description.py +++ b/vertica_python/vertica/messages/backend_messages/parameter_description.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack, unpack_from, calcsize diff --git a/vertica_python/vertica/messages/backend_messages/parameter_status.py b/vertica_python/vertica/messages/backend_messages/parameter_status.py index 70b10055..e38bf13f 100644 --- a/vertica_python/vertica/messages/backend_messages/parameter_status.py +++ b/vertica_python/vertica/messages/backend_messages/parameter_status.py @@ -50,7 +50,7 @@ about. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/parse_complete.py b/vertica_python/vertica/messages/backend_messages/parse_complete.py index 1e68f64c..00fb29ac 100644 --- a/vertica_python/vertica/messages/backend_messages/parse_complete.py +++ b/vertica_python/vertica/messages/backend_messages/parse_complete.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/portal_suspended.py b/vertica_python/vertica/messages/backend_messages/portal_suspended.py index 0ff07d34..df7a160b 100644 --- a/vertica_python/vertica/messages/backend_messages/portal_suspended.py +++ b/vertica_python/vertica/messages/backend_messages/portal_suspended.py @@ -47,7 +47,7 @@ intended by Postgres. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/ready_for_query.py b/vertica_python/vertica/messages/backend_messages/ready_for_query.py index ab9cc655..4b25e516 100644 --- a/vertica_python/vertica/messages/backend_messages/ready_for_query.py +++ b/vertica_python/vertica/messages/backend_messages/ready_for_query.py @@ -41,7 +41,7 @@ command cycle. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack diff --git a/vertica_python/vertica/messages/backend_messages/row_description.py b/vertica_python/vertica/messages/backend_messages/row_description.py index 976f1f47..74cf9e8f 100644 --- a/vertica_python/vertica/messages/backend_messages/row_description.py +++ b/vertica_python/vertica/messages/backend_messages/row_description.py @@ -40,8 +40,11 @@ returned in response to a SELECT, FETCH, etc query. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from typing import List from struct import unpack, unpack_from, calcsize from ..message import BackendMessage @@ -144,7 +147,7 @@ def __init__(self, data, complex_types_enabled): child_column = Column(metadata) column.add_child_column(child_column) - def get_description(self): + def get_description(self) -> List[Column]: # return a list of Column objects for Cursor.description return self.fields diff --git a/vertica_python/vertica/messages/backend_messages/unknown.py b/vertica_python/vertica/messages/backend_messages/unknown.py index 69b2564c..24d28db9 100644 --- a/vertica_python/vertica/messages/backend_messages/unknown.py +++ b/vertica_python/vertica/messages/backend_messages/unknown.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BackendMessage diff --git a/vertica_python/vertica/messages/backend_messages/verify_files.py b/vertica_python/vertica/messages/backend_messages/verify_files.py index 3fff0fed..e6ab1981 100644 --- a/vertica_python/vertica/messages/backend_messages/verify_files.py +++ b/vertica_python/vertica/messages/backend_messages/verify_files.py @@ -23,7 +23,7 @@ before running the copy. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack_from diff --git a/vertica_python/vertica/messages/backend_messages/write_file.py b/vertica_python/vertica/messages/backend_messages/write_file.py index ee9ab192..ccc3f9bc 100644 --- a/vertica_python/vertica/messages/backend_messages/write_file.py +++ b/vertica_python/vertica/messages/backend_messages/write_file.py @@ -24,7 +24,7 @@ saying which rows in the load were rejected. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import unpack_from diff --git a/vertica_python/vertica/messages/frontend_messages/__init__.py b/vertica_python/vertica/messages/frontend_messages/__init__.py index d36d7676..64757237 100644 --- a/vertica_python/vertica/messages/frontend_messages/__init__.py +++ b/vertica_python/vertica/messages/frontend_messages/__init__.py @@ -34,7 +34,7 @@ # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from .bind import Bind from .cancel_request import CancelRequest diff --git a/vertica_python/vertica/messages/frontend_messages/bind.py b/vertica_python/vertica/messages/frontend_messages/bind.py index 01e1b24f..33feb516 100644 --- a/vertica_python/vertica/messages/frontend_messages/bind.py +++ b/vertica_python/vertica/messages/frontend_messages/bind.py @@ -42,7 +42,7 @@ The response is either BindComplete or ErrorResponse. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack @@ -57,8 +57,8 @@ class Bind(BulkFrontendMessage): message_id = b'B' - def __init__(self, portal_name, prepared_statement_name, parameter_values, - parameter_type_oids, binary_transfer): + def __init__(self, portal_name: str, prepared_statement_name: str, parameter_values, + parameter_type_oids, binary_transfer: bool) -> None: BulkFrontendMessage.__init__(self) self._portal_name = portal_name self._prepared_statement_name = prepared_statement_name diff --git a/vertica_python/vertica/messages/frontend_messages/cancel_request.py b/vertica_python/vertica/messages/frontend_messages/cancel_request.py index 783769f1..9e812a6c 100644 --- a/vertica_python/vertica/messages/frontend_messages/cancel_request.py +++ b/vertica_python/vertica/messages/frontend_messages/cancel_request.py @@ -46,7 +46,7 @@ then there will be no visible result at all. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/close.py b/vertica_python/vertica/messages/frontend_messages/close.py index 67c11fda..70dd6ce0 100644 --- a/vertica_python/vertica/messages/frontend_messages/close.py +++ b/vertica_python/vertica/messages/frontend_messages/close.py @@ -43,7 +43,7 @@ issue Close against a nonexistent statement or portal name. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/copy_data.py b/vertica_python/vertica/messages/frontend_messages/copy_data.py index 2a07cd38..4974bb08 100644 --- a/vertica_python/vertica/messages/frontend_messages/copy_data.py +++ b/vertica_python/vertica/messages/frontend_messages/copy_data.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BulkFrontendMessage diff --git a/vertica_python/vertica/messages/frontend_messages/copy_done.py b/vertica_python/vertica/messages/frontend_messages/copy_done.py index 59ce1313..95abeef1 100644 --- a/vertica_python/vertica/messages/frontend_messages/copy_done.py +++ b/vertica_python/vertica/messages/frontend_messages/copy_done.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BulkFrontendMessage diff --git a/vertica_python/vertica/messages/frontend_messages/copy_error.py b/vertica_python/vertica/messages/frontend_messages/copy_error.py index e0bf5dc9..45ad49aa 100644 --- a/vertica_python/vertica/messages/frontend_messages/copy_error.py +++ b/vertica_python/vertica/messages/frontend_messages/copy_error.py @@ -19,7 +19,7 @@ CopyError message, which will cause the COPY SQL statement to fail with an error. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/copy_fail.py b/vertica_python/vertica/messages/frontend_messages/copy_fail.py index afb5804b..c479e6f1 100644 --- a/vertica_python/vertica/messages/frontend_messages/copy_fail.py +++ b/vertica_python/vertica/messages/frontend_messages/copy_fail.py @@ -40,7 +40,7 @@ CopyFail message, which will cause the COPY SQL statement to fail with an error. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/crypt_windows.py b/vertica_python/vertica/messages/frontend_messages/crypt_windows.py index 897bd70d..928375d9 100755 --- a/vertica_python/vertica/messages/frontend_messages/crypt_windows.py +++ b/vertica_python/vertica/messages/frontend_messages/crypt_windows.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations # Initial permutation IP = ( diff --git a/vertica_python/vertica/messages/frontend_messages/describe.py b/vertica_python/vertica/messages/frontend_messages/describe.py index bfb13a7b..bd214fc6 100644 --- a/vertica_python/vertica/messages/frontend_messages/describe.py +++ b/vertica_python/vertica/messages/frontend_messages/describe.py @@ -47,7 +47,7 @@ executed and any semantically-equivalent COPY statement. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/end_of_batch_request.py b/vertica_python/vertica/messages/frontend_messages/end_of_batch_request.py index 604cafb7..049ed80f 100644 --- a/vertica_python/vertica/messages/frontend_messages/end_of_batch_request.py +++ b/vertica_python/vertica/messages/frontend_messages/end_of_batch_request.py @@ -21,7 +21,7 @@ descriptions from the backend. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BulkFrontendMessage diff --git a/vertica_python/vertica/messages/frontend_messages/execute.py b/vertica_python/vertica/messages/frontend_messages/execute.py index eff4f7c3..6e803ba1 100644 --- a/vertica_python/vertica/messages/frontend_messages/execute.py +++ b/vertica_python/vertica/messages/frontend_messages/execute.py @@ -46,7 +46,7 @@ rows regardless of what you put here. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/flush.py b/vertica_python/vertica/messages/frontend_messages/flush.py index 38c3f827..d856e343 100644 --- a/vertica_python/vertica/messages/frontend_messages/flush.py +++ b/vertica_python/vertica/messages/frontend_messages/flush.py @@ -43,7 +43,7 @@ command before issuing more commands. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BulkFrontendMessage diff --git a/vertica_python/vertica/messages/frontend_messages/load_balance_request.py b/vertica_python/vertica/messages/frontend_messages/load_balance_request.py index 9b4c85b3..26f275d1 100755 --- a/vertica_python/vertica/messages/frontend_messages/load_balance_request.py +++ b/vertica_python/vertica/messages/frontend_messages/load_balance_request.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/parse.py b/vertica_python/vertica/messages/frontend_messages/parse.py index f8e01951..9d7dae82 100644 --- a/vertica_python/vertica/messages/frontend_messages/parse.py +++ b/vertica_python/vertica/messages/frontend_messages/parse.py @@ -46,7 +46,7 @@ "Cannot insert multiple commands into a prepared statement" """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/password.py b/vertica_python/vertica/messages/frontend_messages/password.py index ee248b24..017a40cd 100644 --- a/vertica_python/vertica/messages/frontend_messages/password.py +++ b/vertica_python/vertica/messages/frontend_messages/password.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import os import hashlib diff --git a/vertica_python/vertica/messages/frontend_messages/query.py b/vertica_python/vertica/messages/frontend_messages/query.py index 52712d34..783aec9a 100644 --- a/vertica_python/vertica/messages/frontend_messages/query.py +++ b/vertica_python/vertica/messages/frontend_messages/query.py @@ -42,7 +42,7 @@ string, and finally a ReadyForQuery message. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/ssl_request.py b/vertica_python/vertica/messages/frontend_messages/ssl_request.py index 2fac769f..51151047 100644 --- a/vertica_python/vertica/messages/frontend_messages/ssl_request.py +++ b/vertica_python/vertica/messages/frontend_messages/ssl_request.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from struct import pack diff --git a/vertica_python/vertica/messages/frontend_messages/startup.py b/vertica_python/vertica/messages/frontend_messages/startup.py index 4ba4d8c0..76993bda 100644 --- a/vertica_python/vertica/messages/frontend_messages/startup.py +++ b/vertica_python/vertica/messages/frontend_messages/startup.py @@ -40,7 +40,7 @@ Startup message. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import platform import os diff --git a/vertica_python/vertica/messages/frontend_messages/sync.py b/vertica_python/vertica/messages/frontend_messages/sync.py index 69bcd097..51d230fd 100644 --- a/vertica_python/vertica/messages/frontend_messages/sync.py +++ b/vertica_python/vertica/messages/frontend_messages/sync.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BulkFrontendMessage diff --git a/vertica_python/vertica/messages/frontend_messages/terminate.py b/vertica_python/vertica/messages/frontend_messages/terminate.py index b26f5a04..0b422a43 100644 --- a/vertica_python/vertica/messages/frontend_messages/terminate.py +++ b/vertica_python/vertica/messages/frontend_messages/terminate.py @@ -33,7 +33,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from ..message import BulkFrontendMessage diff --git a/vertica_python/vertica/messages/frontend_messages/verified_files.py b/vertica_python/vertica/messages/frontend_messages/verified_files.py index 163874be..878c3497 100644 --- a/vertica_python/vertica/messages/frontend_messages/verified_files.py +++ b/vertica_python/vertica/messages/frontend_messages/verified_files.py @@ -13,7 +13,7 @@ # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations import os from struct import pack diff --git a/vertica_python/vertica/messages/message.py b/vertica_python/vertica/messages/message.py index 0fb25ebd..0aa3c60d 100644 --- a/vertica_python/vertica/messages/message.py +++ b/vertica_python/vertica/messages/message.py @@ -50,7 +50,7 @@ coming from the backend from UTF-8 into Python text string. """ -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from abc import ABCMeta from struct import pack @@ -96,7 +96,7 @@ class BackendMessage(Message): _message_id_map = {} @classmethod - def from_type(cls, type_, data, **kwargs): + def from_type(cls, type_, data, **kwargs) -> BackendMessage: klass = cls._message_id_map.get(type_) if klass is not None: return klass(data, **kwargs) diff --git a/vertica_python/vertica/mixins/__init__.py b/vertica_python/vertica/mixins/__init__.py index a0e7449d..0c97d9ea 100644 --- a/vertica_python/vertica/mixins/__init__.py +++ b/vertica_python/vertica/mixins/__init__.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations diff --git a/vertica_python/vertica/mixins/notice_response_attr.py b/vertica_python/vertica/mixins/notice_response_attr.py index 2d24fd1f..385f9a52 100644 --- a/vertica_python/vertica/mixins/notice_response_attr.py +++ b/vertica_python/vertica/mixins/notice_response_attr.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function, division, absolute_import +from __future__ import print_function, division, absolute_import, annotations from collections import OrderedDict