Skip to content

Commit

Permalink
Rename CLASS_MAP -> DATA_MODEL_CLASS_MAP
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonyte committed May 22, 2024
1 parent a4ef120 commit a2b9ad8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ferry_planner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def check_is_dir(path: Path, /) -> Path:
FilePath = Annotated[Path, AfterValidator(check_is_file)]
DirectoryPath = Annotated[Path, AfterValidator(check_is_dir)]

CLASS_MAP = {
DATA_MODEL_CLASS_MAP = {
cls.__name__: cls
for cls in (
Airport,
Expand All @@ -56,13 +56,13 @@ def _serialize_cls(self, value: type[Location | Connection]) -> str:
@field_validator("cls", mode="before")
@classmethod
def _validate_cls(cls, value: str | type | None) -> type[Location | Connection]:
if isinstance(value, str) and value in CLASS_MAP:
return CLASS_MAP[value]
if isinstance(value, type) and value in CLASS_MAP.values():
if isinstance(value, str) and value in DATA_MODEL_CLASS_MAP:
return DATA_MODEL_CLASS_MAP[value]
if isinstance(value, type) and value in DATA_MODEL_CLASS_MAP.values():
return value
msg = (
f"invalid class name '{value.__name__ if isinstance(value, type) else value}'. "
f"Valid class names are {', '.join(CLASS_MAP)}"
f"Valid class names are {', '.join(DATA_MODEL_CLASS_MAP)}"
)
raise ValueError(msg)

Expand Down

0 comments on commit a2b9ad8

Please sign in to comment.