Skip to content

Commit

Permalink
update to newest whenever
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuyukai committed Jul 30, 2024
1 parent 40f9947 commit e965a02
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 328 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

0.11.1 (2024-07-30)
-------------------

- Fix for newer dependencies.

0.11.0 (2024-04-12)
-------------------

Expand Down
631 changes: 340 additions & 291 deletions poetry.lock

Large diffs are not rendered by default.

26 changes: 4 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry]
name = "pg-purepy"
version = "0.10.0"
version = "0.11.0"
description = "A pure-Python anyio-based PostgreSQL adapter."
authors = ["Lura Skye <[email protected]>"]
license = "LGPL-3.0-or-later"
Expand All @@ -26,18 +26,17 @@ structlog = ">=24.1.0"
whenever = ">=0.5.1"

[tool.poetry.group.docs.dependencies]
sphinx = ">=7.2.6"
sphinx-rtd-theme = ">=2.0.0"
sphinx = "<8.0" # damn, this released *yesterday*
sphinx-inline-tabs = ">=2023.4.21"
sphinx-autodoc-typehints = ">=2.0.1"
sphinxcontrib-jquery = ">=4.1"
sphinx-rtd-theme = ">=2.0.0"

[tool.poetry.group.dev.dependencies]
pytest = ">=8.1.1"
trio = ">=0.25.0"
isort = ">=5.13.2"
pytest-cov = ">=5.0.0"
mypy = ">=1.9.0"
ruff = ">=0.3.7"
ujson = ">=5.9.0"
pyright = ">=1.1.358"
Expand Down Expand Up @@ -80,7 +79,6 @@ select = [
"B",
"YTT",
"ASYNC",
"TRIO",
"PYI",
"SIM",
"RET",
Expand All @@ -105,21 +103,5 @@ reportUnusedVariable = false
reportIncompatibleVariableOverride = false
reportPrivateUsage = false

[tool.mypy]
python_version = "3.11"
ignore_missing_imports = true

local_partial_types = true
warn_unused_ignores = true
warn_unused_configs = true
warn_redundant_casts = true
warn_return_any = true

disallow_any_generics = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
check_untyped_defs = true

[tool.poetry-dynamic-versioning]
enable = true
enable = false
2 changes: 1 addition & 1 deletion src/pg_purepy/conversion/_parse_hstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def esc(s, position):
return "NULL"

if isinstance(s, str):
return '"%s"' % s.replace("\\", "\\\\").replace('"', r"\"")
return '"{}"'.format(s.replace("\\", "\\\\").replace('"', r"\""))

raise ValueError(f"{s!r} in {position} position is not a string.")

Expand Down
2 changes: 1 addition & 1 deletion src/pg_purepy/conversion/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
17 changes: 8 additions & 9 deletions src/pg_purepy/conversion/dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

type PostgresInfinity = Literal["infinity", "-infinity"]
type PostgresTimestampTz = whenever.OffsetDateTime | PostgresInfinity
type PostgresTimestampWithoutTz = whenever.NaiveDateTime | PostgresInfinity
type PostgresTimestampWithoutTz = whenever.LocalDateTime | PostgresInfinity


class TimestampTzConverter(Converter[PostgresTimestampTz]):
Expand All @@ -36,15 +36,14 @@ def from_postgres(self, context: ConversionContext, data: str) -> PostgresTimest
parsed = dateutil.parser.isoparse(data)

# can't directly pass the datetime as it'll complain about UTC.
return whenever.OffsetDateTime.from_rfc3339(parsed.isoformat())
return whenever.OffsetDateTime.parse_rfc3339(parsed.isoformat())

@override
def to_postgres(
self,
context: ConversionContext,
data: PostgresTimestampTz,
) -> str:

match data:
case "infinity":
return "infinity"
Expand All @@ -53,7 +52,7 @@ def to_postgres(
return "-infinity"

case whenever.OffsetDateTime():
return data.rfc3339()
return data.format_common_iso()


STATIC_TIMESTAMPTZ_CONVERTER = TimestampTzConverter()
Expand All @@ -72,7 +71,7 @@ def from_postgres(self, context: ConversionContext, data: str) -> PostgresTimest
if data == "infinity" or data == "-infinity":
return data

return whenever.NaiveDateTime.from_common_iso8601(data)
return whenever.LocalDateTime.parse_common_iso(data)

@override
def to_postgres(self, context: ConversionContext, data: PostgresTimestampWithoutTz) -> str:
Expand All @@ -85,16 +84,16 @@ 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()

case whenever.LocalDateTime():
return data.format_common_iso()


STATIC_TIMESTAMPNOTZ_CONVERTER = TimestampNoTzConverter()
Expand Down
2 changes: 1 addition & 1 deletion src/pg_purepy/conversion/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/pg_purepy/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Any, Self

import structlog
from scramp import ScramClient
from scramp import ScramClient # pyright: ignore[reportMissingTypeStubs]
from structlog.stdlib import BoundLogger

from pg_purepy.conversion import apply_default_converters
Expand Down
4 changes: 2 additions & 2 deletions tests/converters/test_dt_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ async def test_timestamptz_converter():
assert conn.server_timezone == "UTC"

await conn.execute("create temp table test_ttz_in (id int primary key, dt timestamptz);")
juno = OffsetDateTime.from_rfc3339("2011-08-05T16:25:00Z")
juno = OffsetDateTime.parse_rfc3339("2011-08-05T16:25:00Z")
# assert juno.zon == conn.server_timezone

await conn.execute(
"insert into test_ttz_in(id, dt) values (1, :dt);",
dt=OffsetDateTime.from_rfc3339("2011-08-05T16:25:00Z"),
dt=OffsetDateTime.parse_rfc3339("2011-08-05T16:25:00Z"),
)

row_1 = await conn.fetch_one("select dt from test_ttz_in;")
Expand Down

0 comments on commit e965a02

Please sign in to comment.