Skip to content

Commit 6414e00

Browse files
committed
Exceptions classes should have Error suffix
1 parent df38633 commit 6414e00

8 files changed

+69
-49
lines changed

dbutils/pooled_db.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,23 @@ class PooledDBError(Exception):
156156
"""General PooledDB error."""
157157

158158

159-
class InvalidConnection(PooledDBError):
159+
class InvalidConnectionError(PooledDBError):
160160
"""Database connection is invalid."""
161161

162162

163163
class NotSupportedError(PooledDBError):
164164
"""DB-API module not supported by PooledDB."""
165165

166166

167-
class TooManyConnections(PooledDBError):
167+
class TooManyConnectionsError(PooledDBError):
168168
"""Too many database connections were opened."""
169169

170170

171+
# deprecated alias names for error classes
172+
InvalidConnection = InvalidConnectionError
173+
TooManyConnections = TooManyConnectionsError
174+
175+
171176
class PooledDB:
172177
"""Pool for DB-API 2 connections.
173178
@@ -392,7 +397,7 @@ def __del__(self):
392397
def _wait_lock(self):
393398
"""Wait until notified or report an error."""
394399
if not self._blocking:
395-
raise TooManyConnections
400+
raise TooManyConnectionsError
396401
self._lock.wait()
397402

398403

@@ -427,7 +432,7 @@ def __getattr__(self, name):
427432
"""Proxy all members of the class."""
428433
if self._con:
429434
return getattr(self._con, name)
430-
raise InvalidConnection
435+
raise InvalidConnectionError
431436

432437
def __del__(self):
433438
"""Delete the pooled connection."""
@@ -519,7 +524,7 @@ def __getattr__(self, name):
519524
"""Proxy all members of the class."""
520525
if self._con:
521526
return getattr(self._con, name)
522-
raise InvalidConnection
527+
raise InvalidConnectionError
523528

524529
def __del__(self):
525530
"""Delete the pooled connection."""

dbutils/pooled_pg.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ class PooledPgError(Exception):
126126
"""General PooledPg error."""
127127

128128

129-
class InvalidConnection(PooledPgError):
129+
class InvalidConnectionError(PooledPgError):
130130
"""Database connection is invalid."""
131131

132132

133-
class TooManyConnections(PooledPgError):
133+
class TooManyConnectionsError(PooledPgError):
134134
"""Too many database connections were opened."""
135135

136136

137+
# deprecated alias names for error classes
138+
InvalidConnection = InvalidConnectionError
139+
TooManyConnections = TooManyConnectionsError
140+
141+
137142
class PooledPg:
138143
"""Pool for classic PyGreSQL connections.
139144
@@ -208,7 +213,7 @@ def connection(self):
208213
"""Get a steady, cached PostgreSQL connection from the pool."""
209214
if self._connections:
210215
if not self._connections.acquire(self._blocking):
211-
raise TooManyConnections
216+
raise TooManyConnectionsError
212217
try:
213218
con = self._cache.get_nowait()
214219
except Empty:
@@ -290,7 +295,7 @@ def __getattr__(self, name):
290295
"""Proxy all members of the class."""
291296
if self._con:
292297
return getattr(self._con, name)
293-
raise InvalidConnection
298+
raise InvalidConnectionError
294299

295300
def __del__(self):
296301
"""Delete the pooled connection."""

dbutils/simple_pooled_pg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
Licensed under the MIT license.
6868
"""
6969

70-
from pg import DB as PgConnection
70+
from pg import DB as PgConnection # noqa: N811
7171

7272
from . import __version__
7373

dbutils/steady_db.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ class SteadyDBError(Exception):
9898
"""General SteadyDB error."""
9999

100100

101-
class InvalidCursor(SteadyDBError):
101+
class InvalidCursorError(SteadyDBError):
102102
"""Database cursor is invalid."""
103103

104104

105+
# deprecated alias names for error classes
106+
InvalidCursor = InvalidCursorError
107+
108+
105109
def connect(
106110
creator, maxusage=None, setsession=None,
107111
failures=None, ping=1, closeable=True, *args, **kwargs):
@@ -703,7 +707,7 @@ def __getattr__(self, name):
703707
# make execution methods "tough"
704708
return self._get_tough_method(name)
705709
return getattr(self._cursor, name)
706-
raise InvalidCursor
710+
raise InvalidCursorError
707711

708712
def __del__(self):
709713
"""Delete the steady cursor."""

dbutils/steady_pg.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
Licensed under the MIT license.
7070
"""
7171

72-
from pg import DB as PgConnection
72+
from pg import DB as PgConnection # noqa: N811
7373

7474
from . import __version__
7575

@@ -78,10 +78,14 @@ class SteadyPgError(Exception):
7878
"""General SteadyPg error."""
7979

8080

81-
class InvalidConnection(SteadyPgError):
81+
class InvalidConnectionError(SteadyPgError):
8282
"""Database connection is invalid."""
8383

8484

85+
# deprecated alias names for error classes
86+
InvalidConnection = InvalidConnectionError
87+
88+
8589
class SteadyPgConnection:
8690
"""Class representing steady connections to a PostgreSQL database.
8791
@@ -299,7 +303,7 @@ def __getattr__(self, name):
299303
or name.startswith('get_')):
300304
attr = self._get_tough_method(attr)
301305
return attr
302-
raise InvalidConnection
306+
raise InvalidConnectionError
303307

304308
def __del__(self):
305309
"""Delete the steady connection."""

pyproject.toml

-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ select = [
106106
]
107107
# You can use `ruff rule ...` to see what these ignored rules check
108108
ignore = [
109-
"N811",
110-
"N818",
111109
"PIE790",
112110
"PLR5501",
113111
"PTH122",

tests/test_pooled_db.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import pytest
1717

1818
from dbutils.pooled_db import (
19-
InvalidConnection,
19+
InvalidConnectionError,
2020
NotSupportedError,
2121
PooledDB,
2222
SharedDBConnection,
23-
TooManyConnections,
23+
TooManyConnectionsError,
2424
)
2525
from dbutils.steady_db import SteadyDBConnection
2626

@@ -207,7 +207,7 @@ def test_close_connection(dbapi, threadsafety): # noqa: F811
207207
if shareable:
208208
assert db._shared_con is None
209209
assert shared_con.shared == 0
210-
with pytest.raises(InvalidConnection):
210+
with pytest.raises(InvalidConnectionError):
211211
assert db._usage
212212
assert not hasattr(db_con, '_num_queries')
213213
assert len(pool._idle_cache) == 1
@@ -692,9 +692,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
692692
assert len(pool._idle_cache) == 0
693693
if shareable:
694694
assert len(pool._shared_cache) == 0
695-
with pytest.raises(TooManyConnections):
695+
with pytest.raises(TooManyConnectionsError):
696696
pool.connection(False)
697-
with pytest.raises(TooManyConnections):
697+
with pytest.raises(TooManyConnectionsError):
698698
pool.connection()
699699
cache = []
700700
assert pool._connections == 0
@@ -712,13 +712,13 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
712712
assert len(pool._shared_cache) == 2
713713
else:
714714
assert pool._connections == 3
715-
with pytest.raises(TooManyConnections):
715+
with pytest.raises(TooManyConnectionsError):
716716
pool.connection(False)
717717
if shareable:
718718
cache.append(pool.connection(True))
719719
assert pool._connections == 3
720720
else:
721-
with pytest.raises(TooManyConnections):
721+
with pytest.raises(TooManyConnectionsError):
722722
pool.connection()
723723
del cache
724724
assert pool._connections == 0
@@ -732,9 +732,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
732732
assert len(pool._idle_cache) == 0
733733
if shareable:
734734
assert len(pool._shared_cache) == 0
735-
with pytest.raises(TooManyConnections):
735+
with pytest.raises(TooManyConnectionsError):
736736
pool.connection(False)
737-
with pytest.raises(TooManyConnections):
737+
with pytest.raises(TooManyConnectionsError):
738738
pool.connection()
739739
assert db
740740
del db
@@ -750,17 +750,17 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
750750
assert len(pool._shared_cache) == 1
751751
assert pool._shared_cache[0].shared == 2
752752
else:
753-
with pytest.raises(TooManyConnections):
753+
with pytest.raises(TooManyConnectionsError):
754754
pool.connection()
755-
with pytest.raises(TooManyConnections):
755+
with pytest.raises(TooManyConnectionsError):
756756
pool.connection(False)
757757
if shareable:
758758
cache.append(pool.connection(True))
759759
assert pool._connections == 1
760760
assert len(pool._shared_cache) == 1
761761
assert pool._shared_cache[0].shared == 3
762762
else:
763-
with pytest.raises(TooManyConnections):
763+
with pytest.raises(TooManyConnectionsError):
764764
pool.connection(True)
765765
del cache
766766
assert pool._connections == 0
@@ -786,9 +786,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
786786
assert len(pool._idle_cache) == 0
787787
if shareable:
788788
assert len(pool._shared_cache) == 0
789-
with pytest.raises(TooManyConnections):
789+
with pytest.raises(TooManyConnectionsError):
790790
pool.connection(False)
791-
with pytest.raises(TooManyConnections):
791+
with pytest.raises(TooManyConnectionsError):
792792
pool.connection()
793793
pool = PooledDB(dbapi, 4, 3, 2, 1, False)
794794
assert pool._maxconnections == 4
@@ -799,9 +799,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
799799
cache.append(pool.connection(False))
800800
assert pool._connections == 4
801801
assert len(pool._idle_cache) == 0
802-
with pytest.raises(TooManyConnections):
802+
with pytest.raises(TooManyConnectionsError):
803803
pool.connection(False)
804-
with pytest.raises(TooManyConnections):
804+
with pytest.raises(TooManyConnectionsError):
805805
pool.connection()
806806
pool = PooledDB(dbapi, 1, 2, 3, 4, False)
807807
assert pool._maxconnections == 4
@@ -819,9 +819,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
819819
assert pool._connections == 4
820820
else:
821821
assert pool._connections == 4
822-
with pytest.raises(TooManyConnections):
822+
with pytest.raises(TooManyConnectionsError):
823823
pool.connection()
824-
with pytest.raises(TooManyConnections):
824+
with pytest.raises(TooManyConnectionsError):
825825
pool.connection(False)
826826
pool = PooledDB(dbapi, 0, 0, 3, 3, False)
827827
assert pool._maxconnections == 3
@@ -830,9 +830,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
830830
for _i in range(3):
831831
cache.append(pool.connection(False))
832832
assert pool._connections == 3
833-
with pytest.raises(TooManyConnections):
833+
with pytest.raises(TooManyConnectionsError):
834834
pool.connection(False)
835-
with pytest.raises(TooManyConnections):
835+
with pytest.raises(TooManyConnectionsError):
836836
pool.connection(True)
837837
cache = []
838838
assert pool._connections == 0
@@ -844,9 +844,9 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
844844
cache.append(pool.connection())
845845
assert pool._connections == 3
846846
else:
847-
with pytest.raises(TooManyConnections):
847+
with pytest.raises(TooManyConnectionsError):
848848
pool.connection()
849-
with pytest.raises(TooManyConnections):
849+
with pytest.raises(TooManyConnectionsError):
850850
pool.connection(False)
851851
pool = PooledDB(dbapi, 0, 0, 3)
852852
assert pool._maxconnections == 0
@@ -1165,7 +1165,7 @@ def test_shared_in_transaction(dbapi): # noqa: F811
11651165
db = pool.connection()
11661166
db.begin()
11671167
pool.connection(False)
1168-
with pytest.raises(TooManyConnections):
1168+
with pytest.raises(TooManyConnectionsError):
11691169
pool.connection()
11701170
pool = PooledDB(dbapi, 0, 2, 2)
11711171
db1 = pool.connection()
@@ -1183,7 +1183,7 @@ def test_shared_in_transaction(dbapi): # noqa: F811
11831183
db.close()
11841184
db2.begin()
11851185
pool.connection(False)
1186-
with pytest.raises(TooManyConnections):
1186+
with pytest.raises(TooManyConnectionsError):
11871187
pool.connection()
11881188
db1.rollback()
11891189
db = pool.connection()

0 commit comments

Comments
 (0)