Skip to content

Commit 4907a31

Browse files
committed
refactor: support existing Version instance in ParsableSemverVersion
1 parent 51a8130 commit 4907a31

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

questionpy_server/utils/manifest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import asyncio
66
from asyncio import to_thread
77
from pathlib import Path
8-
from typing import IO, Annotated
8+
from typing import IO, Annotated, Any
99
from zipfile import BadZipFile, ZipFile
1010

1111
from pydantic import PlainSerializer, PlainValidator, ValidationError
@@ -80,4 +80,14 @@ async def read_manifest_from_location(location: PackageLocation) -> Manifest:
8080
return await to_thread(_read_manifest_from_path_sync, manifest_path)
8181

8282

83-
type ParsableSemverVersion = Annotated[Version, PlainValidator(Version.parse), PlainSerializer(Version.__str__)]
83+
def _maybe_parse_version(value: Any) -> Any:
84+
if isinstance(value, Version):
85+
return value
86+
if isinstance(value, str):
87+
return Version.parse(value)
88+
return value
89+
90+
91+
type ParsableSemverVersion = Annotated[
92+
Version, PlainValidator(_maybe_parse_version, json_schema_input_type=str), PlainSerializer(Version.__str__)
93+
]

0 commit comments

Comments
 (0)