Skip to content

Commit e68aa19

Browse files
committed
style: use literals instead of the concatenation operator for long strings
The reason we were using operators was to stop async_to_sync to generate a line too long and incur in the flake8 ires. MR psycopg#764 suggests to disable line length check altogether, but we can use per-file ignore, as there will not be many cases to manage.
1 parent 8832666 commit e68aa19

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ extend-exclude = .venv build
1010
per-file-ignores =
1111
# Autogenerated section
1212
psycopg/psycopg/errors.py: E125, E128, E302
13+
14+
# Allow concatenated string literals from async_to_sync
15+
psycopg_pool/psycopg_pool/pool.py: E501

psycopg_pool/.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[flake8]
22
max-line-length = 88
33
ignore = W503, E203, E704
4+
5+
per-file-ignores =
6+
# Allow concatenated string literals from async_to_sync
7+
psycopg_pool/pool.py: E501

psycopg_pool/psycopg_pool/pool.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ def _check_open_getconn(self) -> None:
115115
self._open_implicit = False
116116

117117
warnings.warn(
118-
f"the default for the {type(self).__name__} 'open' parameter"
119-
+ " will become 'False' in a future release. Please use"
120-
+ " open={True|False} explicitly, or use the pool as context"
121-
+ f" manager using: `with {type(self).__name__}(...) as pool: ...`",
118+
f"the default for the {type(self).__name__} 'open' parameter will become 'False' in a future release. Please use open={{True|False}} explicitly, or use the pool as context manager using: `with {type(self).__name__}(...) as pool: ...`",
122119
DeprecationWarning,
123120
)
124121

@@ -278,8 +275,7 @@ def _get_ready_connection(self, timeout: Optional[float]) -> Optional[CT]:
278275
elif self.max_waiting and len(self._waiting) >= self.max_waiting:
279276
self._stats[self._REQUESTS_ERRORS] += 1
280277
raise TooManyRequests(
281-
f"the pool {self.name!r} has already"
282-
+ f" {len(self._waiting)} requests waiting"
278+
f"the pool {self.name!r} has already {len(self._waiting)} requests waiting"
283279
)
284280
return conn
285281

@@ -613,8 +609,7 @@ def _connect(self, timeout: Optional[float] = None) -> CT:
613609
if status != TransactionStatus.IDLE:
614610
sname = TransactionStatus(status).name
615611
raise e.ProgrammingError(
616-
f"connection left in status {sname} by configure function"
617-
+ f" {self._configure}: discarded"
612+
f"connection left in status {sname} by configure function {self._configure}: discarded"
618613
)
619614

620615
# Set an expiry date, with some randomness to avoid mass reconnection
@@ -768,8 +763,7 @@ def _reset_connection(self, conn: CT) -> None:
768763
if status != TransactionStatus.IDLE:
769764
sname = TransactionStatus(status).name
770765
raise e.ProgrammingError(
771-
f"connection left in status {sname} by reset function"
772-
+ f" {self._reset}: discarded"
766+
f"connection left in status {sname} by reset function {self._reset}: discarded"
773767
)
774768
except Exception as ex:
775769
logger.warning(f"error resetting connection: {ex}")
@@ -791,8 +785,7 @@ def _shrink_pool(self) -> None:
791785

792786
if to_close:
793787
logger.info(
794-
"shrinking pool %r to %s because %s unused connections"
795-
+ " in the last %s sec",
788+
"shrinking pool %r to %s because %s unused connections in the last %s sec",
796789
self.name,
797790
self._nconns,
798791
nconns_min,

psycopg_pool/psycopg_pool/pool_async.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def _check_open_getconn(self) -> None:
125125
else:
126126
warnings.warn(
127127
f"the default for the {type(self).__name__} 'open' parameter"
128-
+ " will become 'False' in a future release. Please use"
129-
+ " open={True|False} explicitly, or use the pool as context"
130-
+ f" manager using: `with {type(self).__name__}(...) as pool: ...`",
128+
" will become 'False' in a future release. Please use"
129+
" open={True|False} explicitly, or use the pool as context"
130+
f" manager using: `with {type(self).__name__}(...) as pool: ...`",
131131
DeprecationWarning,
132132
)
133133

@@ -300,7 +300,7 @@ async def _get_ready_connection(self, timeout: Optional[float]) -> Optional[ACT]
300300
self._stats[self._REQUESTS_ERRORS] += 1
301301
raise TooManyRequests(
302302
f"the pool {self.name!r} has already"
303-
+ f" {len(self._waiting)} requests waiting"
303+
f" {len(self._waiting)} requests waiting"
304304
)
305305
return conn
306306

@@ -658,7 +658,7 @@ async def _connect(self, timeout: Optional[float] = None) -> ACT:
658658
sname = TransactionStatus(status).name
659659
raise e.ProgrammingError(
660660
f"connection left in status {sname} by configure function"
661-
+ f" {self._configure}: discarded"
661+
f" {self._configure}: discarded"
662662
)
663663

664664
# Set an expiry date, with some randomness to avoid mass reconnection
@@ -818,7 +818,7 @@ async def _reset_connection(self, conn: ACT) -> None:
818818
sname = TransactionStatus(status).name
819819
raise e.ProgrammingError(
820820
f"connection left in status {sname} by reset function"
821-
+ f" {self._reset}: discarded"
821+
f" {self._reset}: discarded"
822822
)
823823
except Exception as ex:
824824
logger.warning(f"error resetting connection: {ex}")
@@ -841,7 +841,7 @@ async def _shrink_pool(self) -> None:
841841
if to_close:
842842
logger.info(
843843
"shrinking pool %r to %s because %s unused connections"
844-
+ " in the last %s sec",
844+
" in the last %s sec",
845845
self.name,
846846
self._nconns,
847847
nconns_min,

0 commit comments

Comments
 (0)