Skip to content

Commit 8501403

Browse files
committed
Switch from decorator to annotated type so can be shared later
1 parent ea6693c commit 8501403

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

exasol/toolbox/util/dependencies/shared_models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from __future__ import annotations
22

3+
from typing import Annotated
4+
35
from packaging.version import Version
46
from pydantic import (
57
BaseModel,
8+
BeforeValidator,
69
ConfigDict,
7-
field_validator,
810
)
911

12+
VERSION_TYPE = Annotated[Version, BeforeValidator(lambda v: Version(str(v)))]
13+
1014

1115
class Package(BaseModel):
1216
model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)
1317

1418
name: str
15-
version: Version
16-
17-
@field_validator("version", mode="before")
18-
def convert_version(cls, v: str) -> Version:
19-
return Version(v)
19+
version: VERSION_TYPE
2020

2121
@property
2222
def normalized_name(self) -> str:

test/unit/util/git_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from packaging.version import Version
3-
from toolbox.util.git import Git
3+
4+
from exasol.toolbox.util.git import Git
45

56
POETRY_LOCK = "poetry.lock"
67

0 commit comments

Comments
 (0)