From ca594c99f74920dee50a512555e67b778f7c1e2e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 28 Dec 2024 01:28:30 +0100 Subject: [PATCH] refactor: replace list comprehension with generators in multiple assignments --- tests/pool/test_pool.py | 4 ++-- tests/pool/test_pool_async.py | 4 ++-- tests/pool/test_pool_null.py | 4 ++-- tests/pool/test_pool_null_async.py | 4 ++-- tests/test_typing.py | 4 ++-- tools/update_error_prefixes.py | 6 +++--- tools/update_errors.py | 6 +++--- tools/update_oids.py | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index a3e991d1f..d92859cb7 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -6,7 +6,7 @@ from __future__ import annotations import logging import weakref from time import time -from typing import Any, Dict +from typing import Any import pytest @@ -43,7 +43,7 @@ def test_bad_size(dsn, min_size, max_size): pool.ConnectionPool(min_size=min_size, max_size=max_size) -class MyRow(Dict[str, Any]): +class MyRow(dict[str, Any]): pass diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index bdcedff49..464e22ba6 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging import weakref from time import time -from typing import Any, Dict +from typing import Any import pytest @@ -43,7 +43,7 @@ async def test_bad_size(dsn, min_size, max_size): pool.AsyncConnectionPool(min_size=min_size, max_size=max_size) -class MyRow(Dict[str, Any]): +class MyRow(dict[str, Any]): pass diff --git a/tests/pool/test_pool_null.py b/tests/pool/test_pool_null.py index 89b39d7af..13260ad0d 100644 --- a/tests/pool/test_pool_null.py +++ b/tests/pool/test_pool_null.py @@ -4,7 +4,7 @@ from __future__ import annotations import logging -from typing import Any, Dict +from typing import Any import pytest from packaging.version import parse as ver # noqa: F401 # used in skipif @@ -41,7 +41,7 @@ def test_bad_size(dsn, min_size, max_size): pool.NullConnectionPool(min_size=min_size, max_size=max_size) -class MyRow(Dict[str, Any]): +class MyRow(dict[str, Any]): pass diff --git a/tests/pool/test_pool_null_async.py b/tests/pool/test_pool_null_async.py index c74acb8fd..c35cacba3 100644 --- a/tests/pool/test_pool_null_async.py +++ b/tests/pool/test_pool_null_async.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import Any, Dict +from typing import Any import pytest from packaging.version import parse as ver # noqa: F401 # used in skipif @@ -41,7 +41,7 @@ async def test_bad_size(dsn, min_size, max_size): pool.AsyncNullConnectionPool(min_size=min_size, max_size=max_size) -class MyRow(Dict[str, Any]): +class MyRow(dict[str, Any]): pass diff --git a/tests/test_typing.py b/tests/test_typing.py index 2ad397189..911fca1f9 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -408,7 +408,7 @@ reveal_type(ref) cp = mypy.run_on_source(src) out = cp.stdout.decode("utf8", "replace").splitlines() assert len(out) == 2, "\n".join(out) - got, want = [mypy.get_revealed(line) for line in out] + got, want = (mypy.get_revealed(line) for line in out) assert got == want @@ -447,5 +447,5 @@ reveal_type(ref) cp = mypy.run_on_source(src) out = cp.stdout.decode("utf8", "replace").splitlines() assert len(out) == 2, "\n".join(out) - got, want = [mypy.get_revealed(line) for line in out] + got, want = (mypy.get_revealed(line) for line in out) assert got == want diff --git a/tools/update_error_prefixes.py b/tools/update_error_prefixes.py index af63ae240..9b4908806 100755 --- a/tools/update_error_prefixes.py +++ b/tools/update_error_prefixes.py @@ -49,14 +49,14 @@ def make_regexp(pgroot: Path) -> str: def update_file(fn: Path, content: str) -> None: logger.info("updating %s", fn) - with open(fn, "r") as f: + with open(fn) as f: lines = f.read().splitlines() - istart, iend = [ + istart, iend = ( i for i, line in enumerate(lines) if re.match(r"\s*(#|\.\.)\s*autogenerated:\s+(start|end)", line) - ] + ) lines[istart + 1 : iend] = [content] diff --git a/tools/update_errors.py b/tools/update_errors.py index 3218ccac5..d192aeb10 100755 --- a/tools/update_errors.py +++ b/tools/update_errors.py @@ -197,14 +197,14 @@ def generate_docs_data(classes, errors): def update_file(fn, new_lines): logger.info("updating %s", fn) - with open(fn, "r") as f: + with open(fn) as f: lines = f.read().splitlines() - istart, iend = [ + istart, iend = ( i for i, line in enumerate(lines) if re.match(r"\s*(#|\.\.)\s*autogenerated:\s+(start|end)", line) - ] + ) lines[istart + 1 : iend] = new_lines diff --git a/tools/update_oids.py b/tools/update_oids.py index 096cbe9d5..fc913e07f 100755 --- a/tools/update_oids.py +++ b/tools/update_oids.py @@ -241,11 +241,11 @@ order by typname def update_file(fn: Path, new: list[str]) -> None: with fn.open("r") as f: lines = f.read().splitlines() - istart, iend = [ + istart, iend = ( i for i, line in enumerate(lines) if re.match(r"\s*#\s*autogenerated:\s+(start|end)", line) - ] + ) lines[istart + 1 : iend] = new + [""] with fn.open("w") as f: -- 2.39.5