]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
style: use literals instead of the concatenation operator for long strings
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 4 Apr 2024 21:37:57 +0000 (21:37 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 5 Apr 2024 12:06:30 +0000 (13:06 +0100)
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 #764 suggests to disable line length check altogether, but we can use
per-file ignore, as there will not be many cases to manage.

.flake8
psycopg_pool/.flake8
psycopg_pool/psycopg_pool/pool.py
psycopg_pool/psycopg_pool/pool_async.py

diff --git a/.flake8 b/.flake8
index 35bb95d7caa46704b4dbbca8612567f87f379682..b4ae65d212e24c84f6a4050734882ae140947b52 100644 (file)
--- a/.flake8
+++ b/.flake8
@@ -10,3 +10,6 @@ extend-exclude = .venv build
 per-file-ignores =
     # Autogenerated section
     psycopg/psycopg/errors.py: E125, E128, E302
+
+    # Allow concatenated string literals from async_to_sync
+    psycopg_pool/psycopg_pool/pool.py: E501
index 40a061b1e954b4de28869853a004d04fcd5459b7..67466af4d7ecc10e4af9de0579590056e72ffcbf 100644 (file)
@@ -1,3 +1,7 @@
 [flake8]
 max-line-length = 88
 ignore = W503, E203, E704
+
+per-file-ignores =
+    # Allow concatenated string literals from async_to_sync
+    psycopg_pool/pool.py: E501
index a021e14a0ba94d089877a3417fc6e34b932461ed..e08476e603ae06ddb67a107a1d5c3603bc641ec7 100644 (file)
@@ -115,10 +115,7 @@ class ConnectionPool(Generic[CT], BasePool):
             self._open_implicit = False
 
             warnings.warn(
-                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"
-                + f" manager using: `with {type(self).__name__}(...) as pool: ...`",
+                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: ...`",
                 DeprecationWarning,
             )
 
@@ -278,8 +275,7 @@ class ConnectionPool(Generic[CT], BasePool):
         elif self.max_waiting and len(self._waiting) >= self.max_waiting:
             self._stats[self._REQUESTS_ERRORS] += 1
             raise TooManyRequests(
-                f"the pool {self.name!r} has already"
-                + f" {len(self._waiting)} requests waiting"
+                f"the pool {self.name!r} has already {len(self._waiting)} requests waiting"
             )
         return conn
 
@@ -613,8 +609,7 @@ class ConnectionPool(Generic[CT], BasePool):
             if status != TransactionStatus.IDLE:
                 sname = TransactionStatus(status).name
                 raise e.ProgrammingError(
-                    f"connection left in status {sname} by configure function"
-                    + f" {self._configure}: discarded"
+                    f"connection left in status {sname} by configure function {self._configure}: discarded"
                 )
 
         # Set an expiry date, with some randomness to avoid mass reconnection
@@ -768,8 +763,7 @@ class ConnectionPool(Generic[CT], BasePool):
                 if status != TransactionStatus.IDLE:
                     sname = TransactionStatus(status).name
                     raise e.ProgrammingError(
-                        f"connection left in status {sname} by reset function"
-                        + f" {self._reset}: discarded"
+                        f"connection left in status {sname} by reset function {self._reset}: discarded"
                     )
             except Exception as ex:
                 logger.warning(f"error resetting connection: {ex}")
@@ -791,8 +785,7 @@ class ConnectionPool(Generic[CT], BasePool):
 
         if to_close:
             logger.info(
-                "shrinking pool %r to %s because %s unused connections"
-                + " in the last %s sec",
+                "shrinking pool %r to %s because %s unused connections in the last %s sec",
                 self.name,
                 self._nconns,
                 nconns_min,
index 25b19cda0f14471dc8a8733b080706f017b42401..e70781b6031e345fb5ad3e438de640d1fd9f1e4d 100644 (file)
@@ -125,9 +125,9 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
             else:
                 warnings.warn(
                     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"
-                    f" manager using: `with {type(self).__name__}(...) as pool: ...`",
+                    " will become 'False' in a future release. Please use"
+                    " open={True|False} explicitly, or use the pool as context"
+                    f" manager using: `with {type(self).__name__}(...) as pool: ...`",
                     DeprecationWarning,
                 )
 
@@ -300,7 +300,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
             self._stats[self._REQUESTS_ERRORS] += 1
             raise TooManyRequests(
                 f"the pool {self.name!r} has already"
-                f" {len(self._waiting)} requests waiting"
+                f" {len(self._waiting)} requests waiting"
             )
         return conn
 
@@ -658,7 +658,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
                 sname = TransactionStatus(status).name
                 raise e.ProgrammingError(
                     f"connection left in status {sname} by configure function"
-                    f" {self._configure}: discarded"
+                    f" {self._configure}: discarded"
                 )
 
         # Set an expiry date, with some randomness to avoid mass reconnection
@@ -818,7 +818,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
                     sname = TransactionStatus(status).name
                     raise e.ProgrammingError(
                         f"connection left in status {sname} by reset function"
-                        f" {self._reset}: discarded"
+                        f" {self._reset}: discarded"
                     )
             except Exception as ex:
                 logger.warning(f"error resetting connection: {ex}")
@@ -841,7 +841,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
         if to_close:
             logger.info(
                 "shrinking pool %r to %s because %s unused connections"
-                " in the last %s sec",
+                " in the last %s sec",
                 self.name,
                 self._nconns,
                 nconns_min,