Skip to content

Commit

Permalink
remove more Python2 compatibility (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste authored Aug 1, 2024
1 parent a67d90b commit 36a04a9
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ cur.executemany("INSERT INTO table (a, b) VALUES (%s, %s)", [[100, value]], use_
##### Register new SQL literal adapters
It is possible to adapt new Python types to SQL literals via `Cursor.register_sql_literal_adapter(py_class_or_type, adapter_function)` function. Example:
```python
class Point(object):
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pytest
pytest-timeout
python-dateutil
six
tox
#kerberos
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
python_requires=">=3.7",
install_requires=[
'python-dateutil>=1.5',
'six>=1.10.0'
],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
13 changes: 4 additions & 9 deletions vertica_python/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
* `real_types`
"""

import six as _six


def as_bytes(bytes_or_text, encoding='utf-8'):
"""Converts either bytes or unicode to `bytes`, using utf-8 encoding for text.
Expand All @@ -76,7 +74,7 @@ def as_bytes(bytes_or_text, encoding='utf-8'):
Raises:
TypeError: If `bytes_or_text` is not a binary or unicode string.
"""
if isinstance(bytes_or_text, _six.text_type):
if isinstance(bytes_or_text, str):
return bytes_or_text.encode(encoding)
elif isinstance(bytes_or_text, bytearray):
return bytes(bytes_or_text)
Expand All @@ -97,7 +95,7 @@ def as_text(bytes_or_text, encoding='utf-8'):
Raises:
TypeError: If `bytes_or_text` is not a binary or unicode string.
"""
if isinstance(bytes_or_text, _six.text_type):
if isinstance(bytes_or_text, str):
return bytes_or_text
elif isinstance(bytes_or_text, (bytes, bytearray)):
return bytes_or_text.decode(encoding)
Expand All @@ -106,10 +104,7 @@ def as_text(bytes_or_text, encoding='utf-8'):


# Convert an object to a `str` in both Python 2 and 3.
if _six.PY2:
as_str = as_bytes
else:
as_str = as_text
as_str = as_text


def as_str_any(value):
Expand All @@ -126,7 +121,7 @@ def as_str_any(value):


# Either bytes or text.
bytes_or_text_types = (bytes, bytearray, _six.text_type)
bytes_or_text_types = (bytes, bytearray, str)

_allowed_symbols = [
'as_str',
Expand Down
2 changes: 1 addition & 1 deletion vertica_python/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def Binary(string):
return Bytea(string)


class VerticaType(object):
class VerticaType:
UNKNOWN = 4
BOOL = 5
INT8 = 6
Expand Down
2 changes: 1 addition & 1 deletion vertica_python/tests/unit_tests/test_sql_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_default_adapters(self):
self.assertEqual(cursor.object_to_sql_literal(p), "(11,22,33)")

def test_register_adapters(self):
class Point(object):
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
Expand Down
4 changes: 2 additions & 2 deletions vertica_python/vertica/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

# Data of a particular SQL data type might be transmitted in either "text" format or "binary" format.
# The desired format for any column is specified by a format code.
class FormatCode(object):
class FormatCode:
TEXT = 0
BINARY = 1

Expand All @@ -61,7 +61,7 @@ class ColumnTuple(NamedTuple):
null_ok: bool


class Column(object):
class Column:
def __init__(self, col) -> None:
# Describe one query result column
self.name = col['name']
Expand Down
4 changes: 2 additions & 2 deletions vertica_python/vertica/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class _AddressEntry(NamedTuple):
data: Any


class _AddressList(object):
class _AddressList:
def __init__(self, host: str, port: Union[int, str],
backup_nodes: List[Union[str, Tuple[str, Union[int, str]]]],
logger: logging.Logger) -> None:
Expand Down Expand Up @@ -258,7 +258,7 @@ def _generate_session_label() -> str:
)


class Connection(object):
class Connection:
def __init__(self, options: Optional[Dict[str, Any]] = None) -> None:
self.parameters: Dict[str, Union[str, int]] = {}
self.session_id = None
Expand Down
2 changes: 1 addition & 1 deletion vertica_python/vertica/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
DEFAULT_BUFFER_SIZE = 131072


class Cursor(object):
class Cursor:
# NOTE: this is used in executemany and is here for pandas compatibility
_insert_statement = re.compile(RE_BASIC_INSERT_STAT, re.U | re.I)

Expand Down
2 changes: 1 addition & 1 deletion vertica_python/vertica/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ..vertica.column import FormatCode


class Deserializer(object):
class Deserializer:
def get_row_deserializers(self,
columns: List[Column],
custom_converters: Dict[int, Callable[[bytes, Dict[str, Any]], Any]],
Expand Down
2 changes: 1 addition & 1 deletion vertica_python/vertica/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from typing import Union
from ..os_utils import ensure_dir_exists

class VerticaLogging(object):
class VerticaLogging:

@classmethod
def setup_logging(cls, logger_name: str, logfile: str,
Expand Down
2 changes: 1 addition & 1 deletion vertica_python/vertica/messages/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from ..messages import *


class Message(object):
class Message:
__metaclass__ = ABCMeta

def __init__(self):
Expand Down

0 comments on commit 36a04a9

Please sign in to comment.