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
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -28,13 +28,13 @@ class UtcDateTime(types.TypeDecorator):
        return types.String(32)

    def process_bind_param(
        self, value: Any | None, dialect: Dialect
        self, value: datetime | None, dialect: Dialect
    ) -> Optional[str | datetime]:
        if isinstance(value, datetime):
            return value.astimezone(timezone.utc).isoformat()

        if value is None:
            return None

        return value.astimezone(timezone.utc).isoformat()

    def process_result_value(
        self, value: str | None, dialect: Dialect
    ) -> Optional[datetime]:
+4 −2
Original line number Diff line number Diff line
@@ -26,12 +26,14 @@ class Uuid(types.TypeDecorator):
    def load_dialect_impl(self, dialect: Dialect) -> types.TypeEngine[Any]:
        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):
            # Manually create UUID from string, to raise an error if the string is malformed
            UUID(value)

        return str(value) if isinstance(value, UUID) else None
        return str(value) if value else None

    def process_result_value(
        self, value: Optional[str], dialect: Dialect