Skip to content
Snippets Groups Projects
Unverified Commit de55edc5 authored by karp's avatar karp
Browse files

Fix typing in UtcDateTime and Uuid

Update to solve the LSP errors via typing changes and not by code changes.
This undos LSP-violation related code changes.
parent 4e80c09a
No related branches found
No related tags found
1 merge request!22Make MyPy happy
...@@ -28,12 +28,12 @@ class UtcDateTime(types.TypeDecorator): ...@@ -28,12 +28,12 @@ class UtcDateTime(types.TypeDecorator):
return types.String(32) return types.String(32)
def process_bind_param( def process_bind_param(
self, value: Any | None, dialect: Dialect self, value: datetime | None, dialect: Dialect
) -> Optional[str | datetime]: ) -> Optional[str | datetime]:
if isinstance(value, datetime): if value is None:
return value.astimezone(timezone.utc).isoformat() return None
return None return value.astimezone(timezone.utc).isoformat()
def process_result_value( def process_result_value(
self, value: str | None, dialect: Dialect self, value: str | None, dialect: Dialect
......
...@@ -26,12 +26,14 @@ class Uuid(types.TypeDecorator): ...@@ -26,12 +26,14 @@ class Uuid(types.TypeDecorator):
def load_dialect_impl(self, dialect: Dialect) -> types.TypeEngine[Any]: def load_dialect_impl(self, dialect: Dialect) -> types.TypeEngine[Any]:
return types.String(UUID_LENGTH) return types.String(UUID_LENGTH)
def process_bind_param(self, value: Any | None, dialect: Dialect) -> Optional[str]: def process_bind_param(
self, value: None | str | UUID, dialect: Dialect
) -> Optional[str]:
if isinstance(value, str): if isinstance(value, str):
# Manually create UUID from string, to raise an error if the string is malformed # Manually create UUID from string, to raise an error if the string is malformed
UUID(value) UUID(value)
return str(value) if isinstance(value, UUID) else None return str(value) if value else None
def process_result_value( def process_result_value(
self, value: Optional[str], dialect: Dialect self, value: Optional[str], dialect: Dialect
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment