Skip to content

Commit

Permalink
Add max length annotation for custom type aliases
Browse files Browse the repository at this point in the history
Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>
  • Loading branch information
AndrejOrsula committed Jan 6, 2025
1 parent 5086a25 commit 2ce8605
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions simforge/_typing/cfg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Annotated, Dict, List, TypeAlias

from annotated_types import MinLen
from annotated_types import Len
from pydantic import InstanceOf, PositiveInt

from simforge._typing.enum import EnumNameSerializer
Expand All @@ -9,21 +9,28 @@
from simforge.core.exporter import Exporter, FileFormat

FileFormatConfig: TypeAlias = (
InstanceOf[FileFormat] | Annotated[List[InstanceOf[FileFormat]], MinLen(1)] | None
InstanceOf[FileFormat]
| Annotated[
List[InstanceOf[FileFormat]], Len(min_length=1, max_length=len(AssetType))
]
| None
)

ExporterConfig: TypeAlias = (
InstanceOf[Exporter]
| Annotated[List[InstanceOf[Exporter]], MinLen(1)]
| Annotated[
Dict[Annotated[AssetType, EnumNameSerializer], InstanceOf[Exporter]], MinLen(1)
List[InstanceOf[Exporter]], Len(min_length=1, max_length=len(AssetType))
]
| Annotated[
Dict[Annotated[AssetType, EnumNameSerializer], InstanceOf[Exporter]],
Len(min_length=1, max_length=len(AssetType)),
]
)

TexResConfig: TypeAlias = (
PositiveInt
| Annotated[
Dict[Annotated[BakeType, EnumNameSerializer], PositiveInt],
MinLen(len(BakeType)),
Len(min_length=1, max_length=len(BakeType)),
]
)

0 comments on commit 2ce8605

Please sign in to comment.