fix(api): SegmentType.is_valid() raises AssertionError for SegmentType.GROUP (#28249)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from collections.abc import Mapping
|
||||
from enum import StrEnum
|
||||
from typing import Any, Optional
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
from core.file.models import File
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
|
||||
class ArrayValidation(StrEnum):
|
||||
"""Strategy for validating array elements.
|
||||
@@ -155,6 +158,17 @@ class SegmentType(StrEnum):
|
||||
return isinstance(value, File)
|
||||
elif self == SegmentType.NONE:
|
||||
return value is None
|
||||
elif self == SegmentType.GROUP:
|
||||
from .segment_group import SegmentGroup
|
||||
from .segments import Segment
|
||||
|
||||
if isinstance(value, SegmentGroup):
|
||||
return all(isinstance(item, Segment) for item in value.value)
|
||||
|
||||
if isinstance(value, list):
|
||||
return all(isinstance(item, Segment) for item in value)
|
||||
|
||||
return False
|
||||
else:
|
||||
raise AssertionError("this statement should be unreachable.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user