From: Daniele Varrazzo Date: Thu, 4 Apr 2024 21:37:57 +0000 (+0000) Subject: style: use literals instead of the concatenation operator for long strings X-Git-Tag: 3.2.0~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e68aa19fb411d8e1b385860e57a40af367072a54;p=thirdparty%2Fpsycopg.git 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 #764 suggests to disable line length check altogether, but we can use per-file ignore, as there will not be many cases to manage. --- diff --git a/.flake8 b/.flake8 index 35bb95d7c..b4ae65d21 100644 --- 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 diff --git a/psycopg_pool/.flake8 b/psycopg_pool/.flake8 index 40a061b1e..67466af4d 100644 --- a/psycopg_pool/.flake8 +++ b/psycopg_pool/.flake8 @@ -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 diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py index a021e14a0..e08476e60 100644 --- a/psycopg_pool/psycopg_pool/pool.py +++ b/psycopg_pool/psycopg_pool/pool.py @@ -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, diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index 25b19cda0..e70781b60 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -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,