|
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | 4 | from datetime import date |
5 | | -from typing import Any, Collection, Dict, Optional, Sequence |
| 5 | +from typing import Any, Collection, Dict, Optional, Sequence, Literal |
6 | 6 |
|
7 | 7 | from humps import camelize |
8 | 8 | from pydantic import root_validator |
9 | 9 |
|
10 | 10 | from mavedb.lib.validation import urn_re |
11 | | -from mavedb.lib.validation.constants.score_set import default_ranges |
12 | 11 | from mavedb.lib.validation.exceptions import ValidationError |
13 | 12 | from mavedb.lib.validation.utilities import inf_or_float, is_null |
14 | | -from mavedb.lib.utils import sanitize_string |
15 | 13 | from mavedb.models.enums.mapping_state import MappingState |
16 | 14 | from mavedb.models.enums.processing_state import ProcessingState |
17 | 15 | from mavedb.view_models import PublicationIdentifiersGetter, record_type_validator, set_record_type |
@@ -56,23 +54,13 @@ class Config: |
56 | 54 | class ScoreRange(BaseModel): |
57 | 55 | label: str |
58 | 56 | description: Optional[str] |
59 | | - classification: str |
| 57 | + classification: Literal["normal", "abnormal", "not_specified"] |
60 | 58 | # Purposefully vague type hint because of some odd JSON Schema generation behavior. |
61 | 59 | # Typing this as tuple[Union[float, None], Union[float, None]] will generate an invalid |
62 | 60 | # jsonschema, and fail all tests that access the schema. This may be fixed in pydantic v2, |
63 | 61 | # but it's unclear. Even just typing it as Tuple[Any, Any] will generate an invalid schema! |
64 | 62 | range: list[Any] # really: tuple[Union[float, None], Union[float, None]] |
65 | 63 |
|
66 | | - @validator("classification") |
67 | | - def range_classification_value_is_accepted(cls, field_value: str): |
68 | | - classification = sanitize_string(field_value) |
69 | | - if classification not in default_ranges: |
70 | | - raise ValidationError( |
71 | | - f"Unexpected classification value(s): {classification}. Permitted values: {default_ranges}" |
72 | | - ) |
73 | | - |
74 | | - return classification |
75 | | - |
76 | 64 | @validator("range") |
77 | 65 | def ranges_are_not_backwards(cls, field_value: tuple[Any]): |
78 | 66 | if len(field_value) != 2: |
|
0 commit comments