From 905661cb2a0806b4e3dd662757b81d774e219d9e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:44:38 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.5 → v0.5.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.5...v0.5.5) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ff71f9..1a921ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.5 + rev: v0.5.5 hooks: - id: ruff args: ["--preview", "--fix"] From 97d0e83fc2dfbb2b7265b7aae96cbb0386c6e702 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:44:44 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/changelog.rst | 2 +- docs/conversion.rst | 2 +- src/pg_purepy/connection.py | 19 +++++++++---------- src/pg_purepy/conversion/arrays.py | 2 +- src/pg_purepy/conversion/dt.py | 5 ++--- src/pg_purepy/conversion/enums.py | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4c7b03a..f3bc9f8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,7 +4,7 @@ Changelog 0.11.0 (2024-04-12) ------------------- -- Switch to the ``whenever`` package for date/time types, instead of Arrow. See +- Switch to the ``whenever`` package for date/time types, instead of Arrow. See https://dev.arie.bovenberg.net/blog/python-datetime-pitfalls/ for more information as to why. - ``pg-purepy`` now passes Pyright strict mode. - :class:`.Converter` is now a generic type. diff --git a/docs/conversion.rst b/docs/conversion.rst index c942f9c..80b0233 100644 --- a/docs/conversion.rst +++ b/docs/conversion.rst @@ -35,7 +35,7 @@ Date/Time types .. note:: - I use Whenever over the vanilla ``datetime`` objects because I don't like ``datetime``. Write + I use Whenever over the vanilla ``datetime`` objects because I don't like ``datetime``. Write your own converter if you disagree with me. Enumeration types diff --git a/src/pg_purepy/connection.py b/src/pg_purepy/connection.py index 8dd44b6..9624dff 100644 --- a/src/pg_purepy/connection.py +++ b/src/pg_purepy/connection.py @@ -6,6 +6,7 @@ import types import warnings +from asyncio import lowlevel from collections.abc import AsyncGenerator, AsyncIterator, Mapping from contextlib import aclosing, asynccontextmanager from os import PathLike, fspath @@ -187,7 +188,7 @@ async def _read_until_ready( """ if self._protocol.ready: - await anyio.sleep(0) + await lowlevel.checkpoint() return while True: @@ -210,7 +211,7 @@ async def _read_until_ready( yield next_event if isinstance(next_event, ReadyForQuery): - await anyio.sleep(0) # checkpoint() + await lowlevel.checkpoint() # checkpoint() return to_send = self._protocol.get_needed_synchronisation() @@ -288,13 +289,11 @@ async def lowlevel_query( if not self._protocol.ready: await self.wait_until_ready() - simple_query = all( - ( - not (params or kwargs), - not isinstance(query, PreparedStatementInfo), - max_rows is None, - ) - ) + simple_query = all(( + not (params or kwargs), + not isinstance(query, PreparedStatementInfo), + max_rows is None, + )) logger.debug("Executing query", query=query) if simple_query: @@ -527,7 +526,7 @@ async def row_count(self) -> int: """ if self._row_count >= 0: - await anyio.sleep(0) # checkpoint + await lowlevel.checkpoint() # checkpoint return self._row_count async for _ in self: diff --git a/src/pg_purepy/conversion/arrays.py b/src/pg_purepy/conversion/arrays.py index 3bf0198..9ebd531 100644 --- a/src/pg_purepy/conversion/arrays.py +++ b/src/pg_purepy/conversion/arrays.py @@ -30,7 +30,7 @@ def __init__(self, oid: int, subconverter: Converter[T], quote_inner: bool = Fal def from_postgres(self, context: ConversionContext, data: str) -> list[T]: p = partial(self._subconverter.from_postgres, context) return _parse_array(data, p) - + @override def to_postgres(self, context: ConversionContext, data: Iterable[T]) -> str: converted = [ diff --git a/src/pg_purepy/conversion/dt.py b/src/pg_purepy/conversion/dt.py index 2a7ed6f..2e54299 100644 --- a/src/pg_purepy/conversion/dt.py +++ b/src/pg_purepy/conversion/dt.py @@ -44,7 +44,6 @@ def to_postgres( context: ConversionContext, data: PostgresTimestampTz, ) -> str: - match data: case "infinity": return "infinity" @@ -85,14 +84,14 @@ def to_postgres(self, context: ConversionContext, data: PostgresTimestampWithout # |---------------------| # | 2021-07-13 22:16:36 | # +---------------------+ - + match data: case "infinity": return data case "-infinity": return data - + case whenever.NaiveDateTime(): return data.common_iso8601() diff --git a/src/pg_purepy/conversion/enums.py b/src/pg_purepy/conversion/enums.py index c9dbac9..a1e0e00 100644 --- a/src/pg_purepy/conversion/enums.py +++ b/src/pg_purepy/conversion/enums.py @@ -9,7 +9,7 @@ from pg_purepy.protocol import ConversionContext -class EnumConverter[T : Enum](Converter[T]): +class EnumConverter[T: Enum](Converter[T]): """ A converter that lets you use Python enums for PostgreSQL enums. """