Skip to content

Commit

Permalink
Add deprecation warning for db2 module
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti committed Jul 2, 2024
1 parent 107270e commit 0660ea2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
41 changes: 28 additions & 13 deletions pyexasol/db2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@
There is no "paramstyle" and no proper error handling
"""

from warnings import warn
from inspect import cleandoc
from ..connection import ExaConnection

apilevel = '2.0'
from ..warnings import PyexasolDeprecationWarning

warn(
cleandoc(
"""
This module is deprecated and will be removed in the future.
If you require a dbapi2 compliant driver, please use the dbapi2 compliant driver facade available in the `exasol.driver.websocket` package.
"""
),
PyexasolDeprecationWarning,
)

apilevel = "2.0"
threadsafety = 1
paramstyle = None


def connect(**kwargs):
if 'autocommit' not in kwargs:
kwargs['autocommit'] = False
if "autocommit" not in kwargs:
kwargs["autocommit"] = False

return DB2Connection(**kwargs)

Expand Down Expand Up @@ -66,15 +79,17 @@ def description(self):
cols = []

for k, v in self.stmt.columns().items():
cols.append((
k,
v.get('type', None),
v.get('size', None),
v.get('size', None),
v.get('precision', None),
v.get('scale', None),
True
))
cols.append(
(
k,
v.get("type", None),
v.get("size", None),
v.get("size", None),
v.get("precision", None),
v.get("scale", None),
True,
)
)

return cols

Expand Down
6 changes: 6 additions & 0 deletions pyexasol/warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PyexasolWarning(UserWarning):
"""Base class for all warnings emited by pyexasol."""


class PyexasolDeprecationWarning(PyexasolWarning, DeprecationWarning):
"""Warning class for features that will be removed in future versions."""
7 changes: 7 additions & 0 deletions test/unit/deprectation_warning_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest
from pyexasol.warnings import PyexasolDeprecationWarning


def test_import_db2_module_emits_deprecation_warning():
with pytest.warns(PyexasolDeprecationWarning):
from pyexasol import db2

0 comments on commit 0660ea2

Please sign in to comment.