From b0b1703f83242ff1c20125e5c78b1742ed06d337 Mon Sep 17 00:00:00 2001 From: Leander Karp <karp@cl.uni-heidelberg.de> Date: Wed, 7 Aug 2024 16:20:56 +0200 Subject: [PATCH] Fix LSP error in UtcDateTime#process_bind_param According to mypy the previous annotation violated the LSP. We now use the types of the supertype method and return a datetime object only if the argument was a datetime-object. --- portal/model/UtcDateTime.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/portal/model/UtcDateTime.py b/portal/model/UtcDateTime.py index a7e4abb..1216228 100644 --- a/portal/model/UtcDateTime.py +++ b/portal/model/UtcDateTime.py @@ -28,12 +28,12 @@ class UtcDateTime(types.TypeDecorator): return types.String(32) def process_bind_param( - self, value: datetime, dialect: Dialect + self, value: Any | None, dialect: Dialect ) -> Optional[str | datetime]: - if value is None: - return None + if isinstance(value, datetime): + return value.astimezone(timezone.utc).isoformat() - return value.astimezone(timezone.utc).isoformat() + return None def process_result_value( self, value: str | datetime, dialect: Dialect -- GitLab